chattercatcher 0.1.10 → 0.1.12
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/cli.js +23 -10
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +17 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -8,7 +8,7 @@ import fs13 from "fs/promises";
|
|
|
8
8
|
// package.json
|
|
9
9
|
var package_default = {
|
|
10
10
|
name: "chattercatcher",
|
|
11
|
-
version: "0.1.
|
|
11
|
+
version: "0.1.12",
|
|
12
12
|
description: "\u672C\u5730\u4F18\u5148\u7684\u98DE\u4E66/Lark \u5BB6\u5EAD\u7FA4\u77E5\u8BC6\u5E93\u673A\u5668\u4EBA",
|
|
13
13
|
type: "module",
|
|
14
14
|
main: "dist/index.js",
|
|
@@ -88,6 +88,7 @@ var appConfigSchema = z.object({
|
|
|
88
88
|
feishu: z.object({
|
|
89
89
|
domain: z.enum(["feishu", "lark"]).default("feishu"),
|
|
90
90
|
appId: z.string().default(""),
|
|
91
|
+
botOpenId: z.string().default(""),
|
|
91
92
|
groupPolicy: z.enum(["open", "allowlist", "disabled"]).default("open"),
|
|
92
93
|
requireMention: z.boolean().default(true)
|
|
93
94
|
}),
|
|
@@ -2104,16 +2105,24 @@ function stripMentions(text, mentions) {
|
|
|
2104
2105
|
}
|
|
2105
2106
|
}
|
|
2106
2107
|
}
|
|
2107
|
-
return result.replace(
|
|
2108
|
+
return result.replace(/@/g, " ").replace(/\s+/g, " ").trim();
|
|
2108
2109
|
}
|
|
2109
|
-
function
|
|
2110
|
+
function isMentionForBot(mention, config) {
|
|
2111
|
+
if (!config.feishu.botOpenId) {
|
|
2112
|
+
return false;
|
|
2113
|
+
}
|
|
2114
|
+
return mention.id?.open_id === config.feishu.botOpenId;
|
|
2115
|
+
}
|
|
2116
|
+
function getBotMentions(payload, config) {
|
|
2117
|
+
const message = payload.event?.message;
|
|
2118
|
+
return (message?.mentions ?? []).filter((mention) => isMentionForBot(mention, config));
|
|
2119
|
+
}
|
|
2120
|
+
function isFeishuMessageAddressedToBot(payload, config) {
|
|
2110
2121
|
const message = payload.event?.message;
|
|
2111
2122
|
if (!message || message.message_type !== "text") {
|
|
2112
2123
|
return false;
|
|
2113
2124
|
}
|
|
2114
|
-
|
|
2115
|
-
const text = parseTextContent(message.content);
|
|
2116
|
-
return mentions.length > 0 || /@?ChatterCatcher/i.test(text);
|
|
2125
|
+
return getBotMentions(payload, config).length > 0;
|
|
2117
2126
|
}
|
|
2118
2127
|
function getFeishuQuestionDecision(payload, config) {
|
|
2119
2128
|
const message = payload.event?.message;
|
|
@@ -2123,9 +2132,9 @@ function getFeishuQuestionDecision(payload, config) {
|
|
|
2123
2132
|
reason: "\u4E0D\u662F\u53EF\u56DE\u7B54\u7684\u6587\u672C\u6D88\u606F\u3002"
|
|
2124
2133
|
};
|
|
2125
2134
|
}
|
|
2126
|
-
const mentions =
|
|
2135
|
+
const mentions = getBotMentions(payload, config);
|
|
2127
2136
|
const text = parseTextContent(message.content);
|
|
2128
|
-
const hasMention = isFeishuMessageAddressedToBot(payload);
|
|
2137
|
+
const hasMention = isFeishuMessageAddressedToBot(payload, config);
|
|
2129
2138
|
if (config.feishu.requireMention && !hasMention) {
|
|
2130
2139
|
return {
|
|
2131
2140
|
shouldAnswer: false,
|
|
@@ -2302,7 +2311,7 @@ function createFeishuEventDispatcher(options) {
|
|
|
2302
2311
|
return new lark2.EventDispatcher({}).register({
|
|
2303
2312
|
"im.message.receive_v1": async (data2) => {
|
|
2304
2313
|
const payload = { event: data2 };
|
|
2305
|
-
if (options.questionHandler && isFeishuMessageAddressedToBot(payload)) {
|
|
2314
|
+
if (options.questionHandler && isFeishuMessageAddressedToBot(payload, options.config)) {
|
|
2306
2315
|
const platformMessageId = data2?.message?.message_id;
|
|
2307
2316
|
if (platformMessageId && answeredMessageIds.has(platformMessageId)) {
|
|
2308
2317
|
console.log("\u98DE\u4E66\u63D0\u95EE\u91CD\u590D\u6295\u9012\uFF1A\u5DF2\u8DF3\u8FC7\u56DE\u7B54\u3002");
|
|
@@ -3582,6 +3591,10 @@ async function promptForConfiguration(config, secrets) {
|
|
|
3582
3591
|
default: config.feishu.domain
|
|
3583
3592
|
});
|
|
3584
3593
|
config.feishu.appId = await input({ message: "\u98DE\u4E66 App ID", default: config.feishu.appId });
|
|
3594
|
+
config.feishu.botOpenId = await input({
|
|
3595
|
+
message: "\u98DE\u4E66\u673A\u5668\u4EBA Open ID\uFF08\u5FC5\u586B\uFF0C\u7528\u4E8E\u533A\u5206 @ \u673A\u5668\u4EBA\u548C @ \u5176\u4ED6\u4EBA\uFF09",
|
|
3596
|
+
default: config.feishu.botOpenId
|
|
3597
|
+
});
|
|
3585
3598
|
secrets.feishu.appSecret = applySecretInput(
|
|
3586
3599
|
secrets.feishu.appSecret,
|
|
3587
3600
|
await password({ message: secrets.feishu.appSecret ? "\u98DE\u4E66 App Secret\uFF08\u7559\u7A7A\u4FDD\u7559\uFF09" : "\u98DE\u4E66 App Secret", mask: "*" })
|
|
@@ -3613,7 +3626,7 @@ async function promptForConfiguration(config, secrets) {
|
|
|
3613
3626
|
config.embedding.dimension = dimension ?? null;
|
|
3614
3627
|
config.web.port = await number({ message: "Web UI \u7AEF\u53E3", default: config.web.port, required: true }) ?? config.web.port;
|
|
3615
3628
|
config.feishu.requireMention = await confirm({
|
|
3616
|
-
message: "\u7FA4\u804A\u56DE\u7B54\u662F\u5426\u8981\u6C42 @
|
|
3629
|
+
message: "\u7FA4\u804A\u56DE\u7B54\u662F\u5426\u8981\u6C42 @ \u673A\u5668\u4EBA\uFF1F",
|
|
3617
3630
|
default: config.feishu.requireMention
|
|
3618
3631
|
});
|
|
3619
3632
|
}
|