Python调用飞书发送消息

{
"open_id":"ou_5ad573a6411d72b8305fda3a9c15c70e",
"root_id":"om_40eb06e7b84dc71c03e009ad3c754195",
"chat_id":"oc_5ad11d72b830411d72b836c20",
"user_id": "92e39a99",
"email":"fanlv@gmail.com",
"msg_type":"text",
"content":{
"text":"text content<at user_id=\"ou_88a56e7e8e9f680b682f6905cc09098e\">test</at>"
}
}

Curl 请求 Demo

curl -X POST \
https://open.feishu.cn/open-apis/message/v4/send/ \
-H 'Authorization: Bearer t-fee42159a366c575f2cd2b2acde2ed1e94c89d5f' \
-H 'Content-Type: application/json' \
-d '{
"chat_id": "oc_f5b1a7eb27ae2c7b6adc2a74faf339ff",
"msg_type": "text",
"content": {
"text": "text content<at user_id=\"ou_88a56e7e8e9f680b682f6905cc09098e\">test</at>"
}
}'

使用Python封装飞书请求

接下来我们以发送文本格式消息类型,进行以下封装,上代码:

  封装后我们就可以直接调用封装的类,进行消息代码发送;webhook即是创建机器人时生成的webhook链接,执行以下代码后,就可以使用飞书发送消息咯~

    webhook = "https://open.feishu.cn/XXXXXXX"
feishu = FeiShutalkChatbot(webhook)
feishu.send_text("重庆百货-新世纪鱼胡路店内商品'1000800370-牛心白 约1kg'在商详[8]和榜单[7]中排名不一致")