|
1 | | -# 接入飞书 |
| 1 | +# Connecting to Lark |
2 | 2 |
|
3 | | -## 常见问题 |
| 3 | +## Creating a Bot |
4 | 4 |
|
5 | | -如果发现 `加载平台适配器 lark 失败,原因:No module named 'lark_oapi'。请检查依赖库是否安装。提示:可以在 管理面板->控制台->安装Pip库 中安装依赖库。` 报错,说明没有安装 `lark_oapi` 库,请根据提示安装或者直接通过 pip 安装。 |
| 5 | +Navigate to the [Developer Console](https://open.feishu.cn/app) and create a custom enterprise application. |
6 | 6 |
|
7 | | -## 创建机器人 |
| 7 | + |
8 | 8 |
|
9 | | -前往 [开发者后台](https://open.feishu.cn/app) ,创建企业自建应用。 |
| 9 | +Add the Bot capability to your application. |
10 | 10 |
|
11 | | - |
| 11 | + |
12 | 12 |
|
13 | | -添加应用能力——机器人。 |
| 13 | +Click on "Credentials & Basic Info" to obtain your app_id and app_secret. |
14 | 14 |
|
15 | | - |
| 15 | + |
16 | 16 |
|
17 | | -点击凭证与基础信息,获取 app_id 和 app_secret。 |
| 17 | +## Configuring AstrBot |
18 | 18 |
|
19 | | - |
| 19 | +1. Access the AstrBot management panel |
| 20 | +2. Click on `Bots` in the left sidebar |
| 21 | +3. In the right panel, click `+ Create Bot` |
| 22 | +4. Select `lark` |
20 | 23 |
|
21 | | -## 配置 AstrBot |
| 24 | +Fill in the configuration fields as follows: |
22 | 25 |
|
23 | | -1. 进入 AstrBot 的管理面板 |
24 | | -2. 点击左边栏 `机器人` |
25 | | -3. 然后在右边的界面中,点击 `+ 创建机器人` |
26 | | -4. 选择 `lark(飞书)` |
| 26 | +- ID: Choose any identifier to distinguish between different messaging platform instances |
| 27 | +- Enable: Check this option |
| 28 | +- app_id: The app_id you obtained earlier |
| 29 | +- app_secret: The app_secret you obtained earlier |
| 30 | +- Bot name: Your Lark bot's name |
27 | 31 |
|
28 | | -弹出的配置项填写: |
| 32 | +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. |
29 | 33 |
|
30 | | -- ID(id):随意填写,用于区分不同的消息平台实例。 |
31 | | -- 启用(enable): 勾选。 |
32 | | -- app_id: 获取的 app_id |
33 | | -- app_secret: 获取的 app_secret |
34 | | -- 飞书机器人的名字 |
| 34 | +For the subscription method, `socket` uses a long connection subscription approach, while `webhook` sends events to your developer server and requires a public server. Generally, `socket` is recommended. However, if you're using Lark International or a self-hosted Lark instance, choose `webhook`. The subsequent configuration steps will differ accordingly. |
35 | 35 |
|
36 | | -如果您正在用国际版飞书,请将 `domain` 设置为 `https://open.larksuite.com`。 |
| 36 | +If you selected the `webhook` method, navigate to the Lark Developer Console, click on "Events & Callbacks," then "Encryption Policy," and fill in the Encrypt Key. While not mandatory, AstrBot takes your data security seriously, so we strongly recommend setting this up. After filling it in, copy the `Encrypt Key` and `Verification Token` to the corresponding `encrypt_key` and `verification_token` fields in AstrBot's configuration. |
37 | 37 |
|
38 | | -点击 `保存`。 |
| 38 | +Click `Save`. |
39 | 39 |
|
40 | | -## 设置回调和权限 |
| 40 | +## Setting up Callbacks and Permissions |
41 | 41 |
|
42 | | -接下来,点击事件与回调,使用长连接接收事件,点击保存。**如果上一步没有成功启动,那么这里将无法保存。** |
| 42 | +The following steps vary depending on the subscription method you selected above. Please proceed to the corresponding section based on your choice. |
43 | 43 |
|
44 | | - |
| 44 | +### `socket` Long Connection Method |
45 | 45 |
|
46 | | -点击添加事件,消息与群组,下拉找到 `接收消息`,添加。 |
| 46 | +Next, click on "Events & Callbacks," select "Receive events using long connection," and click Save. **If the previous step didn't start successfully, you won't be able to save here.** |
47 | 47 |
|
48 | | - |
| 48 | + |
49 | 49 |
|
50 | | -点击开通以下权限。 |
| 50 | +### `webhook` Send Events to Developer Server Method |
51 | 51 |
|
52 | | - |
| 52 | +> [!TIP] |
| 53 | +> To make better use of this method, please refer to [Unified Webhook Mode](/zh/use/unified-webhook.md#如何使用统一-webhook-模式) for the necessary configuration. |
53 | 54 |
|
54 | | -再点击上面的`保存`按钮。 |
| 55 | +After clicking `Save`, the bot card will display "View Webhook URL." Click to view and copy the callback URL. |
55 | 56 |
|
56 | | -接下来,点击权限管理,点击开通权限,输入 `im:message:send,im:message,im:message:send_as_bot`。添加筛选到的权限。 |
| 57 | + |
57 | 58 |
|
58 | | -再次输入 `im:resource:upload,im:resource` 开通上传图片相关的权限。 |
| 59 | +Next, return to Lark's Events & Callbacks page, click "Event Configuration," select "Send events to developer server," enter the callback URL you just copied as the "Request URL," and click Save. If everything is correct, no errors will appear. |
59 | 60 |
|
60 | | -最终开通的权限如下图: |
| 61 | +### Setting up Events |
61 | 62 |
|
62 | | - |
| 63 | +After completing the event configuration in the previous step, click "Add Event," navigate to "Messages & Groups," scroll down to find `Receive Message`, and add it. |
63 | 64 |
|
64 | | -## 创建版本 |
| 65 | + |
65 | 66 |
|
66 | | -创建版本。 |
| 67 | +Click to enable the following permissions. |
67 | 68 |
|
68 | | - |
| 69 | + |
69 | 70 |
|
70 | | -填写版本号,更新说明,可见范围后点击保存,确认发布。 |
| 71 | +Then click the `Save` button at the top. |
71 | 72 |
|
72 | | -## 拉入机器人到群组 |
| 73 | +Next, click on "Permission Management," click "Enable Permissions," and enter `im:message:send,im:message,im:message:send_as_bot`. Add the filtered permissions. |
73 | 74 |
|
74 | | -进入飞书 APP(网页版飞书无法添加机器人),点进群聊,点击右上角按钮->群机器人->添加机器人。 |
| 75 | +Enter `im:resource:upload,im:resource` again to enable image upload permissions. |
75 | 76 |
|
76 | | -搜索刚刚创建的机器人的名字。比如教程创建了 `AstrBot` 机器人: |
| 77 | +The final set of permissions should look like this: |
77 | 78 |
|
78 | | - |
| 79 | + |
79 | 80 |
|
80 | | -## 🎉 大功告成 |
| 81 | +## Creating a Version |
81 | 82 |
|
82 | | -在群内发送一个 `/help` 指令,机器人将做出响应。 |
| 83 | +Create a new version. |
83 | 84 |
|
84 | | - |
| 85 | + |
| 86 | + |
| 87 | +Fill in the version number, update notes, and visibility scope, then click Save and confirm the release. |
| 88 | + |
| 89 | +## Adding the Bot to a Group |
| 90 | + |
| 91 | +Open the Lark app (the web version doesn't support adding bots), enter a group chat, click the button in the upper right corner → Group Bots → Add Bot. |
| 92 | + |
| 93 | +Search for the bot you just created. For example, if you created the `AstrBot` bot as shown in this tutorial: |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | +## 🎉 All Done! |
| 98 | + |
| 99 | +Send a `/help` command in the group, and the bot will respond. |
| 100 | + |
| 101 | + |
0 commit comments