OpenCLI Online

飞书

飞书 CLI

飞书开放平台机器人、多维表格与审批流的命令行管理与调试。

官方与参考链接

类型链接
飞书开放平台https://open.feishu.cn/
开放接口 / 文档中心https://open.feishu.cn/document/
开发者后台(应用与凭证)https://open.feishu.cn/app/

下文 opencli feishu 全量子命令均列出于「命令参考(全量)」;飞书 HTTP API 细节仍以官方文档为准,但日常只用本站即可知道该 CLI 面所有入口。

概述

飞书 CLI(opencli feishu)封装飞书开放平台常见操作:应用凭证管理、长连接调试、表格记录导入导出等。文档假设你已在飞书开放平台创建企业自建应用。

前置要求

工具 / 信息说明
应用 App ID / App Secret开放平台「凭证与基础信息」
机器人能力需在权限管理中开通消息、通讯录等所需 scope
Node.js 20+与全局 opencli 一致
curl用于手动校验租户网关(可选)

安装 CLI 与飞书子命令

全局安装主程序后,飞书模块随主包提供,无需单独安装:

npm install -g @opencli/cli@latest
opencli feishu --help

若企业使用内网镜像:

npm install -g @opencli/cli@latest --registry=https://your-registry.example.com

配置应用凭证

请勿将 Secret 提交到 Git。 推荐使用环境变量或本地加密配置。

方式一:环境变量(CI / 本地 shell)

export FEISHU_APP_ID=cli_xxxxxxxx
export FEISHU_APP_SECRET=xxxxxxxxxxxxxxxx
  • FEISHU_APP_ID:应用 ID,以 cli_ 开头。
  • FEISHU_APP_SECRET:应用密钥,仅服务器端使用。

方式二:写入 OpenCLI 本地配置

opencli feishu config init --app-id cli_xxxxxxxx
opencli feishu config set app_secret --from-env FEISHU_APP_SECRET
  • config init:创建 ~/.opencli/feishu.json 骨架并写入 app_id。
  • config set app_secret --from-env:从环境变量读取密钥写入本地加密存储,避免出现在 shell 历史中。

获取 tenant_access_token

多数业务 API 需要租户令牌:

opencli feishu auth tenant-token --print
说明
子命令 tenant-token使用 app_id + app_secret 换取 tenant_access_token
--print将令牌打印到 stdout,便于管道传给 curl(调试完请清屏)

默认令牌会缓存至 ~/.opencli/feishu/cache.json,过期前自动刷新。


命令参考(全量)

opencli feishu --help

鉴权 auth

命令说明
opencli feishu auth tenant-token [--print] [--no-cache]换取并缓存 tenant_access_token;--print 打印到 stdout
opencli feishu auth app-token [--print]若使用应用级 token 场景(依企业配置)
opencli feishu auth tenant-token --print

应用 app

命令说明
opencli feishu app info打印 App ID、名称、可用状态
opencli feishu app scopes列出当前应用已开通权限点
opencli feishu app scopes

配置 config

命令说明
opencli feishu config init --app-id <id>初始化本地配置骨架
opencli feishu config set <key> --value <v>写入键值
opencli feishu config set <key> --from-env <ENV>从环境变量读入(如 Secret)
opencli feishu config get <key>读取
opencli feishu config path打印配置文件路径
opencli feishu config init --app-id cli_xxxxxxxx
opencli feishu config set app_secret --from-env FEISHU_APP_SECRET
opencli feishu config path

消息 message

命令说明
opencli feishu message send --receive-id-type <chat_id/open_id/user_id> --receive-id <id> --text <text>发送文本;接收方类型三选一
opencli feishu message send --receive-id-type chat_id --receive-id oc_xxxx --text "OpenCLI 连通性测试"

多维表格 bitable

命令说明
opencli feishu bitable export --app-token <t> --table-id <tbl> --out <file>导出为 CSV
opencli feishu bitable records list --app-token <t> --table-id <tbl> [--page-size N] [--page-token <t>]分页列记录
opencli feishu bitable export --app-token BaseAppToken --table-id tblXXXX --out ./export.csv

云文档 / 上传 drive

命令说明
opencli feishu drive file upload --path <local> [--name <显示名>]上传素材文件,返回 file_key

通用 HTTP http(排障)

命令说明
opencli feishu http get <open-api-path> [--query k=v ...]带鉴权 GET
opencli feishu http post <open-api-path> --body '<json>'带鉴权 POST JSON

事件回调 events

命令说明
opencli feishu events verify --url <公网回调 URL>校验挑战 URL 配置(依实现)

调试建议

  1. 在开放平台「事件与回调」中配置请求地址后,用 opencli feishu events tunnel(若版本提供)做本地反向代理调试。
  2. 出现 99991663 等错误码时,对照飞书错误码文档逐项核对权限与 IP 白名单。