创建机器人
打开需要创建机器人的群组,点击 群组机器 人的图标
点击 + 号键创建机器人
点击 自定义 创建自定义机器人
点击 添加
设置机器人头像,机器人名称,机器人属组,点击下一步
复制API(webhook),点击完成
编写Python脚本
注意:修改脚本内requrl的值为机器人的webhook地址
脚本使用说明:
使用方法:脚本后面跟要发送的消息
at所有人将 isAtAll 的值改为True
at指定人在 atMobiles 列表定义被at人的手机,列表形式
requrl的值为机器人的api,在创建机器人的时候会自动生成api
#!/usr/bin/python
#coding=utf-8
import urllib
import urllib2
import json
import sys
import re
headers = {'Content-Type': 'application/json'}
test_data = {
'msgtype':"text",
"text":{
'content':"%s" % sys.argv[1]
},
"at":{
"atMobiles":[
133xxxx0502,
186xxxx6057
],
"isAtAll":False
}
}
requrl = "https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxx"
req = urllib2.Request(url = requrl,headers = headers,data = json.dumps(test_data))
response = urllib2.urlopen(req)
转载于:https://blog.51cto.com/270142877/1965374