36 lines
1001 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const OutboundBase = require('./base');
/**
* 钉钉 Bot 渠道出站实现。
* 推送 Markdown 消息到钉钉机器人 webhook。
*/
class DingtalkDispatch extends OutboundBase {
/**
* 通过钉钉 Bot 推送消息。
* @param {Object} record 消息记录(Sequelize Model 实例)。
* @return {Promise<{status: number, data: *}>} 推送响应。
*/
async push(record) {
const { ctx } = this;
const extData = record.ext_data || {};
const title = extData.title || '新消息通知';
const text = extData.content || extData.text || `消息:${record.ref_code || record.ext_id}`;
const body = {
msgtype: 'markdown',
markdown: {
title,
text: typeof text === 'string' ? text : JSON.stringify(text),
},
};
ctx.logger.info(`[inbox dingtalk] 推送消息 ext_id=${record.ext_id} url=${record.target_url}`);
return await this.post(record.target_url, body);
}
}
module.exports = DingtalkDispatch;