Skip to content

Fix: Support Array<string | Elements> in active message interface#536

Merged
sj817 merged 2 commits into
mainfrom
copilot/fix-ddc5e4ee-0a54-4ebb-baf6-4f5a96db7e17
Oct 2, 2025
Merged

Fix: Support Array<string | Elements> in active message interface#536
sj817 merged 2 commits into
mainfrom
copilot/fix-ddc5e4ee-0a54-4ebb-baf6-4f5a96db7e17

Conversation

Copilot AI commented Oct 1, 2025

Copy link
Copy Markdown
Contributor

Problem

The active message interface (sendMsg, sendMaster, sendAdmin) did not support arrays containing mixed strings and message segments. This prevented users from sending messages like:

const message = [
  'Hello ',
  segment.at('123456'),
  ', check out this image: ',
  segment.image('image.jpg'),
  ' Amazing!'
]
await karin.sendMsg(selfId, contact, message) // Type error!

Root Cause

Two files had incorrect local Message type definitions that only allowed Array<Elements>:

type Message = string | Elements | Array<Elements> // ❌ Incorrect

While the correct SendMessage type was already properly defined in the type system as:

export type SendMessage = string | Elements | Array<string | Elements> // ✅ Correct

The local definitions were shadowing the correct type and preventing mixed arrays.

Changes

This PR fixes the issue by removing the incorrect local Message type definitions and using the proper SendMessage type:

Files changed:

  • packages/core/src/service/bot.ts - Updated sendMsg function to use SendMessage type
  • packages/core/src/core/karin/sendMsg.ts - Updated sendMaster and sendAdmin functions to use SendMessage type

Impact

After this fix, all active message functions now correctly support mixed arrays:

// All of these patterns now work correctly:
await karin.sendMsg(selfId, contact, 'Simple string')
await karin.sendMsg(selfId, contact, segment.image('img.jpg'))
await karin.sendMsg(selfId, contact, [segment.at('123'), segment.text('Hi')])
await karin.sendMsg(selfId, contact, ['String', segment.image('img.jpg')]) // ✅ Now works!

// Also applies to:
await karin.sendMaster(selfId, masterId, ['Text', segment.at('123')])
await karin.sendAdmin(selfId, adminId, ['Text', segment.image('img.jpg')])

Testing

  • ✅ TypeScript compilation verified
  • ✅ No breaking changes to existing code
  • ✅ All existing message patterns continue to work
  • ✅ New mixed array pattern now supported

Fixes #[issue_number]

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • registry.npmmirror.com
    • Triggering command: node /home/REDACTED/.npm/_npx/c65dbefa27d408e0/node_modules/.bin/prebuild-install -r node --pkg_version=0.12.0 --pkg_name=node-pty-prebuilt-multiarch (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Bug: 主动消息接口不支持 Array<string 和消息段的组合></issue_title>
<issue_description>### 描述问题

1

复现步骤

  1. 第一步
  2. 第二步
  3. ...

预期行为

2

实际行为

3

操作系统

1

Node.js 版本

1

项目版本

1

附加信息

No response</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #516

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Bug: 主动消息接口不支持 Array<string 和消息段的组合> Fix: Support Array<string | Elements> in active message interface Oct 2, 2025
Copilot AI requested a review from sj817 October 2, 2025 00:07
@sj817
sj817 marked this pull request as ready for review October 2, 2025 00:12
Copilot AI review requested due to automatic review settings October 2, 2025 00:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes type definitions in the active message interface to properly support arrays containing mixed strings and message elements. The issue was caused by incorrect local Message type definitions that only allowed Array<Elements> instead of the correct Array<string | Elements>.

Key changes:

  • Remove incorrect local Message type definitions that were shadowing the correct SendMessage type
  • Update function parameters to use the proper SendMessage type from the type system
  • Enable support for mixed arrays like ['Hello', segment.at('123'), 'world']

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/core/src/service/bot.ts Updated sendMsg function to use SendMessage type and removed local Message type definition
packages/core/src/core/karin/sendMsg.ts Updated sendMaster and sendAdmin functions to use SendMessage type and removed local Message type definition

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions

github-actions Bot commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

你可以通过以下命令安装该版本:

pnpm add https://pkg.pr.new/node-karin@fd9bea7 -w

@sj817
sj817 merged commit 3ff6d62 into main Oct 2, 2025
4 checks passed
@sj817
sj817 deleted the copilot/fix-ddc5e4ee-0a54-4ebb-baf6-4f5a96db7e17 branch October 2, 2025 00:18
@github-actions github-actions Bot mentioned this pull request Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: 主动消息接口不支持 Array<string 和消息段的组合>

3 participants