1 在钉钉创建一个群聊,在群里设置自定义机器人,并且配置关键词
2 配置webhook(机器人url)
3 开发钉钉提醒消息(markdown格式或者text文档) open.dingtalk.com/document/or…
import requests
import json
from datetime import datetime
def send_markdown_message(webhook_url, title, text):
headers = {'Content-Type': 'application/json;charset=utf-8'}
date_today = datetime.now().strftime("%Y-%m-%d")
data = {
'msgtype': 'markdown',
'markdown': {
'title':title,
'text': text.format(date_today)
}
}
response = requests.post(webhook_url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
print("消息发送成功!")
print(data)
else:
print("消息发送失败:", response.text)
# 替换为你钉钉机器人的 Webhook 地址
webhook_url = https://oapi.dingtalk.com/robot/sendaccess_token=8426d64b0094bd
# 替换为你要发送的消息标题和内容
title = '来自食药的测试消息'
text = '''
### 今日消息通知 : {}
这是一条 **来自食药的测试消息**。
- 项目1
- 项目2
- 20240509会议
- [baidu](https://www.baidu.com/)
'''
# 发送 Markdown 消息
send_markdown_message(webhook_url, title, text)