Feishu / Lark IM Skill
Use this skill to run Feishu or Lark IM operations through uxc + OpenAPI.
Reuse the uxc skill for shared execution, auth, and error-handling guidance.
Prerequisites
- -
uxc is installed and available in PATH. - Network access to
https://open.feishu.cn/open-apis or https://open.larksuite.com/open-apis. - Access to the curated OpenAPI schema URL:
-
https://raw.githubusercontent.com/holon-run/uxc/main/skills/feishu-openapi-skill/references/feishu-im.openapi.json
- - A Feishu or Lark app with bot capability enabled.
- A Feishu or Lark app
app_id + app_secret, or a current tenant_access_token if you are using the manual fallback path.
Scope
This skill covers an IM-focused request/response surface:
- - chat lookup
- chat member lookup
- image and file upload for IM sends
- message send and reply
- selected message history reads
- basic user lookup through contact APIs
This skill does not cover:
- - docs, bitable, approval, or non-IM product families
- the full Feishu or Lark Open Platform surface
Subscribe Status
Feishu and Lark expose event-delivery models beyond plain request/response APIs, including long-connection event delivery in the platform ecosystem.
Current uxc subscribe status:
- - request/response IM operations are validated
- inbound message intake is validated through the built-in
feishu-long-connection transport - live validation confirmed real
im.message.receive_v1 events delivered into the subscribe sink for a p2p bot chat
Important runtime notes:
- -
feishu-long-connection is a provider-aware transport inside uxc subscribe; it is not a plain raw WebSocket stream - the runtime opens a temporary WebSocket URL from INLINECODE16
- frames are protobuf binary messages, not text JSON
- the runtime sends required event acknowledgements and ping control frames automatically
Endpoint Choice
This schema works against either Feishu or Lark Open Platform base URLs:
- - China / Feishu default: INLINECODE17
- International / Lark alternative: INLINECODE18
The fixed link example below uses Feishu. For Lark, use the same schema URL against the Lark base host.
Authentication
Feishu and Lark service-side APIs use Authorization: Bearer <tenant_access_token> for these operations.
Preferred setup is to store app_id + app_secret as credential fields and let uxc auth bootstrap fetch and refresh the short-lived tenant token automatically.
Feishu bootstrap-managed setup:
CODEBLOCK0
For Lark, use the same bootstrap shape against the Lark host and bind the credential to open.larksuite.com.
To use long-connection subscribe, the credential still needs app_id and app_secret fields because the transport opens its own temporary event URL outside the normal bearer-token request path.
Manual fallback if you already have a tenant token:
CODEBLOCK1
Lark uses the same path shape on the Lark host:
CODEBLOCK2
Configure one bearer credential and bind it to the Feishu API host:
CODEBLOCK3
For Lark, create the same binding against open.larksuite.com:
CODEBLOCK4
Inspect or pre-warm bootstrap state when auth looks wrong:
CODEBLOCK5
Validate the active binding when auth looks wrong:
CODEBLOCK6
Core Workflow
- 1. Use the fixed link command by default:
-
command -v feishu-openapi-cli
- If missing, create it:
uxc link feishu-openapi-cli https://open.feishu.cn/open-apis --schema-url https://raw.githubusercontent.com/holon-run/uxc/main/skills/feishu-openapi-skill/references/feishu-im.openapi.json
- INLINECODE29
- 2. Inspect operation schema first:
-
feishu-openapi-cli get:/im/v1/chats -h
-
feishu-openapi-cli post:/im/v1/images -h
-
feishu-openapi-cli post:/im/v1/files -h
-
feishu-openapi-cli post:/im/v1/messages -h
- INLINECODE34
- 3. Prefer read/setup validation before writes:
-
feishu-openapi-cli get:/im/v1/chats page_size=20
-
feishu-openapi-cli get:/im/v1/chats/{chat_id} chat_id=oc_xxx
- INLINECODE37
- 4. Execute with key/value or positional JSON:
- key/value:
feishu-openapi-cli get:/im/v1/messages container_id_type=chat container_id=oc_xxx page_size=20
- multipart upload:
feishu-openapi-cli post:/im/v1/images image_type=message image=/tmp/example.png
- positional JSON:
INLINECODE40
- 5. For inbound message intake, use
uxc subscribe directly:
-
uxc subscribe start https://open.feishu.cn/open-apis --transport feishu-long-connection --auth feishu-tenant --sink file:$HOME/.uxc/subscriptions/feishu.ndjson
- send a bot-visible message, then inspect the sink for INLINECODE43
Operation Groups
Chat Reads
- - INLINECODE44
- INLINECODE45
- INLINECODE46
Message Reads / Writes
- - INLINECODE47
- INLINECODE48
- INLINECODE49
- INLINECODE50
Uploads
- - INLINECODE51
- INLINECODE52
User Lookup
- - INLINECODE53
- INLINECODE54
Guardrails
- - Keep automation on the JSON output envelope; do not use
--text. - Parse stable fields first:
ok, kind, protocol, data, error. - Prefer
uxc auth bootstrap over manual token management. Manual tenant_access_token setup is still supported as a fallback. - INLINECODE63 requires the app credential fields
app_id and app_secret; a plain bearer-only credential is not enough for event intake. - INLINECODE66 and
post:/im/v1/files use multipart/form-data. File fields must be local path strings; help output marks them as multipart file fields. - INLINECODE69 requires the
receive_id_type query parameter and the body content field is a JSON-encoded string, not a nested JSON object. - Upload first, then send by returned key:
- image sends use
msg_type=image with
content='{\"image_key\":\"img_xxx\"}'
- file sends use
msg_type=file with
content='{\"file_key\":\"file_xxx\"}'
- -
post:/im/v1/messages/{message_id}/reply is for explicit replies to an existing message. Treat it as a high-risk write. - History reads only return chats and messages visible to the bot/app configuration. Auth success does not imply access to every chat.
- Long-connection message intake is validated for Feishu bot chats; webhook-style callbacks and non-IM products are still out of scope.
- INLINECODE77 is equivalent to
uxc https://open.feishu.cn/open-apis --schema-url <feishu_openapi_schema> <operation> ....
References
- - Usage patterns: INLINECODE79
- Curated OpenAPI schema: INLINECODE80
- Feishu Open Platform docs: https://open.feishu.cn/document/
- Lark Open Platform docs: https://open.larksuite.com/document/
飞书 / Lark IM 技能
使用此技能通过 uxc + OpenAPI 执行飞书或 Lark IM 操作。
复用 uxc 技能以实现共享执行、认证和错误处理指导。
前置条件
- - uxc 已安装并可在 PATH 中使用。
- 可访问 https://open.feishu.cn/open-apis 或 https://open.larksuite.com/open-apis。
- 可访问精选的 OpenAPI 模式 URL:
- https://raw.githubusercontent.com/holon-run/uxc/main/skills/feishu-openapi-skill/references/feishu-im.openapi.json
- - 一个已启用机器人功能的飞书或 Lark 应用。
- 飞书或 Lark 应用的 appid + appsecret,或者如果您使用手动回退路径,则需要当前的 tenantaccesstoken。
范围
此技能涵盖以 IM 为中心的请求/响应接口:
- - 群聊查询
- 群聊成员查询
- 用于 IM 发送的图片和文件上传
- 消息发送与回复
- 选定消息历史读取
- 通过联系人 API 进行基本用户查询
此技能不涵盖:
- - 文档、多维表格、审批或其他非 IM 产品系列
- 完整的飞书或 Lark 开放平台接口
订阅状态
飞书和 Lark 提供了超出普通请求/响应 API 的事件投递模型,包括平台生态系统中的长连接事件投递。
当前 uxc subscribe 状态:
- - 请求/响应 IM 操作已验证
- 通过内置的 feishu-long-connection 传输方式验证了入站消息接收
- 实时验证确认了真实的 im.message.receive_v1 事件已投递到 p2p 机器人聊天的订阅接收器中
重要的运行时说明:
- - feishu-long-connection 是 uxc subscribe 内部的一种感知提供者的传输方式;它不是普通的原始 WebSocket 流
- 运行时从 /callback/ws/endpoint 打开一个临时 WebSocket URL
- 帧是 protobuf 二进制消息,而非文本 JSON
- 运行时会自动发送所需的事件确认和 ping 控制帧
端点选择
此模式适用于飞书或 Lark 开放平台的基础 URL:
- - 中国/飞书默认:https://open.feishu.cn/open-apis
- 国际/Lark 替代:https://open.larksuite.com/open-apis
下面的固定链接示例使用飞书。对于 Lark,请使用相同的模式 URL 指向 Lark 基础主机。
认证
飞书和 Lark 服务端 API 对这些操作使用 Authorization: Bearer accesstoken>。
首选设置是将 appid + appsecret 存储为凭证字段,并让 uxc auth bootstrap 自动获取和刷新短期租户令牌。
飞书引导管理设置:
bash
uxc auth credential set feishu-tenant \
--auth-type bearer \
--field appid=env:FEISHUAPP_ID \
--field appsecret=env:FEISHUAPP_SECRET
uxc auth bootstrap set feishu-tenant \
--token-endpoint https://open.feishu.cn/open-apis/auth/v3/tenantaccesstoken/internal \
--header Content-Type=application/json; charset=utf-8 \
--request-json {appid:{{field:appid}},appsecret:{{field:appsecret}}} \
--access-token-pointer /tenantaccesstoken \
--expires-in-pointer /expire \
--success-code-pointer /code \
--success-code-value 0
uxc auth binding add \
--id feishu-tenant \
--host open.feishu.cn \
--path-prefix /open-apis \
--scheme https \
--credential feishu-tenant \
--priority 100
对于 Lark,请使用相同的引导形状指向 Lark 主机,并将凭证绑定到 open.larksuite.com。
要使用长连接订阅,凭证仍需要 appid 和 appsecret 字段,因为传输方式会在正常的 Bearer 令牌请求路径之外打开自己的临时事件 URL。
如果您已有租户令牌,手动回退方式:
bash
curl -sS https://open.feishu.cn/open-apis/auth/v3/tenantaccesstoken/internal \
-H Content-Type: application/json; charset=utf-8 \
-d {appid:clixxx,app_secret:xxxx}
Lark 在 Lark 主机上使用相同的路径形状:
bash
curl -sS https://open.larksuite.com/open-apis/auth/v3/tenantaccesstoken/internal \
-H Content-Type: application/json; charset=utf-8 \
-d {appid:clixxx,app_secret:xxxx}
配置一个 Bearer 凭证并将其绑定到飞书 API 主机:
bash
uxc auth credential set feishu-tenant \
--auth-type bearer \
--secret-env FEISHUTENANTACCESS_TOKEN
uxc auth binding add \
--id feishu-tenant \
--host open.feishu.cn \
--path-prefix /open-apis \
--scheme https \
--credential feishu-tenant \
--priority 100
对于 Lark,针对 open.larksuite.com 创建相同的绑定:
bash
uxc auth binding add \
--id lark-tenant \
--host open.larksuite.com \
--path-prefix /open-apis \
--scheme https \
--credential feishu-tenant \
--priority 100
当认证看起来有问题时,检查或预热引导状态:
bash
uxc auth bootstrap info feishu-tenant
uxc auth bootstrap refresh feishu-tenant
当认证看起来有问题时,验证活动绑定:
bash
uxc auth binding match https://open.feishu.cn/open-apis
核心工作流程
- 1. 默认使用固定链接命令:
- command -v feishu-openapi-cli
- 如果缺失,创建它:
uxc link feishu-openapi-cli https://open.feishu.cn/open-apis --schema-url https://raw.githubusercontent.com/holon-run/uxc/main/skills/feishu-openapi-skill/references/feishu-im.openapi.json
- feishu-openapi-cli -h
- 2. 首先检查操作模式:
- feishu-openapi-cli get:/im/v1/chats -h
- feishu-openapi-cli post:/im/v1/images -h
- feishu-openapi-cli post:/im/v1/files -h
- feishu-openapi-cli post:/im/v1/messages -h
- feishu-openapi-cli get:/im/v1/messages -h
- 3. 在写入之前优先进行读取/设置验证:
- feishu-openapi-cli get:/im/v1/chats page_size=20
- feishu-openapi-cli get:/im/v1/chats/{chat
id} chatid=oc_xxx
- feishu-openapi-cli get:/contact/v3/users/{user
id} userid=ou
xxx userid
type=openid
- 4. 使用键值对或位置 JSON 执行:
- 键值对:
feishu-openapi-cli get:/im/v1/messages container
idtype=chat container
id=ocxxx page_size=20
- 多部分上传:
feishu-openapi-cli post:/im/v1/images image_type=message image=/tmp/example.png
- 位置 JSON:
feishu-openapi-cli post:/im/v1/messages receive
idtype=chat
id {receiveid:oc
xxx,msgtype:text,content:{\text\:\Hello from UXC\}}
- 5. 对于入站消息接收,直接使用 uxc subscribe:
- uxc subscribe start https://open.feishu.cn/open-apis --transport feishu-long-connection --auth feishu-tenant --sink file:$HOME/.uxc/subscriptions/feishu.ndjson
- 发送一条机器人可见的消息,然后在接收器中检查 header.event
type = im.message.receivev1
操作组
群聊读取
- - get:/im/v1/chats
- get:/im/v1/chats/{chatid}
- get:/im/v1/chats/{chatid}/members
消息读取/写入
- - get:/im/v1/messages
- get:/im/v1/messages/{messageid}
- post:/im/v1/messages
- post:/im/v1/messages/{messageid}/reply
上传