34 lines
953 B
JavaScript
34 lines
953 B
JavaScript
'use strict';
|
||
|
||
const OutboundBase = require('./base');
|
||
|
||
/**
|
||
* 企微 Bot 渠道出站实现。
|
||
* 推送 Markdown 消息到企业微信机器人 webhook。
|
||
*/
|
||
class WecomDispatch 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 content = extData.content || extData.text || `新消息通知:${record.ref_code || record.ext_id}`;
|
||
|
||
const body = {
|
||
msgtype: 'markdown',
|
||
markdown: {
|
||
content: typeof content === 'string' ? content : JSON.stringify(content),
|
||
},
|
||
};
|
||
|
||
ctx.logger.info(`[inbox wecom] 推送消息 ext_id=${record.ext_id} url=${record.target_url}`);
|
||
return await this.post(record.target_url, body);
|
||
}
|
||
}
|
||
|
||
module.exports = WecomDispatch;
|