dingding-alert.js
752 Bytes
const rp = require('request-promise');
const REG_AT = /@(\d+)/g;
module.exports = (text, sendTo) => {
let match;
let accessToken = sendTo === 'bjSpider' ? 'ed18d72771bb5df6ee70ee6d59e67d7399f6c5b9a67ebffa06a47c29cc5235c8' : '499f845e894e0aebb6d29ec9f3b186cbb99bfa89cd4347fa4c0e8efd4081ecd5';
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='+accessToken,
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
body: JSON.stringify(data)
});
};