chattercatcher 0.1.11 → 0.1.13

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/index.d.ts CHANGED
@@ -10,6 +10,7 @@ declare const appConfigSchema: z.ZodObject<{
10
10
  lark: "lark";
11
11
  }>>;
12
12
  appId: z.ZodDefault<z.ZodString>;
13
+ botOpenId: z.ZodDefault<z.ZodString>;
13
14
  groupPolicy: z.ZodDefault<z.ZodEnum<{
14
15
  open: "open";
15
16
  allowlist: "allowlist";
@@ -516,7 +517,7 @@ interface FeishuQuestionDecision {
516
517
  chatId?: string;
517
518
  reason?: string;
518
519
  }
519
- declare function isFeishuMessageAddressedToBot(payload: FeishuReceiveMessageEvent): boolean;
520
+ declare function isFeishuMessageAddressedToBot(payload: FeishuReceiveMessageEvent, config: AppConfig): boolean;
520
521
  declare function getFeishuQuestionDecision(payload: FeishuReceiveMessageEvent, config: AppConfig): FeishuQuestionDecision;
521
522
  declare class FeishuQuestionHandler {
522
523
  private readonly options;
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ var appConfigSchema = z.object({
9
9
  feishu: z.object({
10
10
  domain: z.enum(["feishu", "lark"]).default("feishu"),
11
11
  appId: z.string().default(""),
12
+ botOpenId: z.string().default(""),
12
13
  groupPolicy: z.enum(["open", "allowlist", "disabled"]).default("open"),
13
14
  requireMention: z.boolean().default(true)
14
15
  }),
@@ -2031,12 +2032,22 @@ function stripMentions(text, mentions) {
2031
2032
  }
2032
2033
  return result.replace(/@/g, " ").replace(/\s+/g, " ").trim();
2033
2034
  }
2034
- function isFeishuMessageAddressedToBot(payload) {
2035
+ function isMentionForBot(mention, config) {
2036
+ if (!config.feishu.botOpenId) {
2037
+ return false;
2038
+ }
2039
+ return mention.id?.open_id === config.feishu.botOpenId;
2040
+ }
2041
+ function getBotMentions(payload, config) {
2042
+ const message = payload.event?.message;
2043
+ return (message?.mentions ?? []).filter((mention) => isMentionForBot(mention, config));
2044
+ }
2045
+ function isFeishuMessageAddressedToBot(payload, config) {
2035
2046
  const message = payload.event?.message;
2036
2047
  if (!message || message.message_type !== "text") {
2037
2048
  return false;
2038
2049
  }
2039
- return (message.mentions ?? []).length > 0;
2050
+ return getBotMentions(payload, config).length > 0;
2040
2051
  }
2041
2052
  function getFeishuQuestionDecision(payload, config) {
2042
2053
  const message = payload.event?.message;
@@ -2046,9 +2057,9 @@ function getFeishuQuestionDecision(payload, config) {
2046
2057
  reason: "\u4E0D\u662F\u53EF\u56DE\u7B54\u7684\u6587\u672C\u6D88\u606F\u3002"
2047
2058
  };
2048
2059
  }
2049
- const mentions = message.mentions ?? [];
2060
+ const mentions = getBotMentions(payload, config);
2050
2061
  const text = parseTextContent(message.content);
2051
- const hasMention = isFeishuMessageAddressedToBot(payload);
2062
+ const hasMention = isFeishuMessageAddressedToBot(payload, config);
2052
2063
  if (config.feishu.requireMention && !hasMention) {
2053
2064
  return {
2054
2065
  shouldAnswer: false,
@@ -2225,7 +2236,7 @@ function createFeishuEventDispatcher(options) {
2225
2236
  return new lark2.EventDispatcher({}).register({
2226
2237
  "im.message.receive_v1": async (data) => {
2227
2238
  const payload = { event: data };
2228
- if (options.questionHandler && isFeishuMessageAddressedToBot(payload)) {
2239
+ if (options.questionHandler && isFeishuMessageAddressedToBot(payload, options.config)) {
2229
2240
  const platformMessageId = data?.message?.message_id;
2230
2241
  if (platformMessageId && answeredMessageIds.has(platformMessageId)) {
2231
2242
  console.log("\u98DE\u4E66\u63D0\u95EE\u91CD\u590D\u6295\u9012\uFF1A\u5DF2\u8DF3\u8FC7\u56DE\u7B54\u3002");