Files
js-scripts/components/component-dingtalkrobot-ex.js
2025-04-04 17:19:07 +08:00

25 lines
915 B
JavaScript

exports.sendText = (token, message) => {
var dingTalkRobotURL = 'https://oapi.dingtalk.com/robot/send?access_token=' + token;
var postResult = $$.httpRequest()
.url(dingTalkRobotURL)
.addHeader('Content-Type', 'application/json')
.post(JSON.stringify({
"msgtype": "text",
"text": {
"content": $STR(message)
}
}));
return postResult;
};
exports.sendTextDefault = (message) => {
var tokenFile = $$.file($$.prop('user.home'), '.component-dingtalkrobot.js.token');
if (!tokenFile.exists()) {
println('DingTalk token file not exists: ' + tokenFile);
return;
}
var token = $$.rFile(tokenFile).string().trim();
sendDingTalkRobotTextMessage(token, message);
};