MCPcopy
hub / github.com/smallfawn/QLScriptPublic / feishu_bot

Function feishu_bot

notify.py:227–256  ·  view source on GitHub ↗

使用 飞书机器人 推送消息。

(title: str, content: str)

Source from the content-addressed store, hash-verified

225
226
227def feishu_bot(title: str, content: str) -> None:
228 """
229 使用 飞书机器人 推送消息。
230 """
231 if not push_config.get("FSKEY"):
232 return
233 print("飞书 服务启动")
234
235 url = f'https://open.feishu.cn/open-apis/bot/v2/hook/{push_config.get("FSKEY")}'
236 data = {"msg_type": "text", "content": {"text": f"{title}\n\n{content}"}}
237
238 # Add signature if secret is provided
239 # Note: Feishu's signature algorithm uses timestamp+"\n"+secret as the HMAC key
240 # and signs an empty message, which differs from typical HMAC usage
241 if push_config.get("FSSECRET"):
242 timestamp = str(int(time.time()))
243 string_to_sign = f'{timestamp}\n{push_config.get("FSSECRET")}'
244 hmac_code = hmac.new(
245 string_to_sign.encode("utf-8"), digestmod=hashlib.sha256
246 ).digest()
247 sign = base64.b64encode(hmac_code).decode("utf-8")
248 data["timestamp"] = timestamp
249 data["sign"] = sign
250
251 response = requests.post(url, data=json.dumps(data)).json()
252
253 if response.get("StatusCode") == 0 or response.get("code") == 0:
254 print("飞书 推送成功!")
255 else:
256 print("飞书 推送失败!错误信息如下:\n", response)
257
258
259def go_cqhttp(title: str, content: str) -> None:

Callers

nothing calls this directly

Calls 4

printFunction · 0.70
getMethod · 0.45
timeMethod · 0.45
postMethod · 0.45

Tested by

no test coverage detected