auto-sync: lark-send-message-as-bot 2026-04-10_19:54
This commit is contained in:
commit
9fd082cb0b
122
SKILL.md
Normal file
122
SKILL.md
Normal file
@ -0,0 +1,122 @@
|
||||
---
|
||||
name: lark-send-message-as-bot
|
||||
description: |
|
||||
以 Bot 身份通过飞书发送消息。支持两种目标:
|
||||
(1) 给个人用户发私聊消息(基于 user_id)[注意] ./vala_users_list.md中已经记录了vala全员的user_id,请首先查询这个文档!
|
||||
(2) 给群组发消息(基于 chat_id)
|
||||
当 agent 需要主动推送消息、通知用户、向群组发送信息时使用。
|
||||
触发场景:发消息、通知某人、推送到群、Bot 发消息、主动消息。
|
||||
---
|
||||
|
||||
# 以 Bot 身份发送飞书消息
|
||||
|
||||
## 前置条件
|
||||
|
||||
- Bot 应用的凭证已配置在 `/root/.openclaw/credentials/<agent_name>/config.json`
|
||||
- 目标用户必须在 Bot 应用的**可用范围**内(开发者后台配置)
|
||||
- 目标群必须已将 Bot 添加为群成员
|
||||
- Bot 应用需要配置 contact:user.employee_id:readonly 权限。
|
||||
|
||||
## 发送消息
|
||||
|
||||
### 获取 tenant_access_token
|
||||
|
||||
所有发送操作前先获取 token:
|
||||
|
||||
```bash
|
||||
APP_ID=$(jq -r '.apps[0].appId' /root/.openclaw/credentials/<agent_name>/config.json)
|
||||
APP_SECRET=$(jq -r '.apps[0].appSecret' /root/.openclaw/credentials/<agent_name>/config.json)
|
||||
|
||||
TOKEN=$(curl -s -X POST "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"app_id\":\"$APP_ID\",\"app_secret\":\"$APP_SECRET\"}" \
|
||||
| jq -r '.tenant_access_token')
|
||||
```
|
||||
|
||||
token 有效期 2 小时,同一批操作复用即可。
|
||||
|
||||
### 给个人用户发消息
|
||||
[注意]首先尝试基于 ./vala_users_list.md 直接获取对应的 user_id。
|
||||
|
||||
使用 `receive_id_type=user_id`,`receive_id` 填查询到的 user_id:
|
||||
|
||||
```bash
|
||||
curl -s -X POST "https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=user_id" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"receive_id": "<user_id>",
|
||||
"msg_type": "text",
|
||||
"content": "{\"text\":\"消息内容\"}"
|
||||
}'
|
||||
```
|
||||
|
||||
### 给群组发消息
|
||||
|
||||
使用 `receive_id_type=chat_id`,`receive_id` 填群 ID:
|
||||
|
||||
```bash
|
||||
curl -s -X POST "https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=chat_id" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"receive_id": "<chat_id>",
|
||||
"msg_type": "text",
|
||||
"content": "{\"text\":\"消息内容\"}"
|
||||
}'
|
||||
```
|
||||
|
||||
## 消息类型
|
||||
|
||||
`msg_type` 和 `content` 对应关系:
|
||||
|
||||
| msg_type | content 格式 | 示例 |
|
||||
|----------|-------------|------|
|
||||
| text | `{"text":"纯文本"}` | 普通文本消息 |
|
||||
| post | `{"zh_cn":{"title":"标题","content":[[{"tag":"text","text":"正文"}]]}}` | 富文本(支持 @、链接、图片) |
|
||||
| interactive | 卡片 JSON | 消息卡片 |
|
||||
|
||||
富文本 post 支持的 tag:`text`、`a`(链接)、`at`(@用户)、`img`(图片)。
|
||||
|
||||
## ID 查询方式
|
||||
|
||||
### 查询 user_id
|
||||
[注意]首先尝试基于 ./vala_users_list.md 直接获取对应的 user_id。
|
||||
|
||||
其他情况:
|
||||
通过 Bot 所在群的成员列表获取(指定 `member_id_type=user_id`):
|
||||
|
||||
```bash
|
||||
LARKSUITE_CLI_CONFIG_DIR=/root/.openclaw/credentials/<agent_name> \
|
||||
lark-cli im chat.members get \
|
||||
--params '{"chat_id":"<群的chat_id>","member_id_type":"user_id"}' \
|
||||
--as bot
|
||||
```
|
||||
|
||||
返回结果中 `member_id` 即为 `user_id`。
|
||||
|
||||
> **注意:** 不要使用 `open_id` 跨应用发消息,`open_id` 是应用级别的,不同 Bot 看到的同一用户 open_id 不同。`user_id` 是租户级唯一标识,所有 Bot 通用。
|
||||
|
||||
### 查询 chat_id
|
||||
|
||||
列出 Bot 所在的所有群:
|
||||
|
||||
```bash
|
||||
LARKSUITE_CLI_CONFIG_DIR=/root/.openclaw/credentials/<agent_name> \
|
||||
lark-cli im chats list --params '{}' --as bot --page-all
|
||||
```
|
||||
|
||||
返回结果中每个群的 `chat_id` 和 `name` 一一对应。
|
||||
|
||||
## 常见错误
|
||||
|
||||
| 错误码 | 含义 | 解决方式 |
|
||||
|-------|------|---------|
|
||||
| 230013 | Bot has NO availability to this user | 在开发者后台将该用户加入应用的可用范围 |
|
||||
| 230001 | Bot is not in the chat | 将 Bot 添加到目标群 |
|
||||
|
||||
## 安全规则
|
||||
|
||||
- 发送前必须确认用户意图,禁止未经确认自动发送
|
||||
- 禁止在终端明文输出 `appSecret` 或 `accessToken`
|
||||
- `<agent_name>` 根据当前 agent 身份确定(如 xiaokui、xiaoxi、xiaoban 等),参考 `lark-action-as-bot` 技能的凭证目录表
|
||||
62
vala_users_list.md
Normal file
62
vala_users_list.md
Normal file
@ -0,0 +1,62 @@
|
||||
# MAKEE Interactive 全员姓名-租户user_id对照表
|
||||
总人数:57人
|
||||
|
||||
| 姓名 | 租户通用 user_id |
|
||||
|--------|---------------------|
|
||||
| 刘庆逊 | cb2815b4 |
|
||||
| 刘彦江 | 1da2afbf |
|
||||
| 胡晓阳 | 2c856846 |
|
||||
| 张钟月 | 63943ebf |
|
||||
| 黄挥伟 | 8g42f9b4 |
|
||||
| 俞欣宜 | aef91f7c |
|
||||
| 崔竞月 | gfd413g1 |
|
||||
| 李玉 | 329g7c88 |
|
||||
| 李雷 | 738edg1b |
|
||||
| 李若松 | 4aagb443 |
|
||||
| 范威 | fd47b979 |
|
||||
| 李文俊 | 4agg3b17 |
|
||||
| 杨振宇 | b4f341ca |
|
||||
| 王计 | 43872bc9 |
|
||||
| 胡陈辰 | gc64176a |
|
||||
| 吴敬兴 | f4f87c6f |
|
||||
| 庞鸿潇 | 1f5b7ef9 |
|
||||
| 毋益飞 | eggbg21g |
|
||||
| 江涛 | 3d7g1e8f |
|
||||
| 李承龙 | d8cb7f2a |
|
||||
| 梁晨 | d245ccg9 |
|
||||
| 王增礼 | 65cb43f9 |
|
||||
| 张骜 | 6e7c9b45 |
|
||||
| 魏亭亭 | cbg55d99 |
|
||||
| 张沄菥 | 张沄菥 |
|
||||
| 俞凯歌 | 42fge393 |
|
||||
| 曲慧萌 | 8c654e1e |
|
||||
| 何彬君 | d4a56ebg |
|
||||
| 李应瑛 | 58fd6864 |
|
||||
| 王虹茗 | af61e4gc |
|
||||
| 安君仪 | 5412bd9c |
|
||||
| 童瑶 | gc9f72ff |
|
||||
| 王祺 | b87ac848 |
|
||||
| 王欢 | 95g5d89f |
|
||||
| 张昆鹏 | 7f5cd711 |
|
||||
| 宋莉 | b4cdf55a |
|
||||
| 武钰涵 | 8ag94eff |
|
||||
| 孙时敏 | da6f5fcf |
|
||||
| 张路 | 742e5117 |
|
||||
| 遇庭翰 | gcb23689 |
|
||||
| 林逸瀚 | fbdc565b |
|
||||
| 王胤鑫 | 5f3bfbe9 |
|
||||
| 李丹 | ea523c46 |
|
||||
| 朱源 | 5g8c9355 |
|
||||
| 梁音 | g52gb2a3 |
|
||||
| 刘亚伟 | 5f96bf7e |
|
||||
| 王珞 | 9e4b5fa6 |
|
||||
| 刘兴冉 | 76e67fc7 |
|
||||
| 郭少甫 | adfd767f |
|
||||
| 傅硕 | ff52b224 |
|
||||
| 徐思清 | 1df37bdd |
|
||||
| Kala | a893ca1b |
|
||||
| 姜小龙 | bc227c85 |
|
||||
| 许悦 | ae8b8b7f |
|
||||
| 刘新玉 | 7gc796ga |
|
||||
| 布雪松 | a6ge7741 |
|
||||
| 章铭暄 | 222ec715 |
|
||||
Loading…
Reference in New Issue
Block a user