直接上代码,
const request = require('request')
const dingTalkRobot = ({title = '微信小程序发版', msg = 'git', env = '测试', version = '2.0.0'}) => {
const url = 'https://oapi.dingtalk.com/robot/send?access_token=${定义机器人时获取}';
const time = `${new Date().getHours()}:${new Date().getMinutes()}`
const params = {
msgtype: "markdown",
markdown: {
title,
text: `#### ${title} \n 发版信息:${msg} \n 环境信息:${env} \n 版本信息:${version} \n > ![screenshot]()\n > ###### ${time} 发布 \n`
},
}
return new Promise((resolve, reject) => {
request(
{
url,
method: 'POST',
json: true,
headers: {
"content-type": "application/json",
},
body: params
},
function(error, response, body) {
if (response.statusCode === 200) {
console.log('通知成功', body)
resolve(body)
} else {
console.log('通知失败')
reject(error)
}
}
);
})
}
其中机器人的设置参考钉钉官方文档robat