dingding-alert.js
616 Bytes
const rp = require('request-promise');
const REG_AT = /@(\d+)/g;
module.exports = (text) => {
let match;
const ats = [];
while ((match = REG_AT.exec(text))) {
ats.push(match[1]);
}
const data = {
msgtype: 'text',
text: {
content: text
},
at: {
atMobiles: ats,
isAtAll: false
}
};
return rp({
uri: 'https://oapi.dingtalk.com/robot/send?access_token=0b14a14f6d2a3eae2a63d56a975b7ee2d7f2aad6f1782543196687cbe18fabda',
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
body: JSON.stringify(data)
});
};