send-feishu

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Send Feishu Message

发送飞书消息

Send messages, images, and files to Feishu groups or individuals.
向飞书群组或个人发送消息、图片和文件。

Environment Variables

环境变量

VariablePurposeRequired
FEISHU_WEBHOOK
Group Webhook URLFor text/card/image to group
FEISHU_APP_ID
App credentialFor image/file upload & API send
FEISHU_APP_SECRET
App credentialFor image/file upload & API send
FEISHU_CHAT_ID
Group chat ID (
oc_xxx
)
For API send to group
FEISHU_USER_OPEN_ID
Personal open_id (
ou_xxx
)
For send to individual
变量名用途是否必填
FEISHU_WEBHOOK
群组Webhook地址向群组发送文本/卡片/图片时需要
FEISHU_APP_ID
应用凭证上传图片/文件及通过API发送消息时需要
FEISHU_APP_SECRET
应用凭证上传图片/文件及通过API发送消息时需要
FEISHU_CHAT_ID
群聊ID(格式为
oc_xxx
通过API向群组发送消息时需要
FEISHU_USER_OPEN_ID
个人open_id(格式为
ou_xxx
向个人发送消息时需要

Decision Logic

决策逻辑

Choose the sending method based on content type and target:
Text/Card to group     → Webhook (simple, no auth needed)
Image to group         → Get token → Upload image → Webhook send image_key
File to group          → Get token → Upload file → API send to chat_id
Image/File to person   → Get token → Upload resource → API send to open_id
Text/Card to person    → Get token → API send to open_id
根据内容类型和接收对象选择发送方式:
文本/卡片到群组 → Webhook(简单,无需认证)
图片到群组 → 获取令牌 → 上传图片 → 通过Webhook发送image_key
文件到群组 → 获取令牌 → 上传文件 → 通过API发送到chat_id
图片/文件到个人 → 获取令牌 → 上传资源 → 通过API发送到open_id
文本/卡片到个人 → 获取令牌 → 通过API发送到open_id

Choosing Format

格式选择

Use text — simple one-liner (status update, quick note).
Use card — content has title + body, structured data, summary, or report.
Use image — user explicitly asks to send an image file, screenshot, or chart.
Use file — user asks to send .md/.pdf/.doc/.xls etc., or content is too long for card display.
Send to individual — user says "发给我", "私发", "发到我的飞书", or specifies a person.
使用文本格式 —— 适用于简单的单行内容(状态更新、快速备注)。
使用卡片格式 —— 内容包含标题+正文、结构化数据、摘要或报告时使用。
使用图片格式 —— 用户明确要求发送图片文件、截图或图表时使用。
使用文件格式 —— 用户要求发送.md/.pdf/.doc/.xls等格式文件,或内容过长不适合卡片展示时使用。
发送给个人 —— 用户说出「发给我」「私发」「发到我的飞书」,或指定某个人时使用。

Step A: Get tenant_access_token

步骤A:获取tenant_access_token

Required for image upload, file upload, and API message sending. Skip this step if only sending text/card via Webhook.
bash
curl -s -X POST 'https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal' \
  -H 'Content-Type: application/json' \
  -d '{"app_id":"'"$FEISHU_APP_ID"'","app_secret":"'"$FEISHU_APP_SECRET"'"}'
Response:
{"code":0,"msg":"ok","tenant_access_token":"t-xxx","expire":7200}
Extract the token and store in a variable for subsequent steps.
上传图片、文件及通过API发送消息时需要此令牌。如果仅通过Webhook发送文本/卡片,可跳过此步骤。
bash
curl -s -X POST 'https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal' \
  -H 'Content-Type: application/json' \
  -d '{"app_id":"'"$FEISHU_APP_ID"'","app_secret":"'"$FEISHU_APP_SECRET"'"}'
响应示例:
{"code":0,"msg":"ok","tenant_access_token":"t-xxx","expire":7200}
提取令牌并存储到变量中,供后续步骤使用。

Step B: Upload Image (get image_key)

步骤B:上传图片(获取image_key)

Required when sending an image. Supports JPEG/PNG/WEBP/GIF/TIFF/BMP/ICO, max 10MB.
bash
curl -s -X POST 'https://open.feishu.cn/open-apis/im/v1/images' \
  -H "Authorization: Bearer $TOKEN" \
  -F 'image_type="message"' \
  -F 'image=@"/path/to/image.png"'
Response:
{"code":0,"data":{"image_key":"img_xxx"}}
发送图片时需要执行此步骤。支持JPEG/PNG/WEBP/GIF/TIFF/BMP/ICO格式,最大10MB。
bash
curl -s -X POST 'https://open.feishu.cn/open-apis/im/v1/images' \
  -H "Authorization: Bearer $TOKEN" \
  -F 'image_type="message"' \
  -F 'image=@"/path/to/image.png"'
响应示例:
{"code":0,"data":{"image_key":"img_xxx"}}

Step C: Upload File (get file_key)

步骤C:上传文件(获取file_key)

Required when sending a file. Max 30MB.
bash
curl -s -X POST 'https://open.feishu.cn/open-apis/im/v1/files' \
  -H "Authorization: Bearer $TOKEN" \
  -F 'file_type="stream"' \
  -F 'file_name="report.md"' \
  -F 'file=@"/path/to/file"'
file_type
values:
opus
(audio),
mp4
(video),
pdf
,
doc
,
xls
,
ppt
,
stream
(binary, use as default).
Response:
{"code":0,"data":{"file_key":"file_xxx"}}
发送文件时需要执行此步骤。最大支持30MB。
bash
curl -s -X POST 'https://open.feishu.cn/open-apis/im/v1/files' \
  -H "Authorization: Bearer $TOKEN" \
  -F 'file_type="stream"' \
  -F 'file_name="report.md"' \
  -F 'file=@"/path/to/file"'
file_type
可选值:
opus
(音频)、
mp4
(视频)、
pdf
doc
xls
ppt
stream
(二进制文件,默认值)。
响应示例:
{"code":0,"data":{"file_key":"file_xxx"}}

Sending via Webhook

通过Webhook发送

Send Text

发送文本

bash
curl -s -X POST "$FEISHU_WEBHOOK" -H "Content-Type: application/json" \
  -d '{"msg_type":"text","content":{"text":"MESSAGE_HERE"}}'
bash
curl -s -X POST "$FEISHU_WEBHOOK" -H "Content-Type: application/json" \
  -d '{"msg_type":"text","content":{"text":"MESSAGE_HERE"}}'

Send Card

发送卡片

Pick header color by sentiment:
  • green
    — success, complete, done
  • orange
    — warning, attention
  • red
    — error, failure
  • blue
    — info, neutral (default)
  • purple
    — highlight, special
bash
curl -s -X POST "$FEISHU_WEBHOOK" -H "Content-Type: application/json" \
  -d '{
    "msg_type":"interactive",
    "card":{
      "header":{"title":{"content":"TITLE","tag":"plain_text"},"template":"COLOR"},
      "elements":[{"tag":"div","text":{"content":"BODY_LARK_MD","tag":"lark_md"}}]
    }
  }'
Card body supports lark_md:
**bold**
,
*italic*
,
~~strike~~
,
[link](url)
,
\n
for newlines.
根据内容情感选择头部颜色:
  • green
    —— 成功、完成、已办结
  • orange
    —— 警告、注意
  • red
    —— 错误、失败
  • blue
    —— 信息、中性(默认)
  • purple
    —— 高亮、特殊
bash
curl -s -X POST "$FEISHU_WEBHOOK" -H "Content-Type: application/json" \
  -d '{
    "msg_type":"interactive",
    "card":{
      "header":{"title":{"content":"TITLE","tag":"plain_text"},"template":"COLOR"},
      "elements":[{"tag":"div","text":{"content":"BODY_LARK_MD","tag":"lark_md"}}]
    }
  }'
