We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
使用 adapter-qq 发送单聊主动消息
const userId = '064104A3FACEB533A9CB3B7C375E093A' const content = 'xxx' bot.sendPrivateMessage(userId, content)
查看报错信息,发现用户 id 被当成了群的 id,调用了群聊接口进行发送:
[W] qq POST /v2/groups/064104A3FACEB533A9CB3B7C375E093A/messages request: { data: { content: 'xxx', msg_type: 0, msg_id: undefined, msg_seq: undefined } } [W] qq POST /v2/groups/064104A3FACEB533A9CB3B7C375E093A/messages response: { message: 'invalid request', code: 11255, err_code: 11255, trace_id: '34fbaddd179dd40294612dcf4e2733cd' }, trace id: 34fbaddd179dd40294612dcf4e2733cd
排查原因,发现目前是通过 session.isDirect 判断应调用单聊接口还是群聊接口:
session.isDirect
satori/adapters/qq/src/message.ts
Lines 248 to 250 in 83742e6
但发送主动消息,调用 sendPrivateMessage 方法时并未传入 session,导致默认被当成了群聊。
sendPrivateMessage
进一步排查应如何区分单聊和群聊。在 @satorijs/core 中,单聊相比群聊会额外调用 createDirectChannel
createDirectChannel
satori/packages/core/src/bot.ts
Lines 187 to 195 in 83742e6
虽然在 qq 适配器的 createDirectChannel 方法中已经指定了 Channel Type 为 Direct:
satori/adapters/qq/src/bot/index.ts
Lines 114 to 116 in 83742e6
但 sendPrivateMessage 方法只使用了 id,无视了 type。而 qq 群场景中,群的 openId 和用户的 openId 格式相同,难以通过 id 格式区分群和私聊。
id
type
可能的解决方案:
The text was updated successfully, but these errors were encountered:
No branches or pull requests
使用 adapter-qq 发送单聊主动消息
查看报错信息,发现用户 id 被当成了群的 id,调用了群聊接口进行发送:
排查原因,发现目前是通过
session.isDirect
判断应调用单聊接口还是群聊接口:satori/adapters/qq/src/message.ts
Lines 248 to 250 in 83742e6
但发送主动消息,调用
sendPrivateMessage
方法时并未传入 session,导致默认被当成了群聊。进一步排查应如何区分单聊和群聊。在 @satorijs/core 中,单聊相比群聊会额外调用
createDirectChannel
satori/packages/core/src/bot.ts
Lines 187 to 195 in 83742e6
虽然在 qq 适配器的
createDirectChannel
方法中已经指定了 Channel Type 为 Direct:satori/adapters/qq/src/bot/index.ts
Lines 114 to 116 in 83742e6
但
sendPrivateMessage
方法只使用了id
,无视了type
。而 qq 群场景中,群的 openId 和用户的 openId 格式相同,难以通过 id 格式区分群和私聊。可能的解决方案:
createDirectChannel
方法中,为id
拼接一个特殊的前/后缀,将其与普通 openId 的格式区分开来,并以此判断调用单聊还是群聊接口。算是一个比较取巧的做法。sendPrivateMessage
方法时,就必然意味着要调用单聊接口。因此sendPrivateMessage
方法不应无视createDirectChannel
返回的type
参数,而应将它作为判断单聊还是群聊的标准。不过这样修改的话,改动就相对大些。The text was updated successfully, but these errors were encountered: