xiaozuoassistant 0.2.44 → 0.2.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/channels/feishu.js +12 -25
- package/package.json +1 -1
|
@@ -83,35 +83,22 @@ export class FeishuChannel extends BaseChannel {
|
|
|
83
83
|
// 在群聊中,只有当机器人被 @ 时才响应
|
|
84
84
|
if (event.chat_type === 'group') {
|
|
85
85
|
const mentions = event.mentions || [];
|
|
86
|
-
//
|
|
87
|
-
// 飞书 SDK 会将消息文本中的 @ 解析到 mentions 数组
|
|
88
|
-
// 对于机器人自己,如果没有被 @,则直接忽略
|
|
89
|
-
const isMentioned = mentions.some((m) => !m.id || m.id.open_id === undefined);
|
|
90
|
-
// 注意:在飞书事件中,如果 @ 的是机器人自己,通常没有具体的 user_id,或者带有特定的标识。
|
|
91
|
-
// 更严谨的做法是:如果 message 内容中包含 "@_user_1" 并且 mentions 里有机器人的标识。
|
|
92
|
-
// 简单且通用的判定是:群聊中如果不包含 mentions,肯定没被@
|
|
86
|
+
// 1. 如果群聊中没有任何人被 @,则忽略(防止机器人被动读取群消息时刷屏)
|
|
93
87
|
if (mentions.length === 0) {
|
|
94
|
-
return;
|
|
88
|
+
return;
|
|
95
89
|
}
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
//
|
|
101
|
-
//
|
|
102
|
-
// 更精确:飞书给机器人的事件回调,只有在机器人被@或者在单聊时,才会触发!
|
|
103
|
-
// !!!等一下!!!
|
|
104
|
-
// 实际上,飞书开放平台规则:机器人如果在群里,只有被 @ 时,飞书服务器才会把消息推送给长连接!
|
|
105
|
-
// 如果没被 @,飞书根本不会发事件过来!
|
|
106
|
-
// 但是,如果机器人在后台申请了“获取群内所有消息”的高级权限,那么每条消息都会推过来。
|
|
107
|
-
// 为了防止刷屏,我们检查 event.mentions 是否包含机器人。
|
|
108
|
-
// 我们通过检查 mentions 数组里是否包含一个 name 为本机器人的项,或者 id.open_id 为空的项
|
|
90
|
+
// 2. 检查被 @ 的列表中是否包含自己
|
|
91
|
+
// 由于飞书返回的 mentions 对象里,如果被 @ 的是当前收到事件的机器人自己,
|
|
92
|
+
// 通常其 is_self 属性为 true,或者 name 匹配,或者 id 为空/不完整。
|
|
93
|
+
// 最稳妥的方法是依靠飞书 SDK 在下发事件时设置的 m.name === botName,
|
|
94
|
+
// 或者直接看是否有一个 `m.id.open_id` 未定义(因为机器人本身没有用户 open_id),
|
|
95
|
+
// 或者检查 is_self === true
|
|
109
96
|
const isMentionedSelf = mentions.some((m) => {
|
|
110
|
-
|
|
111
|
-
return m.name === botName || !m.id || Object.keys(m.id).length === 0 || m.is_self === true;
|
|
97
|
+
return m.name === botName || m.is_self === true || (!m.id || Object.keys(m.id).length === 0);
|
|
112
98
|
});
|
|
113
|
-
|
|
114
|
-
|
|
99
|
+
if (!isMentionedSelf) {
|
|
100
|
+
return; // 被 @ 的是别人,不是本机器人,忽略
|
|
101
|
+
}
|
|
115
102
|
}
|
|
116
103
|
try {
|
|
117
104
|
let content = JSON.parse(event.content).text;
|