1、发送图片
需要先创建一个应用。 然后,上传图片或视频 最后,用富文本发送
import requests
from requests_toolbelt import MultipartEncoder
# 输入pip install requests_toolbelt 安装依赖库
def uploadImage():
url = "https://open.feishu.cn/open-apis/im/v1/images"
form = {'image_type': 'message',
'image': (open(r'/mnt/f/ComfyUI_00141_.png', 'rb'))} # 需要替换具体的path
multi_form = MultipartEncoder(form)
headers = {'Authorization': 'Bearer t-g1049ofo4FIGDUOS6VMNJFC4SZZEP7HZYQU2YAGT', 'Content-Type': multi_form.content_type}
response = requests.request("POST", url, headers=headers, data=multi_form)
print(response.headers['X-Tt-Logid']) # for debug or oncall
print(response.content) # Print Response
if __name__ == '__main__':
uploadImage()
3、发送富文本消息
https://open.feishu.cn/open-apis/bot/v2/hook/fb0a79bd-51ca-463a-b2a5-929a4ca27053
{
"msg_type": "post",
"content": {
"post": {
"zh_cn": {
"title": "项目更新通知",
"content": [
[{
"tag": "text",
"text": "哈哈哈测试一下: "
}, {
"tag": "a",
"text": "请查看",
"href": "http://www.example.com/"
}, {
"tag": "at",
"user_id": "ou_18eac8"
}],
[{
"tag": "img",
"image_key": "img_v3_02f1_92df7635-9f04-48b3-b4fd-a2396d5b398g"
}]
]
}
}
}
}
富文本支持的标签和参数说明
-
文本标签:text
字段 类型 是否必填 示例值 描述 text string 是 Text content 文本内容 -
超链接标签:a
字段 类型 是否必填 示例值 描述 text string 是 测试地址 超链接的文本内容 href string 是 https://open.feishu.cn 链接地址 -
@ 标签:at
字段 类型 是否必填 示例值 描述 user_id string 是 ou_18eac85d35a26****02e8bbbb 用户的 Open ID 或 User ID user_name string 否 Jian Li 用户名称 -
图片标签:img
字段 类型 是否必填 示例值 描述 image_key string 是 img_ecffc3b9-8f14-400f-a014-05eca1a4310g 图片的唯一标识