Skip to content

🤯 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.

💬 fix(bot): say the sender lacks permission when group policy is disabled (#22187)

Rdmclin2306d2b8fb2a3
diff --git a/apps/server/src/services/bot/BotMessageRouter/index.policy.test.ts b/apps/server/src/services/bot/BotMessageRouter/index.policy.test.ts
index 61b997ac35a..832d9f19985 100644
--- a/apps/server/src/services/bot/BotMessageRouter/index.policy.test.ts
+++ b/apps/server/src/services/bot/BotMessageRouter/index.policy.test.ts
@@ -269,7 +269,7 @@ describe('BotMessageRouter', () => {
expect(mockHandleSubscribedMessage).not.toHaveBeenCalled();
expect(thread.post).toHaveBeenCalledTimes(1);
- expect(thread.post.mock.calls[0][0]).toContain("doesn't respond in groups or channels");
+ expect(thread.post.mock.calls[0][0]).toContain("don't have permission to talk to this bot");
});
it('blocks @-mentions on the new-mention path when group policy is disabled', async () => {
@@ -280,7 +280,23 @@ describe('BotMessageRouter', () => {
expect(mockHandleMention).not.toHaveBeenCalled();
expect(thread.post).toHaveBeenCalledTimes(1);
- expect(thread.post.mock.calls[0][0]).toContain("doesn't respond in groups or channels");
+ expect(thread.post.mock.calls[0][0]).toContain("don't have permission to talk to this bot");
+ });
+
+ it('still lets the owner @-mention the bot in groups when group policy is disabled', async () => {
+ // `disabled` means "only the owner here", not "the bot can't talk in
+ // groups" — which is why the rejection copy names the missing permission.
+ const { mention } = await loadHandlers({ groupPolicy: 'disabled', userId: 'owner-id' });
+ const thread = makeGroupThread('channel-1');
+
+ await mention(thread, {
+ author: { isBot: false, userId: 'owner-id', userName: 'owner' },
+ isMention: true,
+ text: '@bot hi',
+ });
+
+ expect(mockHandleMention).toHaveBeenCalledTimes(1);
+ expect(thread.post).not.toHaveBeenCalled();
});
it('allows open Telegram Guest Mode summons even when group policy is disabled', async () => {
diff --git a/apps/server/src/services/bot/__tests__/replyTemplate.test.ts b/apps/server/src/services/bot/__tests__/replyTemplate.test.ts
index c38d7879f6e..2ac1a0ab45e 100644
--- a/apps/server/src/services/bot/__tests__/replyTemplate.test.ts
+++ b/apps/server/src/services/bot/__tests__/replyTemplate.test.ts
@@ -867,12 +867,19 @@ describe('replyTemplate', () => {
describe('renderGroupRejected', () => {
it('renders disabled and allowlist English copy', () => {
- expect(renderGroupRejected('disabled')).toContain("doesn't respond in groups or channels");
+ const disabled = renderGroupRejected('disabled');
+ expect(disabled).toContain("don't have permission to talk to this bot");
+ // The owner can use the bot in groups, and DMs may be gated too — the
+ // notice must not claim the bot is silent in groups or redirect to DM.
+ // It also can't promise the owner can: the owner ID may be unset.
+ expect(disabled).not.toMatch(/doesn't respond|direct message/i);
expect(renderGroupRejected('allowlist')).toContain("isn't enabled in this channel");
});
it('renders disabled and allowlist Chinese copy when locale is zh-CN', () => {
- expect(renderGroupRejected('disabled', 'zh-CN')).toContain('不在群组或频道中响应');
+ const disabled = renderGroupRejected('disabled', 'zh-CN');
+ expect(disabled).toContain('没有在群组或频道中与该机器人对话的权限');
+ expect(disabled).not.toMatch(/不在群组|私信/);
expect(renderGroupRejected('allowlist', 'zh-CN')).toContain('未在此频道启用');
});
});
diff --git a/apps/server/src/services/bot/replyTemplate.ts b/apps/server/src/services/bot/replyTemplate.ts
index abca5eb5de5..77a8e064e48 100644
--- a/apps/server/src/services/bot/replyTemplate.ts
+++ b/apps/server/src/services/bot/replyTemplate.ts
@@ -426,7 +426,7 @@ const SYSTEM_STRINGS: Partial<Record<BotReplyLocale, SystemStrings>> = {
groupRejectedAllowlist:
"This bot isn't enabled in this channel. Please contact the bot's owner if you need access.",
groupRejectedDisabled:
- "This bot doesn't respond in groups or channels. Please reach out via direct message instead.",
+ "Sorry, you don't have permission to talk to this bot in groups or channels. Please contact the bot's owner if you need access.",
guestAttachmentOverflow:
'<i>Additional attachments could not be listed in this Guest Mode reply.</i>',
guestLinkButton: 'Open Bot',
@@ -551,7 +551,8 @@ const SYSTEM_STRINGS: Partial<Record<BotReplyLocale, SystemStrings>> = {
: `**Agent 执行失败**,详细信息:\n\`\`\`\n${details}\n\`\`\``,
errorWithId: (operationId) => `**Agent 执行失败**\nOperation ID: \`${operationId}\``,
groupRejectedAllowlist: '该机器人未在此频道启用。如需访问请联系机器人管理员。',
- groupRejectedDisabled: '该机器人不在群组或频道中响应。请通过私信联系。',
+ groupRejectedDisabled:
+ '抱歉,您没有在群组或频道中与该机器人对话的权限。如需访问请联系机器人主人。',
guestAttachmentOverflow: '<i>更多附件无法在这条访客模式回复中列出。</i>',
guestLinkButton: '打开机器人',
guestLinkPromptChat: '请在私聊中继续,以完成 LobeHub 账户关联。',
@@ -973,8 +974,16 @@ export function renderDmRejected(reason: 'disabled' | 'allowlist', lng?: BotRepl
/**
* Render the system message shown when an inbound non-DM event was blocked
- * by Group Policy. Same disabled-vs-allowlist split as
- * {@link renderDmRejected} so the sender can pivot (try DM, ask the owner).
+ * by Group Policy. Same disabled-vs-allowlist split as {@link renderDmRejected}.
+ *
+ * The bot's owner bypasses Group Policy (see `passGatesOrNotify`), so the bot
+ * *does* speak in groups — `disabled` really means "only the owner may use it
+ * in the groups it has joined" — or nobody, when no owner identity is
+ * configured. (Telegram Guest Mode summons skip Group Policy and follow Guest
+ * Policy instead, so they never reach this notice.) The copy therefore
+ * names the missing permission instead of claiming the bot can't talk in
+ * groups, never promises the owner can (it may be unset), and never points the
+ * sender to a DM (the DM policy may reject them just the same).
*/
export function renderGroupRejected(
reason: 'disabled' | 'allowlist',
diff --git a/locales/en-US/agent.json b/locales/en-US/agent.json
index e35a98dba07..d042bd20fbb 100644
--- a/locales/en-US/agent.json
+++ b/locales/en-US/agent.json
@@ -19,8 +19,8 @@
"channel.access.dm.listedDesc": "Only listed people can use it; everyone else is turned away.",
"channel.access.group.allowlist": "Only chosen groups",
"channel.access.group.allowlistDesc": "Replies only in the groups you list below.",
- "channel.access.group.disabled": "Not in groups",
- "channel.access.group.disabledDesc": "It ignores group messages and points people to a DM.",
+ "channel.access.group.disabled": "Only me in groups",
+ "channel.access.group.disabledDesc": "In groups and channels it has joined, only you can use it (once your own ID is set above); others are told they lack permission. Telegram Guest Mode follows its own setting.",
"channel.access.group.label": "How it responds in groups and channels",
"channel.access.group.listNote": "The people list above also applies here: only people on it can use the bot in groups.",
"channel.access.group.open": "Every group and channel",
@@ -434,7 +434,7 @@
"channel.quickView.dm.disabled": "This bot isn't accepting direct messages. Please reach out by mentioning it in a shared channel or group instead.",
"channel.quickView.dm.pairing": "To DM this bot, send this pairing code to the bot's owner: 7K2F. They run /approve 7K2F to grant you access. The code expires in 1 hour.",
"channel.quickView.group.allowlist": "This bot isn't enabled in this channel. Please contact the bot's owner if you need access.",
- "channel.quickView.group.disabled": "This bot doesn't respond in groups or channels. Please reach out via direct message instead.",
+ "channel.quickView.group.disabled": "Sorry, you don't have permission to talk to this bot in groups or channels. Please contact the bot's owner if you need access.",
"channel.quickView.groupAllowlist": "Replies only in the groups on your list.",
"channel.quickView.keywords": "Also wakes on {{keywords}} without an @mention.",
"channel.quickView.open": "Preview",
diff --git a/locales/zh-CN/agent.json b/locales/zh-CN/agent.json
index 34266eb574a..166e566a88a 100644
--- a/locales/zh-CN/agent.json
+++ b/locales/zh-CN/agent.json
@@ -19,8 +19,8 @@
"channel.access.dm.listedDesc": "只有名单里的人能使用,其他人会被拒绝。",
"channel.access.group.allowlist": "仅指定的群聊",
"channel.access.group.allowlistDesc": "只在你列在下面的群聊里回复。",
- "channel.access.group.disabled": "不在群聊里响应",
- "channel.access.group.disabledDesc": "不处理群聊消息,会引导对方私聊。",
+ "channel.access.group.disabled": "群聊里仅自己可用",
+ "channel.access.group.disabledDesc": "在机器人已加入的群聊和频道里只有你能使用(需先在上方填写你自己的 ID),其他人会收到无权限提示;Telegram 访客模式按其单独设置。",
"channel.access.group.label": "在群聊和频道里怎么响应",
"channel.access.group.listNote": "上面的名单在群聊里也生效:只有名单里的人能在群聊里使用它。",
"channel.access.group.open": "所有群聊和频道",
@@ -434,7 +434,7 @@
"channel.quickView.dm.disabled": "该机器人不接受私信。请在共享频道或群组里 @它来联系。",
"channel.quickView.dm.pairing": "若要私信该机器人,请把以下配对码发给机器人管理员:7K2F,他们将通过 /approve 7K2F 命令为你授权。配对码 1 小时后失效。",
"channel.quickView.group.allowlist": "该机器人未在此频道启用。如需访问请联系机器人管理员。",
- "channel.quickView.group.disabled": "该机器人不在群组或频道中响应。请通过私信联系。",
+ "channel.quickView.group.disabled": "抱歉,您没有在群组或频道中与该机器人对话的权限。如需访问请联系机器人主人。",
"channel.quickView.groupAllowlist": "只会在名单内的群聊里回复。",
"channel.quickView.keywords": "消息里出现 {{keywords}} 时,不用 @ 也会唤醒它。",
"channel.quickView.open": "预览",
diff --git a/packages/locales/src/default/agent.ts b/packages/locales/src/default/agent.ts
index 6f0b33940d3..ac7bac0d254 100644
--- a/packages/locales/src/default/agent.ts
+++ b/packages/locales/src/default/agent.ts
@@ -574,7 +574,7 @@ export default {
'channel.quickView.dm.disabled':
"This bot isn't accepting direct messages. Please reach out by mentioning it in a shared channel or group instead.",
'channel.quickView.group.disabled':
- "This bot doesn't respond in groups or channels. Please reach out via direct message instead.",
+ "Sorry, you don't have permission to talk to this bot in groups or channels. Please contact the bot's owner if you need access.",
'channel.quickView.group.allowlist':
"This bot isn't enabled in this channel. Please contact the bot's owner if you need access.",
'channel.quickView.sender.rejected':
@@ -609,8 +609,9 @@ export default {
'channel.access.group.openDesc': 'Replies whenever it is @mentioned.',
'channel.access.group.allowlist': 'Only chosen groups',
'channel.access.group.allowlistDesc': 'Replies only in the groups you list below.',
- 'channel.access.group.disabled': 'Not in groups',
- 'channel.access.group.disabledDesc': 'It ignores group messages and points people to a DM.',
+ 'channel.access.group.disabled': 'Only me in groups',
+ 'channel.access.group.disabledDesc':
+ 'In groups and channels it has joined, only you can use it (once your own ID is set above); others are told they lack permission. Telegram Guest Mode follows its own setting.',
'channel.access.group.listNote':
'The people list above also applies here: only people on it can use the bot in groups.',
'channel.access.identity.desc':