MCPcopy Create free account
hub / github.com/6dylan6/jdpro / ddBotNotify

Function ddBotNotify

function/sendNotify.js:1371–1438  ·  view source on GitHub ↗
(text, desp)

Source from the content-addressed store, hash-verified

1369}
1370
1371function ddBotNotify(text, desp) {
1372 return new Promise((resolve) => {
1373 const options = {
1374 url: `https://oapi.dingtalk.com/robot/send?access_token=${DD_BOT_TOKEN}`,
1375 json: {
1376 msgtype: 'text',
1377 text: {
1378 content: ` ${text}\n\n${desp}`,
1379 },
1380 },
1381 headers: {
1382 'Content-Type': 'application/json',
1383 },
1384 timeout,
1385 };
1386 if (DD_BOT_TOKEN && DD_BOT_SECRET) {
1387 const crypto = require('crypto');
1388 const dateNow = Date.now();
1389 const hmac = crypto.createHmac('sha256', DD_BOT_SECRET);
1390 hmac.update(`${dateNow}\n${DD_BOT_SECRET}`);
1391 const result = encodeURIComponent(hmac.digest('base64'));
1392 options.url = `${options.url}&timestamp=${dateNow}&sign=${result}`;
1393 $.post(options, (err, resp, data) => {
1394 try {
1395 if (err) {
1396 console.log('钉钉发送通知消息失败!!\n');
1397 console.log(err);
1398 } else {
1399 data = JSON.parse(data);
1400 if (data.errcode === 0) {
1401 console.log('钉钉发送通知消息成功🎉。\n');
1402 } else {
1403 console.log(`${data.errmsg}\n`);
1404 }
1405 }
1406 } catch (e) {
1407 $.logErr(e, resp);
1408 }
1409 finally {
1410 resolve(data);
1411 }
1412 });
1413 } else if (DD_BOT_TOKEN) {
1414 $.post(options, (err, resp, data) => {
1415 try {
1416 if (err) {
1417 console.log('钉钉发送通知消息失败!!\n');
1418 console.log(err);
1419 } else {
1420 data = JSON.parse(data);
1421 if (data.errcode === 0) {
1422 console.log('钉钉发送通知消息完成。\n');
1423 } else {
1424 console.log(`${data.errmsg}\n`);
1425 }
1426 }
1427 } catch (e) {
1428 $.logErr(e, resp);

Callers 1

sendNotifyFunction · 0.70

Calls 4

nowMethod · 0.80
postMethod · 0.45
logMethod · 0.45
logErrMethod · 0.45

Tested by

no test coverage detected