Skip to content

fix: 飞书群聊中机器人应仅响应 @机器人 的消息 #150

@shellmind112

Description

@shellmind112

问题

飞书群聊中 @机器人一次后,机器人会对群内所有消息都回复,而非仅响应 @机器人 的消息。

原因

handleMessage 未区分 chat_type(私聊 p2p / 群聊 group),飞书 SDK 在群聊中会推送所有消息事件,而代码直接处理了所有收到的消息。

修复方案

handleMessage 入口处检查 message.chat_type,若为 group 则检查 message.mentions 字段,无 @mention 则直接忽略。

if (chatType === "group") {
  const mentions = message.mentions
  if (!mentions || !Array.isArray(mentions) || mentions.length === 0) {
    return  // 忽略未 @机器人 的群聊消息
  }
}

依赖

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions