npx skills add https://github.com/jssfy/k-skills --skill send-feishu向飞书群组或个人发送消息、图片和文件。
| 变量 | 用途 | 必填 |
|---|---|---|
FEISHU_WEBHOOK | 群组 Webhook URL | 用于向群组发送文本/卡片/图片 |
FEISHU_APP_ID | 应用凭证 | 用于图片/文件上传及 API 发送 |
FEISHU_APP_SECRET | 应用凭证 | 用于图片/文件上传及 API 发送 |
FEISHU_CHAT_ID | 群聊 ID (oc_xxx) |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 用于通过 API 向群组发送 |
FEISHU_USER_OPEN_ID | 个人 open_id (ou_xxx) | 用于向个人发送 |
FEISHU_WEBHOOK_SECRET | Webhook 签名密钥 | 仅当群组 Webhook 启用了签名时需配置 |
根据内容类型和目标选择发送方式:
文本/卡片到群组 → Webhook (简单,无需认证)
图片到群组 → 获取 token → 上传图片 → Webhook 发送 image_key
文件到群组 → 获取 token → 上传文件 → API 发送到 chat_id
图片/文件到个人 → 获取 token → 上传资源 → API 发送到 open_id
文本/卡片到个人 → 获取 token → API 发送到 open_id
使用文本 — 简单的单行内容(状态更新、快速备注)。
使用卡片 — 内容包含标题 + 正文、结构化数据、摘要或报告。
使用图片 — 用户明确要求发送图片文件、截图或图表。
使用文件 — 用户要求发送 .html/.md/.pdf/.doc/.xls 等文件,或内容过长不适合卡片显示。
发送给个人 — 用户说“发给我”、“私发”、“发到我的飞书”,或指定了某个人。
用于图片上传、文件上传和 API 消息发送。如果仅通过 Webhook 发送文本/卡片,可跳过此步骤。
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}
提取 token 并存储在变量中,供后续步骤使用。
发送图片时需要。支持 JPEG/PNG/WEBP/GIF/TIFF/BMP/ICO,最大 10MB。
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"}}
发送文件时需要。最大 30MB。
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"}}
如果 Webhook 启用了签名验证,则首先生成 timestamp 和 sign,然后将它们包含在 Webhook 负载中。如果未配置密钥,请使用下方未签名的示例。
python3 - <<'PY'
import base64
import hashlib
import hmac
import json
import os
import time
secret = os.environ["FEISHU_WEBHOOK_SECRET"]
timestamp = str(int(time.time()))
string_to_sign = f"{timestamp}\n{secret}".encode("utf-8")
sign = base64.b64encode(hmac.new(string_to_sign, b"", digestmod=hashlib.sha256).digest()).decode("utf-8")
payload = {
"timestamp": timestamp,
"sign": sign,
"msg_type": "text",
"content": {"text": "MESSAGE_HERE"},
}
print(json.dumps(payload, ensure_ascii=False))
PY
将输出的 JSON 作为 curl -d 请求体发送到 $FEISHU_WEBHOOK。卡片、图片消息同理,只需替换 msg_type 和 content。
curl -s -X POST "$FEISHU_WEBHOOK" -H "Content-Type: application/json" \
-d '{"msg_type":"text","content":{"text":"MESSAGE_HERE"}}'
根据情感选择标题颜色:
green — 成功、完成、已结束orange — 警告、注意red — 错误、失败blue — 信息、中性(默认)purple — 高亮、特殊简短内容(无特殊字符):
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"}}]
}
}'
长内容或包含特殊字符($、"、\n 等)的内容 — 始终使用此模式:
python3 - << 'EOF' | curl -s -X POST "$FEISHU_WEBHOOK" \
-H "Content-Type: application/json" -d @-
import json
card = {
"msg_type": "interactive",
"card": {
"header": {"title": {"content": "TITLE", "tag": "plain_text"}, "template": "COLOR"},
"elements": [
{"tag": "div", "text": {"content": "BODY LINE 1\nBODY LINE 2", "tag": "lark_md"}},
{"tag": "hr"},
{"tag": "div", "text": {"content": "SECTION 2 CONTENT", "tag": "lark_md"}}
]
}
}
print(json.dumps(card))
EOF
卡片正文支持 lark_md 语法:**粗体**、*斜体*、~~删除线~~、[链接](url)、\n 换行。
上传图片(步骤 B)获取 image_key 后:
curl -s -X POST "$FEISHU_WEBHOOK" \
-H "Content-Type: application/json" \
-d '{"msg_type":"image","content":{"image_key":"img_xxx"}}'
发送文件,或向个人发送任何内容时,使用 API。
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"}'
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"}'
content 字段必须是 JSON 编码的字符串(JSON 内部嵌套转义后的 JSON)。
文本:
{"receive_id":"ID","msg_type":"text","content":"{\"text\":\"Hello\"}"}
图片(上传后):
{"receive_id":"ID","msg_type":"image","content":"{\"image_key\":\"img_xxx\"}"}
文件(上传后):
{"receive_id":"ID","msg_type":"file","content":"{\"file_key\":\"file_xxx\"}"}
检查响应 JSON:
{"code":0,"msg":"success"} → 成功{"code":0,"msg":"success","data":{...}} → 成功code != 0 → 报告错误:
printf '%s' 或 heredoc 安全地传递给 curlFEISHU_WEBHOOK_SECRET 并包含 timestamp + signim:message:send_as_bot (发送消息), im:resource (上传图片和文件)每周安装量
279
仓库
GitHub Stars
2
首次出现
2026年2月22日
安全审计
安装于
codex276
gemini-cli275
opencode275
cursor275
amp274
github-copilot274
Send messages, images, and files to Feishu groups or individuals.
| Variable | Purpose | Required |
|---|---|---|
FEISHU_WEBHOOK | Group Webhook URL | For text/card/image to group |
FEISHU_APP_ID | App credential | For image/file upload & API send |
FEISHU_APP_SECRET | App credential | For 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_SECRET | Webhook signing secret | Only when group webhook has signature enabled |
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
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 .html/.md/.pdf/.doc/.xls etc., or content is too long for card display.
Send to individual — user says "发给我", "私发", "发到我的飞书", or specifies a person.
Required for image upload, file upload, and API message sending. Skip this step if only sending text/card via Webhook.
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.
Required when sending an image. Supports JPEG/PNG/WEBP/GIF/TIFF/BMP/ICO, max 10MB.
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"}}
Required when sending a file. Max 30MB.
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"}}
If the webhook has signature verification enabled , generate timestamp and sign first, then include them in the webhook payload. If no secret is configured, use the unsigned examples below.
python3 - <<'PY'
import base64
import hashlib
import hmac
import json
import os
import time
secret = os.environ["FEISHU_WEBHOOK_SECRET"]
timestamp = str(int(time.time()))
string_to_sign = f"{timestamp}\n{secret}".encode("utf-8")
sign = base64.b64encode(hmac.new(string_to_sign, b"", digestmod=hashlib.sha256).digest()).decode("utf-8")
payload = {
"timestamp": timestamp,
"sign": sign,
"msg_type": "text",
"content": {"text": "MESSAGE_HERE"},
}
print(json.dumps(payload, ensure_ascii=False))
PY
将输出的 JSON 作为 curl -d 请求体发送到 $FEISHU_WEBHOOK。卡片、图片消息同理,只需替换 msg_type 和 content。
curl -s -X POST "$FEISHU_WEBHOOK" -H "Content-Type: application/json" \
-d '{"msg_type":"text","content":{"text":"MESSAGE_HERE"}}'
Pick header color by sentiment:
green — success, complete, doneorange — warning, attentionred — error, failureblue — info, neutral (default)purple — highlight, specialShort content (no special characters):
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"}}]
}
}'
Long content or content with special characters ($, ", \n, etc.) — always use this pattern:
python3 - << 'EOF' | curl -s -X POST "$FEISHU_WEBHOOK" \
-H "Content-Type: application/json" -d @-
import json
card = {
"msg_type": "interactive",
"card": {
"header": {"title": {"content": "TITLE", "tag": "plain_text"}, "template": "COLOR"},
"elements": [
{"tag": "div", "text": {"content": "BODY LINE 1\nBODY LINE 2", "tag": "lark_md"}},
{"tag": "hr"},
{"tag": "div", "text": {"content": "SECTION 2 CONTENT", "tag": "lark_md"}}
]
}
}
print(json.dumps(card))
EOF
Card body supports lark_md: **bold**, *italic*, ~~strike~~, [link](url), \n for newlines.
After uploading image (Step B) to get image_key:
curl -s -X POST "$FEISHU_WEBHOOK" \
-H "Content-Type: application/json" \
-d '{"msg_type":"image","content":{"image_key":"img_xxx"}}'
Use API when sending files, or sending any content to an individual.
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"}'
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"}'
The content field must be a JSON-encoded string (escaped JSON inside JSON).
Text:
{"receive_id":"ID","msg_type":"text","content":"{\"text\":\"Hello\"}"}
Image (after upload):
{"receive_id":"ID","msg_type":"image","content":"{\"image_key\":\"img_xxx\"}"}
File (after upload):
{"receive_id":"ID","msg_type":"file","content":"{\"file_key\":\"file_xxx\"}"}
Check the response JSON:
{"code":0,"msg":"success"} → success{"code":0,"msg":"success","data":{...}} → successcode != 0 → report the error:
printf '%s' or heredoc to safely pass message content to curl if it contains special charactersFEISHU_WEBHOOK_SECRET and include timestamp + signim:message:send_as_bot (send messages), im:resource (upload images and files)Weekly Installs
279
Repository
GitHub Stars
2
First Seen
Feb 22, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex276
gemini-cli275
opencode275
cursor275
amp274
github-copilot274
Skills CLI 使用指南:AI Agent 技能包管理器安装与管理教程
27,400 周安装