61 lines
1.5 KiB
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 渠道出站实现。
* 推送交互式卡片消息到飞书机器人 webhook。
*/
class FeishuDispatch 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 content = extData.content || extData.text || `消息:${record.ref_code || record.ext_id}`;
const body = {
msg_type: 'interactive',
card: {
header: {
title: {
tag: 'plain_text',
content: title,
},
},
elements: [
{
tag: 'div',
text: {
tag: 'lark_md',
content: typeof content === 'string' ? content : JSON.stringify(content),
},
},
{
tag: 'hr',
},
{
tag: 'note',
elements: [
{
tag: 'plain_text',
content: `编号: ${record.ref_code || record.ext_id}`,
},
],
},
],
},
};
ctx.logger.info(`[inbox feishu] 推送消息 ext_id=${record.ext_id} url=${record.target_url}`);
return await this.post(record.target_url, body);
}
}
module.exports = FeishuDispatch;