[Question] 飞书的webhook收不到通知,钉钉可以,请问什么时候计划支持飞书呢
描述问题 如题
复现 重现该行为的步骤: 添加飞书webhook https://open.larksuite.com/open-apis/bot/v2/hook/5a5b6710-c683-4b1b-abf6-xxxxxx 测试发送 日志显示 [Info] 2025-06-27 20:52:52 "url":"/api/v2/manage/setting" "method":"GET" "status":200 "protocol":"HTTP/1.1" "remote_ip":"172.26.0.1" "bytes_in": "0 bytes" "bytes_out": "5719 bytes
但是收不到通知 空空如也
但是换成钉钉机器人可以顺利收到通知
期望的结果 希望能支持飞书webhook
部署方式
- Docker
环境 (请填写环境信息):
- 操作系统: [MacOS]
- 浏览器 [chrome]
- 版本号 [137.0.7151.104]
额外的日志信息 在这里添加有关该问题的所有日志。
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
Title: [Question] Feishu's webhook cannot receive notifications, DingTalk can do it, when will it plan to support Feishu?
目前只支持钉钉的webhook吧, 我看有人在开发飞书的相关能力了
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
Currently, only DingTalk's webhook is supported. I see that someone is developing Feishu's related abilities
#!/usr/bin/python3
import json
import hmac
import hashlib
import datetime
import base64
import requests
from flask import Flask, request
# 飞书 Webhook 配置
feishu_webhook_url = "https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
secret = "xxxxxxxxxxxxxxxxxxxxxxx"
app = Flask(__name__)
def calculate_signature(secret, timestamp):
"""保留原签名逻辑"""
timestamp = int(datetime.datetime.now().timestamp())
string_to_sign = '{}\n{}'.format(timestamp, secret)
hmac_code = hmac.new(string_to_sign.encode("utf-8"), digestmod=hashlib.sha256).digest()
signature = base64.b64encode(hmac_code).decode('utf-8')
return signature
def extract_markdown_text(data):
"""提取并分行处理 markdown 的 text 字段,同时去掉空行"""
markdown_content = data.get("markdown", {}).get("text", "")
if not markdown_content:
print("Markdown text is empty or not provided.")
return []
# 按换行符分割,并过滤掉空行
lines = [line.strip() for line in markdown_content.split("\n") if line.strip()]
print("Extracted lines from markdown text (empty lines removed):")
for line in lines:
print(line) # 打印每一行
return lines
def send_feishu_notification(lines, webhook_url, secret):
"""发送通知到飞书"""
timestamp = int(datetime.datetime.now().timestamp())
signature = calculate_signature(secret, timestamp)
headers = {
"Content-Type": "application/json",
}
# 将提取的行内容重新合并到消息卡片中
markdown_content = "\n".join(lines)
send_data = {
"timestamp": timestamp,
"sign": signature,
"msg_type": "interactive",
"card": {
"config": {"wide_screen_mode": True},
"elements": [
{
"tag": "div",
"text": {"tag": "lark_md", "content": f"**Yearning 工单通知**\n\n{markdown_content}"},
},
],
"header": {
"template": "blue",
"title": {"content": "Yearning 工单通知", "tag": "plain_text"}
},
},
}
response = requests.post(webhook_url, headers=headers, data=json.dumps(send_data))
print("Webhook URL:", webhook_url)
print("Request Headers:", headers)
print("Request Body:", json.dumps(send_data, indent=4, ensure_ascii=False))
print("Response:", response.status_code, response.text)
if response.status_code == 200:
print("Notification sent successfully.")
else:
print(f"Failed to send notification. Status code: {response.status_code}, Response: {response.text}")
@app.route("/", methods=["POST"])
def handle_yearning_notification():
"""处理接收到的 Yearning 通知"""
try:
data = request.get_json()
if not data:
return "Invalid request", 400
print("Received Body:", json.dumps(data, indent=4, ensure_ascii=False))
# 提取 markdown 的 text 字段并逐行处理
lines = extract_markdown_text(data)
# 发送提取内容到飞书
send_feishu_notification(lines, feishu_webhook_url, secret)
return "Notification processed.", 200
except Exception as e:
print("Error processing request:", str(e))
return "Internal Server Error", 500
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
替换里面的key secret部分,然后webhook部分填写类似: http://localhost:5000 就可以发到飞书了,需要安装 flask requests两个pip包