dingding robot

"Custom bot" only supports message sending, automatic reply requires "enterprise internal bot"

send message

import requests
import json

res = 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)

Response

  • {"errcode":0,"errmsg":"ok"}message sent successfully
  • {"errcode":40035,"errmsg":"缺少参数 json"}Check whether the body parameter format is json
  • {"errcode":310000,"errmsg":"错误描述:关键词不匹配;解决方案:请联系群管理员查看此机器人的关键词,并在发送的信息中包含此关键词;"}When the keyword is set, the content must contain the keyword to send the message

message type

https://open.dingtalk.com/document/robots/custom-robot-access

text type

insert image description here

dict_tmp1 = {
    
    
    "msgtype": "text",
    "text": {
    
    
        "content":"1webhook"
    },
    "at": {
    
    
        "atUserIds":["vin0sen"],
        "isAtAll": False
    },
}

link type:

insert image description here

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 type

reference article

DingTalk custom robot official document

Guess you like

Origin blog.csdn.net/m0_52062236/article/details/132214283