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.

💄 style(channel): walk WeCom setup through create permission, long connection and chat usage (#23089)

Rdmclin2e18e7142da5a
diff --git a/docs/usage/channels/wecom.mdx b/docs/usage/channels/wecom.mdx
index 01816cbab9e..723ec1cd27b 100644
--- a/docs/usage/channels/wecom.mdx
+++ b/docs/usage/channels/wecom.mdx
@@ -21,7 +21,7 @@ LobeHub uses the AI bot's **API mode with a long connection**: LobeHub connects
## Prerequisites
-- A WeCom organization and an admin account for its admin console
+- A WeCom organization, and either an admin account or an admin who can grant you permission to create long-connection bots
- An unverified organization can have at most 100 members; WeCom's docs do not say whether an unverified organization can create AI bots
## Step 1: Create an AI bot
@@ -31,13 +31,21 @@ LobeHub uses the AI bot's **API mode with a long connection**: LobeHub connects
Go to the [WeCom admin console](https://work.weixin.qq.com/wework_admin/frame) and sign in.
+ ### Get permission to create long-connection bots
+
+ Admins can skip this. By default only admins can create AI bots that use a long connection; other members need an admin to grant them access under **Smart Zone → AI Bots → Permissions → API Mode Management**, and to add them to **Bot Creation Permission** on the same page if the organization restricts it (it is open to all members by default).
+
### Create a bot in API mode
- Go to **Smart Zone → AI Bots**, click **Create**, choose **API mode**, and receive messages over a **long connection**.
+ Go to **Smart Zone → AI Bots** and click **Create** (members can also use **Workbench → AI Bots** in the WeCom app), then choose to create it in **API mode**.
+
+ ### Choose long connection and set the visible range
+
+ On the API settings page, set the connection method to **Use long connection**, then set the bot's **visible range**: only members in it can find and use the bot. Leave the rest as is.
### Copy the BotID and Secret
- Copy the **BotID** and the long-connection **Secret** from the bot's API settings.
+ The page generates the **BotID** and **Secret**. Copy both and keep the Secret somewhere safe before you save the bot settings.
> **Important:** a bot can have only one long connection at a time. Connecting the same bot anywhere else (another deployment, a local dev environment, another tool) disconnects it from LobeHub.
</Steps>
@@ -61,8 +69,8 @@ LobeHub uses the AI bot's **API mode with a long connection**: LobeHub connects
## Step 3: Test it
-- **Direct chat:** find the bot in WeCom and send it a message. The bot shows a reply-in-progress bubble first, then fills in the answer.
-- **Group chat:** add the bot to an internal group chat and @-mention it. External and interconnected groups do not support bots.
+- **Direct chat:** members in the visible range find the bot under **AI Bots** in WeCom Contacts and send it a message. The bot shows a reply-in-progress bubble first, then fills in the answer.
+- **Group chat:** in an internal group chat, open the top-right corner → **Add members** → **AI Bots** to add the bot, then @-mention it. External, interconnected, and upstream/downstream groups do not support bots.
## Access policies
diff --git a/docs/usage/channels/wecom.zh-CN.mdx b/docs/usage/channels/wecom.zh-CN.mdx
index ee6150d09d2..2e5a0118609 100644
--- a/docs/usage/channels/wecom.zh-CN.mdx
+++ b/docs/usage/channels/wecom.zh-CN.mdx
@@ -19,7 +19,7 @@ LobeHub 使用企业微信智能机器人的 **API 模式 + 长连接**:由 Lo
## 前置条件
-- 一个企业微信企业,以及可以进入管理后台的管理员账号
+- 一个企业微信企业,以及管理员账号,或者能为你开通长连接机器人创建权限的管理员
- 未认证的企业最多 100 人使用企业微信;未认证企业能否创建智能机器人,官方文档没有说明
## 第一步:创建智能机器人
@@ -29,13 +29,21 @@ LobeHub 使用企业微信智能机器人的 **API 模式 + 长连接**:由 Lo
访问 [企业微信管理后台](https://work.weixin.qq.com/wework_admin/frame) 并登录。
+ ### 开通长连接机器人的创建权限
+
+ 企业管理员可跳过这一步。长连接方式的智能机器人默认只有管理员能创建,其他成员需请管理员在 **智能专区 → 智能机器人 → 权限管理 → API 模式管理** 中为你授权;如果企业在同一页限制了 **机器人创建权限**(默认全员开放),也要把你加进去。
+
### 创建 API 模式的机器人
- 进入 **智能专区 → 智能机器人**,点击 **创建**,选择 **API 模式**,并使用 **长连接** 接收消息。
+ 进入 **智能专区 → 智能机器人**,点击 **创建**(成员也可以在企业微信客户端的 **工作台 → 智能机器人** 中创建),选择 **API 模式创建**。
+
+ ### 选择长连接并设置可见范围
+
+ 在 API 配置页把连接方式选为 **使用长连接**,再设置机器人的 **可见范围**:范围内的成员才能找到和使用机器人。其余保持默认。
### 复制 BotID 和 Secret
- 在机器人的 API 配置中复制 **BotID** 和长连接 **Secret**。
+ 页面会生成 **BotID** 和 **Secret**。先把两者复制下来并妥善保存 Secret,再保存机器人配置。
> **重要提示:** 同一个机器人同一时间只能有一条长连接。在其他地方(另一套部署、本地开发环境、其他工具)接入同一个机器人,会让 LobeHub 这边的连接断开。
</Steps>
@@ -59,8 +67,8 @@ LobeHub 使用企业微信智能机器人的 **API 模式 + 长连接**:由 Lo
## 第三步:测试
-- **单聊:** 在企业微信里找到机器人,发一条消息。机器人会先显示正在回复的气泡,回复完成后填入内容。
-- **群聊:** 把机器人加入企业内部群,在消息里 @ 它。外部群和互联群不支持机器人。
+- **单聊:** 可见范围内的成员在企业微信通讯录的 **智能机器人** 分组里找到机器人,发一条消息。机器人会先显示正在回复的气泡,回复完成后填入内容。
+- **群聊:** 在企业内部群点右上角添加成员,选择 **智能机器人** 把它加进群,然后在消息里 @ 它。外部群、互联群和上下游群不支持机器人。
## 接入策略
diff --git a/locales/en-US/agent.json b/locales/en-US/agent.json
index baa5710fa9e..f377b8398e0 100644
--- a/locales/en-US/agent.json
+++ b/locales/en-US/agent.json
@@ -429,6 +429,7 @@
"channel.quickSetup.link.createLineAccount": "Create Official Account",
"channel.quickSetup.link.createSlackApp": "Create Slack app",
"channel.quickSetup.link.inviteBot": "Invite bot to server",
+ "channel.quickSetup.link.openAdminConsole": "Open admin console",
"channel.quickSetup.link.openBotFather": "Open BotFather",
"channel.quickSetup.link.openBotSettings": "Open bot settings",
"channel.quickSetup.link.openConsole": "Open developer console",
@@ -453,10 +454,16 @@
"channel.quickSetup.telegram.privacy.title": "Let it read group messages (optional)",
"channel.quickSetup.telegram.token.desc": "BotFather replies with a token like 1234567890:ABC… — paste it here.",
"channel.quickSetup.telegram.token.title": "Copy the token",
- "channel.quickSetup.wecom.create.desc": "In the WeCom admin console, go to Smart Zone → AI Bots, create a bot, and choose API mode with a long connection.",
+ "channel.quickSetup.wecom.access.desc": "Admins can skip this. Other members need an admin to grant them access under Smart Zone → AI Bots → Permissions → API Mode Management in the admin console, and to add them to Bot Creation Permission too if the organization restricts it.",
+ "channel.quickSetup.wecom.access.title": "Get permission to create long-connection bots",
+ "channel.quickSetup.wecom.connection.desc": "On the API settings page, set the connection method to Use long connection, then set the visible range: only members in it can find and use the bot. Leave the rest as is.",
+ "channel.quickSetup.wecom.connection.title": "Choose long connection and set the visible range",
+ "channel.quickSetup.wecom.create.desc": "In the admin console, go to Smart Zone → AI Bots and click Create, or open Workbench → AI Bots in the WeCom app. Choose to create it in API mode.",
"channel.quickSetup.wecom.create.title": "Create an AI bot in API mode",
- "channel.quickSetup.wecom.credentials.desc": "Find them in the bot's API settings. A bot can be connected to only one place at a time.",
+ "channel.quickSetup.wecom.credentials.desc": "The page generates the BotID and Secret. Copy them into the fields below and keep the Secret somewhere safe before you save the bot settings.",
"channel.quickSetup.wecom.credentials.title": "Copy the BotID and Secret",
+ "channel.quickSetup.wecom.usage.desc": "Members in the visible range find the bot under AI Bots in WeCom Contacts and can chat with it directly. To use it in a group, add it to an internal group from the top-right corner → Add members → AI Bots; there it replies only when @-mentioned. External, interconnected, and upstream/downstream groups aren't supported.",
+ "channel.quickSetup.wecom.usage.title": "Use it in direct and group chats",
"channel.quickView.answer": "Three things came up today: the release moved to Thursday, the sign-in page copy, and the priority of the bug list. Want me to turn them into to-dos?",
"channel.quickView.ask": "Summarize today's discussion",
"channel.quickView.askDm": "Can you summarize today's discussion?",
@@ -682,7 +689,7 @@
"channel.wecom.botId": "BotID",
"channel.wecom.botIdHint": "The BotID of your WeCom AI bot (API mode).",
"channel.wecom.secret": "Secret",
- "channel.wecom.secretHint": "The bot's long-connection Secret. Connecting the same bot anywhere else disconnects it here.",
+ "channel.wecom.secretHint": "The bot's long-connection Secret. A bot can be connected in only one place at a time: saving here takes over a connection it has elsewhere, and connecting it elsewhere later disconnects it here.",
"share.entry": "Share this Agent",
"share.settings.limits.desc": "Every visitor run is billed to your account, so these caps are what keep a shared link from running up your bill. They always apply — you can change the numbers, but not turn them off.",
"share.settings.limits.maxFileStorageHint": "Files visitors attach are stored on your account. Uploads stop once they reach this total; set 0 to turn attachments off.",
diff --git a/locales/zh-CN/agent.json b/locales/zh-CN/agent.json
index 1d3fff64772..37146bb41f1 100644
--- a/locales/zh-CN/agent.json
+++ b/locales/zh-CN/agent.json
@@ -429,6 +429,7 @@
"channel.quickSetup.link.createLineAccount": "创建官方账号",
"channel.quickSetup.link.createSlackApp": "一键创建 Slack 应用",
"channel.quickSetup.link.inviteBot": "邀请机器人进服务器",
+ "channel.quickSetup.link.openAdminConsole": "打开管理后台",
"channel.quickSetup.link.openBotFather": "打开 BotFather",
"channel.quickSetup.link.openBotSettings": "打开 Bot 设置",
"channel.quickSetup.link.openConsole": "打开开发者后台",
@@ -453,10 +454,16 @@
"channel.quickSetup.telegram.privacy.title": "允许读取群消息(可选)",
"channel.quickSetup.telegram.token.desc": "BotFather 会回复形如 1234567890:ABC… 的 Token,粘贴到这里即可。",
"channel.quickSetup.telegram.token.title": "复制 Token",
- "channel.quickSetup.wecom.create.desc": "在企业微信管理后台进入「智能专区 → 智能机器人」,创建机器人并选择 API 模式(长连接)。",
+ "channel.quickSetup.wecom.access.desc": "企业管理员可跳过这一步。其他成员需请管理员在管理后台「智能专区 → 智能机器人 → 权限管理 → API 模式管理」中为你授权;如果企业限制了「机器人创建权限」,也要把你加进去。",
+ "channel.quickSetup.wecom.access.title": "开通长连接机器人的创建权限",
+ "channel.quickSetup.wecom.connection.desc": "在 API 配置页把连接方式选为「使用长连接」,再设置可见范围:范围内的成员才能找到和使用机器人。其余保持默认。",
+ "channel.quickSetup.wecom.connection.title": "选择长连接并设置可见范围",
+ "channel.quickSetup.wecom.create.desc": "在管理后台「智能专区 → 智能机器人」点「创建」,或在企业微信客户端「工作台 → 智能机器人」中创建,选择「API 模式创建」。",
"channel.quickSetup.wecom.create.title": "创建 API 模式的智能机器人",
- "channel.quickSetup.wecom.credentials.desc": "在机器人的 API 配置中查看。同一个机器人同一时间只能接入一处。",
+ "channel.quickSetup.wecom.credentials.desc": "页面会生成 BotID 和 Secret。先复制并填到下面,妥善保存好 Secret,再保存机器人配置。",
"channel.quickSetup.wecom.credentials.title": "复制 BotID 和 Secret",
+ "channel.quickSetup.wecom.usage.desc": "可见范围内的成员在企业微信通讯录的「智能机器人」分组找到它,就能单聊。在企业内部群点右上角添加成员,选「智能机器人」把它加进群,群里 @ 它才会回复。外部群、互联群和上下游群不支持。",
+ "channel.quickSetup.wecom.usage.title": "在单聊和群聊中使用",
"channel.quickView.answer": "今天主要讨论了三件事:发布时间调整到周四、登录页的文案,以及 bug 列表的优先级。需要我整理成待办吗?",
"channel.quickView.ask": "帮我总结一下今天的讨论",
"channel.quickView.askDm": "能帮我总结一下今天的讨论吗?",
@@ -682,7 +689,7 @@
"channel.wecom.botId": "BotID",
"channel.wecom.botIdHint": "企业微信智能机器人(API 模式)的 BotID。",
"channel.wecom.secret": "Secret",
- "channel.wecom.secretHint": "机器人的长连接 Secret。在其他地方接入同一个机器人,会让这里的连接断开。",
+ "channel.wecom.secretHint": "机器人的长连接 Secret。同一个机器人同一时间只能接入一处:在这里保存会接管它在别处的连接,之后在别处接入也会让这里断开。",
"share.entry": "分享此助手",
"share.settings.limits.desc": "访客的每次运行都记在你的账户上,这些上限是分享链接不会跑出高额账单的唯一保障。上限始终生效,你可以调整数值,但不能关闭。",
"share.settings.limits.maxFileStorageHint": "访客上传的文件会存放在你的账号里。累计达到这个总量后就不能再上传;填 0 表示关闭附件功能。",
diff --git a/packages/locales/src/default/agent.ts b/packages/locales/src/default/agent.ts
index 159caf6247d..fdcbdef5948 100644
--- a/packages/locales/src/default/agent.ts
+++ b/packages/locales/src/default/agent.ts
@@ -8,6 +8,7 @@ export default {
'channel.quickSetup.link.openBotFather': 'Open BotFather',
'channel.quickSetup.link.openBotSettings': 'Open bot settings',
'channel.quickSetup.link.openConsole': 'Open developer console',
+ 'channel.quickSetup.link.openAdminConsole': 'Open admin console',
'channel.quickSetup.link.createLineAccount': 'Create Official Account',
'channel.quickSetup.link.openLineAccountManager': 'Open Official Account Manager',
'channel.quickSetup.link.openSlackApp': 'Open app settings',
@@ -82,12 +83,21 @@ export default {
'On the QQ Open Platform, create a bot and finish its basic setup.',
'channel.quickSetup.qq.credentials.title': 'Copy the App ID and App Secret',
'channel.quickSetup.qq.credentials.desc': "Find them in the bot's Development settings.",
+ 'channel.quickSetup.wecom.access.title': 'Get permission to create long-connection bots',
+ 'channel.quickSetup.wecom.access.desc':
+ 'Admins can skip this. Other members need an admin to grant them access under Smart Zone → AI Bots → Permissions → API Mode Management in the admin console, and to add them to Bot Creation Permission too if the organization restricts it.',
'channel.quickSetup.wecom.create.title': 'Create an AI bot in API mode',
'channel.quickSetup.wecom.create.desc':
- 'In the WeCom admin console, go to Smart Zone → AI Bots, create a bot, and choose API mode with a long connection.',
+ 'In the admin console, go to Smart Zone → AI Bots and click Create, or open Workbench → AI Bots in the WeCom app. Choose to create it in API mode.',
+ 'channel.quickSetup.wecom.connection.title': 'Choose long connection and set the visible range',
+ 'channel.quickSetup.wecom.connection.desc':
+ 'On the API settings page, set the connection method to Use long connection, then set the visible range: only members in it can find and use the bot. Leave the rest as is.',
'channel.quickSetup.wecom.credentials.title': 'Copy the BotID and Secret',
'channel.quickSetup.wecom.credentials.desc':
- "Find them in the bot's API settings. A bot can be connected to only one place at a time.",
+ 'The page generates the BotID and Secret. Copy them into the fields below and keep the Secret somewhere safe before you save the bot settings.',
+ 'channel.quickSetup.wecom.usage.title': 'Use it in direct and group chats',
+ 'channel.quickSetup.wecom.usage.desc':
+ "Members in the visible range find the bot under AI Bots in WeCom Contacts and can chat with it directly. To use it in a group, add it to an internal group from the top-right corner → Add members → AI Bots; there it replies only when @-mentioned. External, interconnected, and upstream/downstream groups aren't supported.",
'channel.quickSetup.dingtalk.create.title': 'Create an internal app',
'channel.quickSetup.dingtalk.create.desc':
'In the DingTalk developer console, create an internal app, then copy the Client ID and Client Secret from Credentials & Basic Info.',
@@ -353,7 +363,7 @@ export default {
'channel.wecom.botIdHint': 'The BotID of your WeCom AI bot (API mode).',
'channel.wecom.secret': 'Secret',
'channel.wecom.secretHint':
- "The bot's long-connection Secret. Connecting the same bot anywhere else disconnects it here.",
+ "The bot's long-connection Secret. A bot can be connected in only one place at a time: saving here takes over a connection it has elsewhere, and connecting it elsewhere later disconnects it here.",
'channel.wechat.description':
'Connect this agent to WeChat via iLink Bot for private and group chats.',
'channel.wechatQrExpired': 'QR code expired. Please refresh to get a new one.',
diff --git a/src/features/AgentChannel/quickSetup/guides.ts b/src/features/AgentChannel/quickSetup/guides.ts
index 8e0ff8c006b..36b20f681ba 100644
--- a/src/features/AgentChannel/quickSetup/guides.ts
+++ b/src/features/AgentChannel/quickSetup/guides.ts
@@ -21,6 +21,7 @@ export type SetupLinkLabel =
| 'inviteBot'
| 'openBotFather'
| 'openBotSettings'
+ | 'openAdminConsole'
| 'openLineAccountManager'
| 'openConsole'
| 'openSlackApp';
@@ -159,11 +160,20 @@ export const getSetupGuide = (
};
}
case 'wecom': {
+ // Long-connection bots can only be created by an admin until the admin grants members
+ // the right, and the bot reaches only the people in its visible range. Admins skip the
+ // permission step, so the admin-console link sits on the create step. The API settings
+ // page generates the BotID and Secret; they are copied before the bot settings are saved
+ // so the Secret is not lost. Using the bot (direct chat, internal groups) needs it
+ // connected, so that step follows the save.
return {
guide: 'wecom',
steps: [
- { key: 'create', link: { href: WECOM_ADMIN_CONSOLE_URL, label: 'openConsole' } },
+ { key: 'access' },
+ { key: 'create', link: { href: WECOM_ADMIN_CONSOLE_URL, label: 'openAdminConsole' } },
+ { key: 'connection' },
{ key: 'credentials', fields: ['applicationId', 'secret'] },
+ { key: 'usage' },
],
};
}
diff --git a/src/features/AgentChannel/quickSetup/quickSetup.test.ts b/src/features/AgentChannel/quickSetup/quickSetup.test.ts
index bba4bc35bb6..d48431ecad7 100644
--- a/src/features/AgentChannel/quickSetup/quickSetup.test.ts
+++ b/src/features/AgentChannel/quickSetup/quickSetup.test.ts
@@ -255,16 +255,36 @@ describe('getSetupGuide', () => {
expect(getInlineFieldKeys('wechat').size).toBe(0);
});
- it('walks WeCom from the admin console to the BotID and Secret', () => {
+ it('walks WeCom from the create permission to using the bot in chats', () => {
const guide = getSetupGuide('wecom', { appName: 'Moss' })!;
- expect(guide.steps.map((step) => step.key)).toEqual(['create', 'credentials']);
- expect(guide.steps[0].link).toEqual({
+ expect(guide.steps.map((step) => step.key)).toEqual([
+ 'access',
+ 'create',
+ 'connection',
+ 'credentials',
+ 'usage',
+ ]);
+ // WeCom has an admin console, not a developer console. Admins skip the permission step,
+ // so the one link sits on the create step that both paths go through.
+ expect(guide.steps[0].link).toBeUndefined();
+ expect(guide.steps[1].link).toEqual({
href: 'https://work.weixin.qq.com/wework_admin/frame',
- label: 'openConsole',
+ label: 'openAdminConsole',
});
+ expect(guide.steps.filter((step) => step.link)).toHaveLength(1);
expect([...getInlineFieldKeys('wecom')]).toEqual(['applicationId', 'secret']);
});
+ it('has English copy for every WeCom step and its link', () => {
+ for (const step of getSetupGuide('wecom', { appName: 'Moss' })!.steps) {
+ for (const part of ['title', 'desc'] as const) {
+ const key = `channel.quickSetup.wecom.${step.key}.${part}`;
+ expect(defaultAgentLocale[key as keyof typeof defaultAgentLocale], key).toBeTruthy();
+ }
+ }
+ expect(defaultAgentLocale['channel.quickSetup.link.openAdminConsole']).toBeTruthy();
+ });
+
it('asks to save right after the last step with a credential, before what needs a running bot', () => {
const at = (platform: string) => {
const steps = getSetupGuide(platform, { appName: 'Moss' })!.steps;
@@ -275,6 +295,15 @@ describe('getSetupGuide', () => {
expect(at('discord')).toEqual(['create', 'credentials', 'bot', 'intent', 'invite', 'connect']);
expect(at('telegram')).toEqual(['botfather', 'token', 'connect', 'privacy']);
expect(at('line')).toEqual(['account', 'messagingApi', 'credentials', 'connect', 'webhook']);
+ // Members can only find and use a WeCom bot once it is connected.
+ expect(at('wecom')).toEqual([
+ 'access',
+ 'create',
+ 'connection',
+ 'credentials',
+ 'connect',
+ 'usage',
+ ]);
// Stream mode connects on save, so the DingTalk console setup comes first.
expect(at('dingtalk')).toEqual(['create', 'robot', 'permissions', 'publish', 'connect']);
expect(connectStepIndex([{ key: 'only' }])).toBe(1);