添加自定義機器人
尚在編寫中,具體內容可參考釘釘官方文檔:https://developers.dingtalk.com/document/robots/custom-robot-access
使用Google Chrome 調試
調用機器人
將access_token
作為鏈接直接復制入搜索框,按下F12
打開調試界面,切換至Console
,將相關代碼復制入Console
即可
由於需要使用jQuery
的ajax
方法,所以要引入
// 第一段需要復制的代碼
var script = document.createElement('script');
script.setAttribute('type','text/javascript');
script.setAttribute('src',"https://code.jquery.com/jquery-3.1.1.min.js");
document.getElementsByTagName('head')[0].appendChild(script);
如果你足夠高興,那么你可以將jQuery
的版本可以通過直接更改jQuery的地址
為以下幾個地址:
script.setAttribute('src',"jQuery的地址");
jQuery官網引用地址:
3.1.1
版本:https://code.jquery.com/jquery-3.1.1.min.js
3.0.0
版本:https://code.jquery.com/jquery-3.0.0.min.js
2.1.4
版本:https://code.jquery.com/jquery-2.1.4.min.js
百度引用地址:http://libs.baidu.com/jquery/2.1.4/jquery.min.js
微軟引用地址:http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js
等等……
以下這段代碼是用於測試你的瀏覽器是否正常執行了POST
請求的
// 第二段需要復制的代碼
var url = "https://oapi.dingtalk.com/robot/send?access_token=此處替換為你的機器人的access_token",
msg = '{"msgtype":"text", "text": {"content": "TEST."}}';
$.ajax({
type: 'POST',
url: url,
data: msg,
dataType: 'json',
headers: {'Content-Type': 'application/json'},
success: function(result){
console.log(result.responseText);
}
});
若輸入代碼后輸出如圖所示,且之前定義的機器人發送了內容為TEST.
的消息則可以正常使用
接下來我們來解釋一下第二段代碼的具體使用方法(第一段沒什么好講的,直接復制就好):
// 第二段需要復制的代碼
var url = "https://oapi.dingtalk.com/robot/send?access_token=此處替換為你的機器人的access_token",
msg = `此處為發送消息的文本
或多行文本`; // 若要發送多行消息,則需使用反單引號("`")括起文本
$.ajax({ // 發送POST
type: 'POST',
url: url,
data: msg,
dataType: 'json',
headers: {'Content-Type': 'application/json'},
success: function(result){
console.log(result.responseText);
}
});
發送消息文本格式請見另一篇文章https://www.cnblogs.com/howardzhangdqs/p/dingtalk_robot_instruction_2.html
使用Python
調用機器人
尚在編寫中……
使用Postman
調用機器人
尚在編寫中……