feat(lark): implement app registration and bot info retrieval

- Add app registration functionality for Lark and Feishu platforms, including endpoints and request handling.
- Introduce polling mechanism for app registration status.
- Create bot info retrieval functionality to fetch bot details after successful registration.
- Enhance dashboard with new UI components for one-click QR setup and manual setup options.
- Update internationalization files to support new features and actions.
- Add unit tests for app registration endpoint resolution and data handling.
This commit is contained in:
Soulter
2026-05-14 22:43:03 +08:00
parent 094c2de85a
commit 8dde2292fb
20 changed files with 1049 additions and 52 deletions

View File

@@ -20,6 +20,31 @@ The Lark client version must be >= 7.20. Lower versions only display the title a
## Creating a Bot
Lark supports two setup methods: one-click QR creation in AstrBot, or manually creating a custom enterprise app in the Lark Developer Console.
### Option 1: One-click QR Creation
AstrBot version requirement: >= 4.25.0.
Open the AstrBot management panel, click `Bots` in the left sidebar, click `+ Create Bot`, and select `lark`.
Under `Creation Method`, select `One-click QR Creation`, choose the China or international edition as needed, then scan the QR code with the Lark mobile app and confirm. After creation succeeds, AstrBot automatically fills in the app's `app_id`, `app_secret`, and domain configuration.
> [!IMPORTANT]
> After an app is created through QR scanning, group chats receive only messages that @ mention the bot or messages triggered by a wake prefix such as `/` by default. If you need the bot to receive all group messages, enable the additional permissions in the Lark Developer Console.
>
> Replace `<APP_ID>` in the URL below with your Lark app ID, then open it to jump to the permission enablement page:
>
> To find the App ID, go back to AstrBot's `Bots` page, find the Lark bot you just created, click `Edit`, and check the dialog that opens.
>
> ```text
> https://open.feishu.cn/app/<APP_ID>/auth?q=contact:contact.base:readonly,im:message.p2p_msg:readonly,im:message.group_at_msg:readonly,im:message:send,im:message,im:message:send_as_bot,im:resource:upload,im:resource,cardkit:card:write,im:message.group_at_msg:readonly,im:message.group_msg&op_from=openapi&token_type=tenant
> ```
After QR creation succeeds, continue checking the event subscription, permissions, version release, and group installation steps below.
### Option 2: Manual Creation
Navigate to the [Developer Console](https://open.feishu.cn/app) and create a custom enterprise application.
![Create Custom Enterprise Application](https://files.astrbot.app/docs/source/images/lark/image.png)
@@ -38,6 +63,7 @@ Click on "Credentials & Basic Info" to obtain your app_id and app_secret.
2. Click on `Bots` in the left sidebar
3. In the right panel, click `+ Create Bot`
4. Select `lark`
5. If you want AstrBot to create the app for you, select `One-click QR Creation` and complete the scan. If you already created the app yourself, select `Manual Creation`
Fill in the configuration fields as follows:
@@ -45,7 +71,6 @@ Fill in the configuration fields as follows:
- Enable: Check this option
- app_id: The app_id you obtained earlier
- app_secret: The app_secret you obtained earlier
- Bot name: Your Lark bot's name
For the domain field, if you're using Lark China, keep the default value. If you're using Lark International, set it to `https://open.larksuite.com`. If you're using a self-hosted enterprise Lark instance, enter your Lark instance's domain.
@@ -92,6 +117,11 @@ Next, click on "Permission Management," click "Enable Permissions," and enter `i
Enter `im:resource:upload,im:resource` again to enable image upload permissions.
If you want to use the bot in group chats, additionally enable `im:message.group_at_msg:readonly` and `im:message.group_msg`.
> [!TIP]
> Apps created through one-click QR creation are suitable for @ mentions and wake-prefix triggers by default. To receive every group message, make sure `im:message.group_msg` is enabled. You can also use the permission URL above to quickly open the corresponding page.
If you want to use streaming output, additionally enable `Create and update cards (cardkit:card:write)`.
The final set of permissions should look like this:

View File

@@ -20,6 +20,31 @@
## 创建机器人
飞书Lark支持两种创建方式在 AstrBot 中扫码一键创建,或在飞书开发者后台手动创建企业自建应用。
### 方式一:扫码一键创建
需要版本 >4.25.0。
进入 AstrBot 管理面板,点击左边栏 `机器人`,然后点击 `+ 创建机器人`,选择 `lark(飞书)`
`选择创建方式` 中选择 `扫码一键创建`按需选择国内版或海外版然后使用手机飞书扫描页面中的二维码并确认。创建成功后AstrBot 会自动写入该应用的 `app_id``app_secret` 和域名配置。
> [!IMPORTANT]
> 通过扫码方式创建后,群聊下默认仅会接收 @ 机器人和通过唤醒前缀(例如 `/`)触发的消息。如果你希望机器人接收群聊中的所有消息,需要前往飞书开发者后台为应用开通额外权限。
>
> 可以将下面链接中的 `<APP_ID>` 替换为你的飞书应用 App ID 后打开,一键进入权限开通页:
>
> App ID 获取方式:回到 AstrBot 的 `机器人` 页,找到刚刚创建的飞书机器人,点击 `编辑`,弹出的对话框中可以看到 App ID。
>
> ```text
> https://open.feishu.cn/app/<APP_ID>/auth?q=contact:contact.base:readonly,im:message.p2p_msg:readonly,im:message.group_at_msg:readonly,im:message:send,im:message,im:message:send_as_bot,im:resource:upload,im:resource,cardkit:card:write,im:message.group_at_msg:readonly,im:message.group_msg&op_from=openapi&token_type=tenant
> ```
扫码创建完成后,建议继续检查后文的事件订阅、权限、版本发布和拉入群组步骤。
### 方式二:手动创建
前往 [开发者后台](https://open.feishu.cn/app) ,创建企业自建应用。
![创建企业自建应用](https://files.astrbot.app/docs/source/images/lark/image.png)
@@ -38,6 +63,7 @@
2. 点击左边栏 `机器人`
3. 然后在右边的界面中,点击 `+ 创建机器人`
4. 选择 `lark(飞书)`
5. 如果使用扫码一键创建,选择 `扫码一键创建` 并完成扫码;如果使用自己创建的企业自建应用,选择 `手动创建`
弹出的配置项填写:
@@ -45,7 +71,6 @@
- 启用(enable): 勾选。
- app_id: 获取的 app_id
- app_secret: 获取的 app_secret
- 飞书机器人的名字
对于 domain如果您使用国内版飞书保持默认即可如果您正在用国际版飞书请设置为 `https://open.larksuite.com`;如果您使用企业自部署飞书,请填写您的飞书实例的域名。
@@ -94,6 +119,9 @@
如果需要在群聊里使用,请额外开通 `im:message.group_at_msg:readonly``im:message.group_msg` 权限。
> [!TIP]
> 扫码一键创建的应用默认适合 @ 机器人和唤醒前缀触发。如果要接收群聊所有消息,请确认已经开通 `im:message.group_msg`。你也可以使用上文提供的权限开通链接快速进入对应页面。
如果需要使用流式输出,请额外开通 `创建与更新卡片(cardkit:card:write)` 权限。
最终开通的权限如下图: