dingding-alert.js 796 Bytes
/**
 * Created by zhangwenxue on 2019/07/23.
 */
'use strict';

const rp = require('request-promise');

/**
 * 向dingtalk robot发 markdown 格式的消息
 * @param {string} text markdown格式消息
 * @param {Array[string]} atMobiles 需要@的手机号
 * @param {boolean} isAtAll 是否@全体人员
 */
module.exports = (text, atMobiles, isAtAll) => {
  const data = {
    msgtype: 'markdown',
    markdown: {
      title: 'ufo-app-web',
      text
    },
    at: {
      atMobiles,
      isAtAll,
    }
  };

  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)
  });
};