🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
✨ feat(bot): bring the bot-wake settings to Feishu / Lark (#21825)
Arvin Xu47d911f344f9
diff --git a/apps/server/src/services/agentSignal/scenarios/__tests__/botWakeFacts.test.ts b/apps/server/src/services/agentSignal/scenarios/__tests__/botWakeFacts.test.tsindex 1624da5030b..b81b7d7ef17 100644--- a/apps/server/src/services/agentSignal/scenarios/__tests__/botWakeFacts.test.ts+++ b/apps/server/src/services/agentSignal/scenarios/__tests__/botWakeFacts.test.ts@@ -1,9 +1,11 @@// @vitest-environment nodeimport {+ hasConversationLog,isEmptyOrEmojiOnly,judgeExplicitMention,parseDiscordMentions,resolveChannelKeys,+ resolveConversationLogKeys,wakeStateKeys,} from '../botWake/facts';@@ -173,9 +175,39 @@ describe('resolveChannelKeys', () => {]);});+ it('matches a Feishu / Lark chat by its chat id, not by its chat type', () => {+ expect(resolveChannelKeys('feishu', 'app', 'feishu:group:oc_1').ids).toEqual([+ 'feishu:group:oc_1',+ 'oc_1',+ ]);+ expect(resolveChannelKeys('lark', 'app', 'lark:oc_1').ids).toEqual(['lark:oc_1', 'oc_1']);+ });+it('keeps two bots in one channel apart', () => {expect(resolveChannelKeys('discord', 'a', 'discord:g:c').channelKey).not.toBe(resolveChannelKeys('discord', 'b', 'discord:g:c').channelKey,);});});++describe('hasConversationLog', () => {+ it.each([+ ['discord', 'discord:g1:c1', true],+ ['discord', 'discord:g1:c1:t1', true],+ ['discord', 'discord:@me:dm1', false],+ ['feishu', 'feishu:group:oc_1', true],+ ['lark', 'lark:group:oc_1', true],+ ['feishu', 'feishu:p2p:oc_1', false],+ // A legacy id cannot tell a group from a direct message.+ ['feishu', 'feishu:oc_1', false],+ ['telegram', 'telegram:-100', false],+ ])('%s %s -> %s', (platform, threadId, expected) => {+ expect(hasConversationLog(platform, threadId)).toBe(expected);+ });++ it('files a Feishu group message under the group', () => {+ expect(resolveConversationLogKeys('feishu', 'feishu:group:oc_1')).toEqual([+ 'feishu:group:oc_1',+ ]);+ });+});diff --git a/apps/server/src/services/agentSignal/scenarios/botWake/facts.ts b/apps/server/src/services/agentSignal/scenarios/botWake/facts.tsindex 5f2ad33f085..a8513937a7e 100644--- a/apps/server/src/services/agentSignal/scenarios/botWake/facts.ts+++ b/apps/server/src/services/agentSignal/scenarios/botWake/facts.ts@@ -5,6 +5,9 @@ const DISCORD_ROLE_MENTION = /<@&(\d+)>/g;const DISCORD_CUSTOM_EMOJI = /<a?:\w+:\d+>/g;const SHORTCODE_EMOJI = /:[\w+-]+:/g;+const LARK_CHAT_TYPES = new Set(['group', 'p2p']);+const isLarkPlatform = (platform: string) => platform === 'feishu' || platform === 'lark';+/*** Re-derives mentions from a Discord message's own text.*@@ -88,14 +91,36 @@ export const resolveChannelKeys = (// Other platforms encode the conversation as `platform:part:part`. The owner may know it by the// whole id or by the id they see in the platform's UI (Telegram chat id, Slack channel id).+ // Feishu / Lark put the chat type there (`feishu:group:oc_…`), which is no id of the chat.const [, ...parts] = platformThreadId.split(':');+ const ids = isLarkPlatform(platform)+ ? parts.filter((part) => !LARK_CHAT_TYPES.has(part))+ : parts;return {channelKey: `${base}:${platformThreadId}`,- ids: [platformThreadId, ...parts.filter(Boolean)],+ ids: [platformThreadId, ...ids.filter(Boolean)],};};+/**+ * Whether a conversation keeps a shared message log: a group conversation on a platform that+ * delivers every message said in it, not only those addressed to the bot. Direct messages are+ * private and never logged.+ *+ * - Discord: guild channels (`discord:<guild>:<channel>[:<thread>]`), not `@me`+ * - Feishu / Lark: group chats (`feishu:group:oc_…`); a legacy id without the chat type cannot+ * tell a group from a direct message, so it is not logged+ */+export const hasConversationLog = (platform: string, platformThreadId: string): boolean => {+ const [, kind] = platformThreadId.split(':');++ if (platform === 'discord') return !!kind && kind !== '@me';+ if (isLarkPlatform(platform)) return kind === 'group';++ return false;+};+/*** Keys of a conversation's shared message log, the channel first and then the thread when there is* one. Unlike the wake state they carry no application id: every bot in a channel reads and writesdiff --git a/apps/server/src/services/bot/BotMessageRouter/wakeDecision.initiate.test.ts b/apps/server/src/services/bot/BotMessageRouter/wakeDecision.initiate.test.tsindex 541f4293c37..8cd98fb2867 100644--- a/apps/server/src/services/bot/BotMessageRouter/wakeDecision.initiate.test.ts+++ b/apps/server/src/services/bot/BotMessageRouter/wakeDecision.initiate.test.ts@@ -568,6 +568,28 @@ describe('bot-wake recorder: remembering what was said', () => {expect(state.logs.get('discord:g1:c1')?.[0].at).toBe(Date.UTC(2026, 0, 1));});+ it('keeps a Feishu group message under the group, stamped with its send time', async () => {+ const state = fakeState();+ const sent = new Date(Date.UTC(2026, 0, 1));+ await make(ENFORCE, state, { platform: 'feishu' }).remember(+ observation({ threadId: 'feishu:group:oc_1' }, { id: 'om_1', metadata: { dateSent: sent } }),+ );++ expect(state.logs.get('feishu:group:oc_1')?.[0]).toMatchObject({+ at: sent.getTime(),+ id: 'om_1',+ });+ });++ it('does not keep a Feishu direct message', async () => {+ const state = fakeState();+ await make(ENFORCE, state, { platform: 'feishu' }).remember(+ observation({ threadId: 'feishu:p2p:oc_1' }),+ );++ expect(state.rememberMessages).not.toHaveBeenCalled();+ });+it('never throws when Redis is down', async () => {const state = fakeState();state.rememberMessages.mockRejectedValueOnce(new Error('redis down'));diff --git a/apps/server/src/services/bot/BotMessageRouter/wakeDecision.ts b/apps/server/src/services/bot/BotMessageRouter/wakeDecision.tsindex a848c23c21e..438c84d6997 100644--- a/apps/server/src/services/bot/BotMessageRouter/wakeDecision.ts+++ b/apps/server/src/services/bot/BotMessageRouter/wakeDecision.ts@@ -22,6 +22,7 @@ import {toConversationLine,} from '@/server/services/agentSignal/scenarios/botWake/conversation';import {+ hasConversationLog,judgeExplicitMention,resolveChannelKeys,resolveConversationLogKey,@@ -563,9 +564,9 @@ export const createBotWakeRecorder = (options: BotWakeRecorderOptions): BotWakeRconst readState = async (signal: WakeSignal) =>toChannelState(await state.readChannel(wakeStateKeys(signal.channelKeys!)));- // Direct messages are private: only guild channels keep a shared log.+ // Direct messages are private: only group conversations keep a shared log.const logKeyFor = (observation: BotWakeObservation): string | undefined =>- platform === 'discord' && observation.threadId.split(':')[1] !== '@me'+ hasConversationLog(platform, observation.threadId)? resolveConversationLogKey(platform, observation.threadId): undefined;@@ -971,8 +972,10 @@ export const createBotWakeRecorder = (options: BotWakeRecorderOptions): BotWakeRif (!enabled || !(await rolledOut())) return;const line = toConversationLine({- // A Discord id carries its send time, so two bots write the identical line.- at: discordMessageTime(message.id) ?? Date.now(),+ // The send time comes from the message (a Discord id carries it), so two bots in one+ // channel write the identical line.+ at:+ discordMessageTime(message.id) ?? message.metadata?.dateSent?.getTime() ?? Date.now(),authorId: message.author?.userId,authorName: message.author?.userName ?? message.author?.fullName,hasAttachments: (message.attachments?.length ?? 0) > 0,diff --git a/apps/server/src/services/bot/platforms/__tests__/botWakeFields.test.ts b/apps/server/src/services/bot/platforms/__tests__/botWakeFields.test.tsindex ebf27688348..e443ae0c7ac 100644--- a/apps/server/src/services/bot/platforms/__tests__/botWakeFields.test.ts+++ b/apps/server/src/services/bot/platforms/__tests__/botWakeFields.test.ts@@ -12,8 +12,9 @@ import {} from '@/server/services/agentSignal/scenarios/botWake/config';import agentLocale from '../../../../../../../packages/locales/src/default/agent';-import { botWakeFields } from '../botWakeFields';+import { botWakeFields, larkBotWakeFields } from '../botWakeFields';import { schema as discordSchema } from '../discord/schema';+import { sharedSchema as larkSchema } from '../feishu/definitions/schema';import type { FieldSchema } from '../types';import { mergeWithDefaults } from '../utils';@@ -166,4 +167,21 @@ describe('bot-wake settings fields', () => {// Off is the master switch; once it is on, everything enforces.expect(parsed.ruleMode).toBe('enforce');});++ it('are offered on Feishu / Lark, with group chat ids in the channel lists', () => {+ const keys = settingsFields(larkSchema).map((field) => field.key);+ for (const field of botWakeFields) expect(keys).toContain(field.key);++ const allow = larkBotWakeFields.find((f) => f.key === BOT_WAKE_SETTING_KEYS.allowChannels)!;+ expect(allow.items?.properties?.[0].placeholder).toBe(+ 'channel.botWakeChannelIdPlaceholderLark',+ );+ // Discord's "a channel and its threads count as one place" does not describe a Feishu group.+ const scope = larkBotWakeFields.find((f) => f.key === BOT_WAKE_SETTING_KEYS.scope)!;+ expect(scope.enumDescriptions).toContain('channel.botWakeScopeBotThreadsHintLark');+ expect(agentLocale['channel.botWakeScopeBotThreadsHintLark']).not.toMatch(/discord/i);+ expect(+ larkBotWakeFields.flatMap(referencedKeys).filter((key) => !(key in agentLocale)),+ ).toEqual([]);+ });});diff --git a/apps/server/src/services/bot/platforms/botWakeFields.ts b/apps/server/src/services/bot/platforms/botWakeFields.tsindex e4e43459327..323ca2b0485 100644--- a/apps/server/src/services/bot/platforms/botWakeFields.ts+++ b/apps/server/src/services/bot/platforms/botWakeFields.ts@@ -21,7 +21,7 @@ const CUSTOM_PACE = [ENABLED, { field: KEY.pace, value: 'custom' }];/** Visible lines of the custom-instructions and duties text areas. */const CUSTOM_INSTRUCTIONS_ROWS = 10;-const channelList = (key: string, label: string): FieldSchema => ({+const channelList = (key: string, label: string, idPlaceholder: string): FieldSchema => ({key,default: [],description: `${label}Hint`,@@ -40,7 +40,7 @@ const channelList = (key: string, label: string): FieldSchema => ({{key: 'id',label: 'channel.botWakeChannelIdLabel',- placeholder: 'channel.botWakeChannelIdPlaceholder',+ placeholder: idPlaceholder,required: true,type: 'string',},@@ -58,7 +58,15 @@ const channelList = (key: string, label: string): FieldSchema => ({* timings until it is set to `enforce`, and the whole group until the `bot_wake` rollout reaches* the signed-in user.*/-export const botWakeFields: FieldSchema[] = [+export const makeBotWakeFields = ({+ channelIdPlaceholder = 'channel.botWakeChannelIdPlaceholder',+ scopeBotThreadsHint = 'channel.botWakeScopeBotThreadsHint',+}: {+ /** How the platform's conversation ids look, shown in the channel lists. */+ channelIdPlaceholder?: string;+ /** What "where it already spoke" covers on the platform. */+ scopeBotThreadsHint?: string;+} = {}): FieldSchema[] => [{key: KEY.enabled,default: false,@@ -80,7 +88,7 @@ export const botWakeFields: FieldSchema[] = [enum: ['all', 'bot-threads', 'none'],enumDescriptions: ['channel.botWakeScopeAllHint',- 'channel.botWakeScopeBotThreadsHint',+ scopeBotThreadsHint,'channel.botWakeScopeNoneHint',],enumLabels: [@@ -89,8 +97,8 @@ export const botWakeFields: FieldSchema[] = ['channel.botWakeScopeNone',],},- channelList(KEY.allowChannels, 'channel.botWakeAllowChannels'),- channelList(KEY.denyChannels, 'channel.botWakeDenyChannels'),+ channelList(KEY.allowChannels, 'channel.botWakeAllowChannels', channelIdPlaceholder),+ channelList(KEY.denyChannels, 'channel.botWakeDenyChannels', channelIdPlaceholder),{key: KEY.pace,default: 'balanced',@@ -241,3 +249,11 @@ export const botWakeFields: FieldSchema[] = [visibleWhen: [...CUSTOM_PACE, { field: KEY.schedulerMode, value: 'enforce' }],},];++export const botWakeFields: FieldSchema[] = makeBotWakeFields();++/** Feishu / Lark: a conversation is a group chat, and the lists take its id (`oc_…`). */+export const larkBotWakeFields: FieldSchema[] = makeBotWakeFields({+ channelIdPlaceholder: 'channel.botWakeChannelIdPlaceholderLark',+ scopeBotThreadsHint: 'channel.botWakeScopeBotThreadsHintLark',+});diff --git a/apps/server/src/services/bot/platforms/feishu/definitions/schema.ts b/apps/server/src/services/bot/platforms/feishu/definitions/schema.tsindex 566fbfd3bbf..8e6f1a116d7 100644--- a/apps/server/src/services/bot/platforms/feishu/definitions/schema.ts+++ b/apps/server/src/services/bot/platforms/feishu/definitions/schema.ts@@ -5,6 +5,7 @@ import {MIN_BOT_HISTORY_LIMIT,} from '@lobechat/const';+import { larkBotWakeFields } from '../../botWakeFields';import {allowFromField,displayToolCallsField,@@ -125,6 +126,7 @@ export const sharedSchema: FieldSchema[] = [...makeGroupPolicyFields({ policy: 'open' }),allowFromField,watchKeywordsField,+ ...larkBotWakeFields,...replyStyleFields,],type: 'object',diff --git a/apps/server/src/services/bot/wake/__tests__/scheduler.test.ts b/apps/server/src/services/bot/wake/__tests__/scheduler.test.tsindex 8086c18f15c..e070df699a1 100644--- a/apps/server/src/services/bot/wake/__tests__/scheduler.test.ts+++ b/apps/server/src/services/bot/wake/__tests__/scheduler.test.ts@@ -201,6 +201,21 @@ describe('wake scheduler wiring', () => {);});+ it('is kept in the shared log of a Feishu group', async () => {+ await recordWakeRunOutcome({+ ...base,+ platform: 'feishu',+ platformThreadId: 'feishu:group:oc_1',+ spoke: true,+ spoken,+ });++ expect(mocks.botWake.rememberMessages).toHaveBeenCalledWith(+ ['feishu:group:oc_1'],+ [expect.objectContaining({ id: 'bot:op-1', isBot: true })],+ );+ });+it.each([{ name: 'the bot stayed silent', input: { spoke: false, spoken } },{ name: 'there is no text to keep', input: { spoke: true, spoken: { id: 'op-1' } } },@@ -208,6 +223,10 @@ describe('wake scheduler wiring', () => {name: 'it was a direct message',input: { platformThreadId: 'discord:@me:dm1', spoke: true, spoken },},+ {+ name: 'it was a Feishu direct message',+ input: { platform: 'feishu', platformThreadId: 'feishu:p2p:oc_1', spoke: true, spoken },+ },{ name: 'the platform has no log yet', input: { platform: 'slack', spoke: true, spoken } },])('is not kept when $name', async ({ input }) => {await recordWakeRunOutcome({ ...base, ...input });diff --git a/apps/server/src/services/bot/wake/scheduler.ts b/apps/server/src/services/bot/wake/scheduler.tsindex 9eed85f452f..a02e74b0816 100644--- a/apps/server/src/services/bot/wake/scheduler.ts+++ b/apps/server/src/services/bot/wake/scheduler.ts@@ -6,6 +6,7 @@ import { appEnv } from '@/envs/app';import { parseBotWakeSettings } from '@/server/services/agentSignal/scenarios/botWake/config';import { toConversationLine } from '@/server/services/agentSignal/scenarios/botWake/conversation';import {+ hasConversationLog,resolveChannelKeys,resolveConversationLogKeys,wakeStateKeys,@@ -181,7 +182,7 @@ const rememberBotReply = async ({platformThreadId: string;spoken?: { id: string; text?: string };}) => {- if (platform !== 'discord' || platformThreadId.split(':')[1] === '@me') return;+ if (!hasConversationLog(platform, platformThreadId)) return;try {const line = toConversationLine({diff --git a/apps/server/src/services/bot/wake/signal.ts b/apps/server/src/services/bot/wake/signal.tsindex 278ce270a36..a4e5ac5e53c 100644--- a/apps/server/src/services/bot/wake/signal.ts+++ b/apps/server/src/services/bot/wake/signal.ts@@ -17,7 +17,7 @@ export interface WakeMessageLike {id: string;isMention?: boolean;/** `edited` is set when the message was dispatched from an edit rather than its first send. */- metadata?: { edited?: boolean; editedAt?: Date };+ metadata?: { dateSent?: Date; edited?: boolean; editedAt?: Date };raw?: unknown;text?: string;}diff --git a/locales/en-US/agent.json b/locales/en-US/agent.jsonindex 0c84501c859..f561df89057 100644--- a/locales/en-US/agent.json+++ b/locales/en-US/agent.json@@ -70,6 +70,7 @@"channel.botWakeAllowChannelsHint": "Channel or thread IDs where the bot may join. Leave empty for no limit.","channel.botWakeChannelIdLabel": "Channel ID","channel.botWakeChannelIdPlaceholder": "e.g. 1234567890",+ "channel.botWakeChannelIdPlaceholderLark": "Group chat ID, e.g. oc_a0553eda9014c201e6969b478895c230","channel.botWakeClassifierThreshold": "Follow-up sensitivity","channel.botWakeClassifierThresholdHint": "Right after the bot replied, how sure it must be that a message is still for it before it joins, from 0 to 1. A higher value makes it join less often.","channel.botWakeCollectSeconds": "Collect for (seconds)",@@ -117,6 +118,7 @@"channel.botWakeScopeAllHint": "Any channel or thread the bot can read.","channel.botWakeScopeBotThreads": "Only where it already spoke","channel.botWakeScopeBotThreadsHint": "A channel or thread where the bot posted within the follow-up window. Discord counts a channel and its threads as one place.",+ "channel.botWakeScopeBotThreadsHintLark": "A group chat where the bot posted within the follow-up window.","channel.botWakeScopeHint": "Limits the places where the bot may join unprompted.","channel.botWakeScopeNone": "Nowhere","channel.botWakeScopeNoneHint": "The bot never joins unprompted.",@@ -536,6 +538,8 @@"channel.verificationTokenHint": "Optional. Used to verify webhook event source.","channel.verificationTokenPlaceholder": "Paste your verification token here","channel.wake.intro": "Lets the bot speak up when nobody @-mentioned it: when a message calls it by name, when someone follows up soon after it spoke, or when a watch keyword matches. It judges each message first, and may choose to stay silent.",+ "channel.wake.feishuScope.title": "Group messages need an extra permission",+ "channel.wake.feishuScope.desc": "To hear group messages that do not @-mention the bot, the app needs the im:message.group_msg scope. If other bots share the group, also add im:message.group_msg.include_bot:read so the bot sees what they say when it decides whether to step in. Add scopes under Permissions & Scopes in the developer console, then create and publish a new version. Apps made with one-click setup already have the first one.","channel.wake.section.channels": "Channels","channel.wake.section.channelsDesc": "Where the bot may join a conversation nobody addressed to it.","channel.wake.section.judgement": "Duties",diff --git a/locales/zh-CN/agent.json b/locales/zh-CN/agent.jsonindex b6d7fc45474..fe38f6c8ab2 100644--- a/locales/zh-CN/agent.json+++ b/locales/zh-CN/agent.json@@ -70,6 +70,7 @@"channel.botWakeAllowChannelsHint": "允许机器人参与的频道或子区 ID。留空表示不限制。","channel.botWakeChannelIdLabel": "频道 ID","channel.botWakeChannelIdPlaceholder": "例如 1234567890",+ "channel.botWakeChannelIdPlaceholderLark": "群聊 ID,例如 oc_a0553eda9014c201e6969b478895c230","channel.botWakeClassifierThreshold": "跟进灵敏度","channel.botWakeClassifierThresholdHint": "机器人刚回复过后,要多确定一条消息仍是对它说的,才会接话,范围 0 到 1。越高,它接话越少。","channel.botWakeCollectSeconds": "收集时长(秒)",@@ -117,6 +118,7 @@"channel.botWakeScopeAllHint": "机器人能读到的任何频道或子区。","channel.botWakeScopeBotThreads": "仅限它发过言的地方","channel.botWakeScopeBotThreadsHint": "机器人在追问时间窗内发过言的频道或子区。Discord 会把一个频道和它的子区算作同一处。",+ "channel.botWakeScopeBotThreadsHintLark": "机器人在追问时间窗内发过言的群聊。","channel.botWakeScopeHint": "限定机器人可以主动参与的位置。","channel.botWakeScopeNone": "不主动参与","channel.botWakeScopeNoneHint": "机器人不会主动插话。",@@ -536,6 +538,8 @@"channel.verificationTokenHint": "可选。用于验证事件推送来源。","channel.verificationTokenPlaceholder": "在此粘贴你的 Verification Token","channel.wake.intro": "没人 @ 它时,机器人也能主动参与:消息里直接叫了它的名字、在它刚发言不久后有人接着说,或命中了监听关键词。它会先判断这条消息是不是在对它说,也可以选择不回复。",+ "channel.wake.feishuScope.title": "群消息需要额外权限",+ "channel.wake.feishuScope.desc": "要收到群里没有 @ 机器人的消息,应用需开通「获取群组中所有消息」(im:message.group_msg)权限。群里还有其他机器人时,再开通「获取群组中用户和机器人发送的消息」(im:message.group_msg.include_bot:read),机器人判断要不要插话时才能看到它们说了什么。在开发者后台「权限管理」中添加后,需创建版本并发布才会生效。一键创建的应用已自带第一项权限。","channel.wake.section.channels": "频道","channel.wake.section.channelsDesc": "机器人可以在哪些频道里,主动参与没人叫它的对话。","channel.wake.section.judgement": "职责边界",diff --git a/packages/locales/src/default/agent.ts b/packages/locales/src/default/agent.tsindex 6715fa94f13..1ae9ca9b3eb 100644--- a/packages/locales/src/default/agent.ts+++ b/packages/locales/src/default/agent.ts@@ -475,6 +475,8 @@ export default {'channel.botWakeScopeBotThreads': 'Only where it already spoke','channel.botWakeScopeBotThreadsHint':'A channel or thread where the bot posted within the follow-up window. Discord counts a channel and its threads as one place.',+ 'channel.botWakeScopeBotThreadsHintLark':+ 'A group chat where the bot posted within the follow-up window.','channel.botWakeScopeNone': 'Nowhere','channel.botWakeScopeNoneHint': 'The bot never joins unprompted.','channel.botWakeAllowChannels': 'Allowed channels',@@ -489,6 +491,8 @@ export default {'channel.botWakeDenyChannelsEmpty': 'No channels blocked.','channel.botWakeChannelIdLabel': 'Channel ID','channel.botWakeChannelIdPlaceholder': 'e.g. 1234567890',+ 'channel.botWakeChannelIdPlaceholderLark':+ 'Group chat ID, e.g. oc_a0553eda9014c201e6969b478895c230','channel.channelListLimit': 'Lists hold at most {{max}} entries — remove one first.','channel.botWakePace': 'How often it joins','channel.botWakePaceHint':@@ -650,6 +654,9 @@ export default {'channel.tab.wake': 'Wake policy','channel.wake.intro':'Lets the bot speak up when nobody @-mentioned it: when a message calls it by name, when someone follows up soon after it spoke, or when a watch keyword matches. It judges each message first, and may choose to stay silent.',+ 'channel.wake.feishuScope.title': 'Group messages need an extra permission',+ 'channel.wake.feishuScope.desc':+ 'To hear group messages that do not @-mention the bot, the app needs the im:message.group_msg scope. If other bots share the group, also add im:message.group_msg.include_bot:read so the bot sees what they say when it decides whether to step in. Add scopes under Permissions & Scopes in the developer console, then create and publish a new version. Apps made with one-click setup already have the first one.','channel.wake.section.keywords': 'Keywords','channel.wake.section.channels': 'Channels','channel.wake.section.channelsDesc':diff --git a/src/features/AgentChannel/PlatformDetail/Body.botWake.test.tsx b/src/features/AgentChannel/PlatformDetail/Body.botWake.test.tsxindex f25c27a7421..9fcb15acfe1 100644--- a/src/features/AgentChannel/PlatformDetail/Body.botWake.test.tsx+++ b/src/features/AgentChannel/PlatformDetail/Body.botWake.test.tsx@@ -8,6 +8,7 @@ import { describe, expect, it, vi } from 'vitest';import { flattenBotWakeSettings } from '@/server/services/agentSignal/scenarios/botWake/config';import { schema as discordSchema } from '@/server/services/bot/platforms/discord/schema';+import { sharedSchema as feishuSchema } from '@/server/services/bot/platforms/feishu/definitions/schema';import type { SerializedPlatformDefinition } from '@/server/services/bot/platforms/types';import agentZh from '../../../../locales/zh-CN/agent.json';@@ -74,21 +75,30 @@ const platformDef = {schema: discordSchema,} as unknown as SerializedPlatformDefinition;+const feishuDef = {+ documentation: {},+ id: 'feishu',+ name: 'Feishu',+ schema: feishuSchema,+} as unknown as SerializedPlatformDefinition;+/** Mounts the form the way the channel page does: a saved bot, its settings merged with the defaults. */const Harness = ({activeTab = 'wake',+ def = platformDef,moduleControls,settings,}: {activeTab?: 'reply' | 'wake';+ def?: SerializedPlatformDefinition;moduleControls?: ModuleControls;settings?: Record<string, unknown>;}) => {const form = useForm<ChannelFormValues>();// The page switches the master on for a user the options are released to.const saved = withWakeMasterOn(- mergeSettingsWithDefaults(discordSchema, settings ?? {}),- isWakeMasterReleased(discordSchema, state.featureFlags),+ mergeSettingsWithDefaults(def.schema, settings ?? {}),+ isWakeMasterReleased(def.schema, state.featureFlags),);useEffect(() => {@@ -105,7 +115,7 @@ const Harness = ({currentConfig={{ applicationId: '1', credentials: {}, settings: saved }}form={form}moduleControls={moduleControls}- platformDef={platformDef}+ platformDef={def}/>);};@@ -190,6 +200,26 @@ describe('channel settings form: bot-wake options', () => {expect(screen.getByText(en['channel.wake.intro'])).toBeInTheDocument();});+ it('offers them on Feishu too, naming the scope that lets the bot hear group messages', () => {+ state.copy = en;+ state.featureFlags = { enableBotWake: true };++ render(<Harness def={feishuDef} />);++ expect(screen.getByText(en['channel.wake.intro'])).toBeInTheDocument();+ expect(screen.getByText(en['channel.botWakeScope'])).toBeInTheDocument();+ expect(screen.getByText(en['channel.wake.feishuScope.desc'])).toBeInTheDocument();+ });++ it('names no Feishu scope on Discord', () => {+ state.copy = en;+ state.featureFlags = { enableBotWake: true };++ render(<Harness />);++ expect(screen.queryByText(en['channel.wake.feishuScope.desc'])).not.toBeInTheDocument();+ });+it('opens straight onto the options for a bot that already has them on', () => {state.copy = en;state.featureFlags = { enableBotWake: true };diff --git a/src/features/AgentChannel/PlatformDetail/Body.tsx b/src/features/AgentChannel/PlatformDetail/Body.tsxindex 58593ecf524..13bcbd52610 100644--- a/src/features/AgentChannel/PlatformDetail/Body.tsx+++ b/src/features/AgentChannel/PlatformDetail/Body.tsx@@ -16,6 +16,7 @@ import {platformCredentialBodyMap,platformCredentialExtrasMap,platformSettingsFieldExtrasMap,+ platformWakeNoticeMap,} from '../platform/registry';import { getInlineFieldKeys } from '../quickSetup/guides';import QuickSetupSection from '../quickSetup/QuickSetupSection';@@ -123,6 +124,7 @@ const Body = memo<BodyProps>(const CustomCredentialBody = platformCredentialBodyMap[platformDef.id];const CredentialExtras = platformCredentialExtrasMap[platformDef.id];+ const WakeNotice = platformWakeNoticeMap[platformDef.id];// Fields behind a rollout flag stay hidden until the user's flag is on (and// while the flags have not loaded yet).@@ -372,6 +374,7 @@ const Body = memo<BodyProps>({t('channel.wake.intro')}</Text>)}+ {group.key === 'wake' && WakeNotice && <WakeNotice />}{group.key === 'reply' && hasConfig && (<Text fontSize={12} type={'secondary'}>{t('channel.reply.instant')}diff --git a/src/features/AgentChannel/platform/feishu/WakeNotice.tsx b/src/features/AgentChannel/platform/feishu/WakeNotice.tsxnew file mode 100644index 00000000000..827a7be3865--- /dev/null+++ b/src/features/AgentChannel/platform/feishu/WakeNotice.tsx@@ -0,0 +1,29 @@+'use client';++import { Alert } from '@lobehub/ui';+import { memo } from 'react';+import { useTranslation } from 'react-i18next';++/**+ * Feishu / Lark push a group message the bot was not @-mentioned in only when the app holds+ * `im:message.group_msg`, and another bot's message only with+ * `im:message.group_msg.include_bot:read` on top. Without the first, keywords and wake rules save+ * fine but never fire; without the second, the wake judgement never sees what other bots said.+ * Nothing on the page would say why, so the wake tab names both scopes up front.+ */+const FeishuWakeNotice = memo(() => {+ const { t } = useTranslation('agent');++ return (+ <Alert+ showIcon+ description={t('channel.wake.feishuScope.desc')}+ title={t('channel.wake.feishuScope.title')}+ type={'info'}+ />+ );+});++FeishuWakeNotice.displayName = 'FeishuWakeNotice';++export default FeishuWakeNotice;diff --git a/src/features/AgentChannel/platform/registry.ts b/src/features/AgentChannel/platform/registry.tsindex 496eeba63a9..953f795e2ab 100644--- a/src/features/AgentChannel/platform/registry.ts+++ b/src/features/AgentChannel/platform/registry.ts@@ -2,6 +2,7 @@ import type { ComponentType } from 'react';import { FeishuUserIdExtras } from '@/features/AgentSetting/AgentChannel/feishu/UserIdExtras';+import FeishuWakeNotice from './feishu/WakeNotice';import ImessageCredentialExtras from './imessage/CredentialExtras';import LineCredentialExtras from './line/CredentialExtras';import type {@@ -50,3 +51,12 @@ export const platformSettingsFieldExtrasMap: Record<'feishu:userId': FeishuUserIdExtras,'lark:userId': FeishuUserIdExtras,};++/**+ * A notice at the top of the wake tab, keyed by platform id, for what the platform needs before+ * the bot can hear messages nobody addressed to it.+ */+export const platformWakeNoticeMap: Record<string, ComponentType> = {+ feishu: FeishuWakeNotice,+ lark: FeishuWakeNotice,+};