“自定义机器人”只支持消息发送,自动回复需要“企业内部机器人”
消息发送
import requests
import jsonres = requests.post('https://oapi.dingtalk.com/robot/send?access_token=036a339axxx',data = json.dumps({"text": {"content":"hello world" # 不设置关键词},"at": {"atUserIds":["user123"],"isAtAll": False # 不要省略},"msgtype": "text",}),headers={'Content-Type': 'application/json'}
)
print(res.text)
响应情况
{"errcode":0,"errmsg":"ok"}
消息发送成功{"errcode":40035,"errmsg":"缺少参数 json"}
检查body参数格式是否为json{"errcode":310000,"errmsg":"错误描述:关键词不匹配;解决方案:请联系群管理员查看此机器人的关键词,并在发送的信息中包含此关键词;"}
设置了关键字的情况,content必须包含关键字才能发送消息
消息类型
https://open.dingtalk.com/document/robots/custom-robot-access
text类型
dict_tmp1 = {"msgtype": "text","text": {"content":"1webhook"},"at": {"atUserIds":["vin0sen"],"isAtAll": False},
}
link类型:
dict_tmp2 = {"msgtype": "link", "link": {"title": "钉钉", "text": "钉钉,让进步发生", "picUrl": "https://img.alicdn.com/imgextra/i4/O1CN01RtfAks1Xa6qJFAekm_!!6000000002939-2-tps-128-128.png", "messageUrl": "https://www.dingtalk.com/"}
}
- markdown类型
参考文章
钉钉自定义机器人官方文档