卡片正文支持lark_md格式:
**加粗**
*斜体*
~~删除线~~
[链接](url)
\n
换行。

Send Image via Webhook

通过Webhook发送图片

After uploading image (Step B) to get
image_key
:
bash
curl -s -X POST "$FEISHU_WEBHOOK" \
  -H "Content-Type: application/json" \
  -d '{"msg_type":"image","content":{"image_key":"img_xxx"}}'
完成步骤B上传图片并获取
image_key
后执行:
bash
curl -s -X POST "$FEISHU_WEBHOOK" \
  -H "Content-Type: application/json" \
  -d '{"msg_type":"image","content":{"image_key":"img_xxx"}}'

Sending via API

通过API发送

Use API when sending files, or sending any content to an individual.
发送文件或向个人发送任何内容时使用API方式。

Send to Group (chat_id)

发送到群组(chat_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; charset=utf-8" \
  -d '{"receive_id":"'"$FEISHU_CHAT_ID"'","msg_type":"MSG_TYPE","content":"CONTENT_JSON_STRING"}'
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; charset=utf-8" \
  -d '{"receive_id":"'"$FEISHU_CHAT_ID"'","msg_type":"MSG_TYPE","content":"CONTENT_JSON_STRING"}'

Send to Individual (open_id)

发送到个人(open_id)

bash
curl -s -X POST "https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=open_id" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json; charset=utf-8" \
  -d '{"receive_id":"'"$FEISHU_USER_OPEN_ID"'","msg_type":"MSG_TYPE","content":"CONTENT_JSON_STRING"}'
bash
curl -s -X POST "https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=open_id" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json; charset=utf-8" \
  -d '{"receive_id":"'"$FEISHU_USER_OPEN_ID"'","msg_type":"MSG_TYPE","content":"CONTENT_JSON_STRING"}'

API Content Formats

API内容格式

The
content
field must be a JSON-encoded string (escaped JSON inside JSON).
Text:
json
{"receive_id":"ID","msg_type":"text","content":"{\"text\":\"Hello\"}"}
Image (after upload):
json
{"receive_id":"ID","msg_type":"image","content":"{\"image_key\":\"img_xxx\"}"}
File (after upload):
json
{"receive_id":"ID","msg_type":"file","content":"{\"file_key\":\"file_xxx\"}"}
content
字段必须是JSON编码字符串(JSON内部嵌套转义后的JSON)。
文本格式示例:
json
{"receive_id":"ID","msg_type":"text","content":"{\"text\":\"Hello\"}"}
图片格式示例(上传后):
json
{"receive_id":"ID","msg_type":"image","content":"{\"image_key\":\"img_xxx\"}"}
文件格式示例(上传后):
json
{"receive_id":"ID","msg_type":"file","content":"{\"file_key\":\"file_xxx\"}"}

After Sending

发送后检查

Check the response JSON:
  • Webhook:
    {"code":0,"msg":"success"}
    → success
  • API:
    {"code":0,"msg":"success","data":{...}}
    → success
  • code
    != 0 → report the error:
    • 19001: webhook URL invalid
    • 19021: signature check failed
    • 19022: IP not whitelisted
    • 19024: keyword check failed
    • 99991663: token invalid or expired (re-run Step A)
    • 230001: bot not in chat or no permission
检查响应JSON:
  • Webhook:
    {"code":0,"msg":"success"}
    → 发送成功
  • API:
    {"code":0,"msg":"success","data":{...}}
    → 发送成功
  • code
    不等于0 → 报告错误:
    • 19001:webhook地址无效
    • 19021:签名验证失败
    • 19022:IP不在白名单内
    • 19024:关键词验证失败
    • 99991663:令牌无效或过期(重新执行步骤A)
    • 230001:机器人不在群聊中或无权限

Important

重要提示

  • Always escape special characters in JSON (quotes, backslashes, newlines)
  • Use
    printf '%s'
    or heredoc to safely pass message content to curl if it contains special characters
  • If required env vars are not set, tell user which ones to configure
  • Keep messages concise — Feishu cards have display limits
  • Token from Step A is valid for 2 hours; no need to refresh within a session
  • App permissions required:
    im:message:send_as_bot
    (send messages),
    im:resource
    (upload images and files)
  • 务必转义JSON中的特殊字符(引号、反斜杠、换行符)
  • 如果消息内容包含特殊字符,使用
    printf '%s'
    或heredoc安全地将内容传递给curl
  • 如果所需环境变量未设置,告知用户需要配置哪些变量
  • 保持消息简洁——飞书卡片有展示限制
  • 步骤A获取的令牌有效期为2小时;同一会话内无需刷新
  • 所需应用权限
    im:message:send_as_bot
    (发送消息)、
    im:resource
    (上传图片和文件)