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=499f845e894e0aebb6d29ec9f3b186cbb99bfa89cd4347fa4c0e8efd4081ecd5',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json; charset=utf-8'
    },
    body: JSON.stringify(data)
  });
};