@ian2018cs/agenthub 0.2.1 → 0.2.2
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/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - 下载图片 / 音频资源
|
|
8
8
|
* - 发送 / 回复 / 更新 消息(文本 + 卡片模板)
|
|
9
9
|
*
|
|
10
|
-
* 仅处理单聊(chat_type === 'p2p'
|
|
10
|
+
* 仅处理单聊(chat_type === 'p2p');群聊消息仅在 @机器人 时回复提示,其他静默忽略。
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import * as lark from '@larksuiteoapi/node-sdk';
|
|
@@ -37,12 +37,22 @@ export class LarkClient {
|
|
|
37
37
|
this.appSecret = appSecret;
|
|
38
38
|
this.engine = engine;
|
|
39
39
|
this.wsClient = null;
|
|
40
|
+
this.botOpenId = null;
|
|
40
41
|
|
|
41
42
|
// REST 客户端(用于发消息、下载资源)
|
|
42
43
|
this.client = new lark.Client({ appId, appSecret, disableTokenCache: false });
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
async start() {
|
|
47
|
+
// 获取机器人自身 open_id,用于群聊 @ 检测
|
|
48
|
+
try {
|
|
49
|
+
const botInfo = await this.client.bot.info.get({});
|
|
50
|
+
this.botOpenId = botInfo.data?.bot?.open_id || null;
|
|
51
|
+
console.log('[Feishu] Bot open_id:', this.botOpenId);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
console.error('[Feishu] Failed to get bot info:', err.message);
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
this.wsClient = new lark.WSClient({ appId: this.appId, appSecret: this.appSecret });
|
|
47
57
|
|
|
48
58
|
const dispatcher = new lark.EventDispatcher({}).register({
|
|
@@ -92,9 +102,11 @@ export class LarkClient {
|
|
|
92
102
|
const chatId = message.chat_id;
|
|
93
103
|
const messageId = message.message_id;
|
|
94
104
|
|
|
95
|
-
//
|
|
105
|
+
// 只处理单聊;群聊仅在 @机器人 时回复提示,其他消息静默忽略
|
|
96
106
|
if (chatType !== 'p2p') {
|
|
97
|
-
|
|
107
|
+
const mentions = message.mentions || [];
|
|
108
|
+
const isMentioned = this.botOpenId && mentions.some(m => m?.id?.open_id === this.botOpenId);
|
|
109
|
+
if (isMentioned && chatId && messageId) {
|
|
98
110
|
await this.replyText(messageId, '暂不支持群聊,请直接私信我进行对话 🙏').catch(() => {});
|
|
99
111
|
}
|
|
100
112
|
return;
|