一键导入
feishu-send-message
通过 Feishu REST API 发送消息到群组,适用于 cron 任务和无 gateway 直连的场景。 触发词:「飞书发消息」「发送到飞书群」「飞书群消息」「cron发飞书」。 当用户提到发送飞书消息、群组通知、cron任务发消息时使用。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
通过 Feishu REST API 发送消息到群组,适用于 cron 任务和无 gateway 直连的场景。 触发词:「飞书发消息」「发送到飞书群」「飞书群消息」「cron发飞书」。 当用户提到发送飞书消息、群组通知、cron任务发消息时使用。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
高德地图综合服务,支持POI搜索、路径规划、旅游规划、周边搜索和热力图数据可视化
Knowledge comic creator supporting multiple art styles and tones. Creates original educational comics with detailed panel layouts and sequential image generation. Use when user asks to create "知识漫画", "教育漫画", "biography comic", "tutorial comic", or "Logicomix-style comic".
Generate professional infographics with 21 layout types and 21 visual styles. Analyzes content, recommends layout×style combinations, and generates publication-ready infographics. Use when user asks to create "infographic", "visual summary", "信息图", "可视化", or "高密度信息大图".
Darwin Skill (达尔文.skill): autonomous skill optimizer inspired by Karpathy's autoresearch. Evaluates SKILL.md files using an 8-dimension rubric (structure + effectiveness), runs hill-climbing with git version control, validates improvements through test prompts, and generates visual result cards. Use when user mentions "优化skill", "skill评分", "自动优化", "auto optimize", "skill质量检查", "达尔文", "darwin", "帮我改改skill", "skill怎么样", "提升skill质量", "skill review", "skill打分".
从 DESIGN.md 生成预览图并截图的工作流 - 解决 Playwright 浏览器路径问题和 YAML 解析
Cron jobs auto-deliver final responses to configured targets — send_message to the same target gets deduplicated and skipped. Print report content directly as final response instead.
| name | feishu-send-message |
| version | 1.1.0 |
| slug | feishu-send-message |
| description | 通过 Feishu REST API 发送消息到群组,适用于 cron 任务和无 gateway 直连的场景。 触发词:「飞书发消息」「发送到飞书群」「飞书群消息」「cron发飞书」。 当用户提到发送飞书消息、群组通知、cron任务发消息时使用。 |
| metadata | {"emoji":"📮","keywords":["feishu","飞书","send_message","群消息","cron"]} |
通过 Feishu Open API 发送消息到群组,适用于 cron 任务、脚本等无法直接调用 gateway 的场景。
本技能配套以下参考文件(位于 references/ 目录):
references/api-reference.md — API 参考(获取token、发送消息、上传图片)references/chat-id-lookup.md — 群组 chat_id 查询表位置:/opt/data/.env
字段:FEISHU_APP_ID、FEISHU_APP_SECRET
import json
from urllib.request import Request, urlopen
# 读取凭证
app_id = app_secret = None
with open('/opt/data/.env', 'r') as f:
for line in f:
line = line.strip()
if line.startswith('FEISHU_APP_ID='):
app_id = line.split('=', 1)[1]
elif line.startswith('FEISHU_APP_SECRET='):
app_secret = line.split('=', 1)[1]
# 获取 token(有效期 7200 秒,cron 任务每次重新获取)
token_url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal"
token_data = json.dumps({"app_id": app_id, "app_secret": app_secret}).encode()
req = Request(token_url, data=token_data, headers={"Content-Type": "application/json"})
resp = urlopen(req)
tenant_token = json.loads(resp.read().decode())["tenant_access_token"]
chat_id = "oc_xxx" # 目标群组 chat_id(见下方已知群组表)
send_url = "https://open.feishu.cn/open-apis/im/v1/messages"
send_data = json.dumps({
"receive_id": chat_id,
"msg_type": "text",
"content": json.dumps({"text": "消息内容"})
}).encode()
req = Request(
f"{send_url}?receive_id_type=chat_id",
data=send_data,
headers={
"Content-Type": "application/json; charset=utf-8",
"Authorization": f"Bearer {tenant_token}"
}
)
resp = urlopen(req)
send_resp = json.loads(resp.read().decode())
# send_resp["code"] == 0 表示成功
飞书发送图片需要先上传获取 image_key,再发送图片消息。MEDIA: 前缀在飞书端不可靠,必须用 REST API。
import os
def upload_image(filepath, tenant_token):
"""上传图片到飞书,返回 image_key"""
boundary = '----WebKitFormBoundary7MA4YWxkTrZu0gW'
filename = os.path.basename(filepath)
with open(filepath, 'rb') as f:
file_data = f.read()
body = (
f'--{boundary}\r\n'
f'Content-Disposition: form-data; name="image_type"\r\n\r\n'
f'message\r\n'
f'--{boundary}\r\n'
f'Content-Disposition: form-data; name="image"; filename="{filename}"\r\n'
f'Content-Type: image/png\r\n\r\n'
).encode() + file_data + f'\r\n--{boundary}--\r\n'.encode()
req = Request(
"https://open.feishu.cn/open-apis/im/v1/images",
data=body,
headers={
"Authorization": f"Bearer {tenant_token}",
"Content-Type": f"multipart/form-data; boundary={boundary}"
}
)
resp = urlopen(req)
result = json.loads(resp.read().decode())
if result.get("code") == 0:
return result["data"]["image_key"]
raise Exception(f"Upload failed: {result}")
def send_image(chat_id, image_key, tenant_token):
"""发送图片消息到群组"""
send_data = json.dumps({
"receive_id": chat_id,
"msg_type": "image",
"content": json.dumps({"image_key": image_key})
}).encode()
req = Request(
"https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=chat_id",
data=send_data,
headers={
"Content-Type": "application/json; charset=utf-8",
"Authorization": f"Bearer {tenant_token}"
}
)
resp = urlopen(req)
result = json.loads(resp.read().decode())
return result.get("code") == 0
批量发送图片:
for fname, label in covers:
fpath = os.path.join(ARTICLE_DIR, fname)
send_text(chat_id, label)
image_key = upload_image(fpath, tenant_token)
send_image(chat_id, image_key, tenant_token)
以下是发送文本消息的完整脚本,可直接在 execute_code 中运行:
import json
from urllib.request import Request, urlopen
# 1. 读取凭证
app_id = app_secret = None
with open('/opt/data/.env', 'r') as f:
for line in f:
line = line.strip()
if line.startswith('FEISHU_APP_ID='):
app_id = line.split('=', 1)[1]
elif line.startswith('FEISHU_APP_SECRET='):
app_secret = line.split('=', 1)[1]
if not app_id or not app_secret:
raise ValueError("FEISHU_APP_ID or FEISHU_APP_SECRET not found in /opt/data/.env")
# 2. 获取 token
token_resp = json.loads(urlopen(Request(
"https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal",
data=json.dumps({"app_id": app_id, "app_secret": app_secret}).encode(),
headers={"Content-Type": "application/json"}
)).read().decode())
tenant_token = token_resp["tenant_access_token"]
# 3. 发送消息
chat_id = "oc_xxx" # ← 替换为目标群组
message = "Hello from Hermes!" # ← 替换为实际内容
send_resp = json.loads(urlopen(Request(
f"https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=chat_id",
data=json.dumps({
"receive_id": chat_id,
"msg_type": "text",
"content": json.dumps({"text": message})
}).encode(),
headers={
"Content-Type": "application/json; charset=utf-8",
"Authorization": f"Bearer {tenant_token}"
}
)).read().decode())
print(f"Status: {'✅ Success' if send_resp.get('code') == 0 else '❌ Failed'}")
print(f"Response: {json.dumps(send_resp, ensure_ascii=False, indent=2)}")
家庭账本 oc_2abe398e83a9758c72451ed260170088
完整列表见 references/chat-id-lookup.md。
/opt/data/.env 文件不存在或缺少必要字段
→ 检查文件是否存在
→ 验证 FEISHU_APP_ID 和 FEISHU_APP_SECRET 是否配置
→ 提供错误信息给用户
API 返回认证错误
→ 检查 APP_ID 和 APP_SECRET 是否正确
→ 验证应用是否已发布
→ 提供错误信息给用户
API 返回发送错误
→ 检查 chat_id 是否正确
→ 验证机器人是否在群组中
→ 检查消息格式是否正确
→ 提供错误信息给用户
multipart/form-data 格式错误
→ 检查 boundary 是否一致
→ 验证图片文件是否存在
→ 检查图片格式是否支持
→ 提供错误信息给用户
from hermes_tools import read_file,否则 NameErrorchat_id:发送群消息时 query 参数必须带 receive_id_type=chat_idMEDIA: 前缀发图在飞书不可靠:send_message 的 MEDIA: 前缀在飞书端经常丢图,必须用 REST API 上传+发送家庭账本月度汇总 cron 任务使用此方法发送报告到飞书群。流程: