t-comm
Version:
专业、稳定、纯粹的工具库
93 lines (90 loc) • 2.55 kB
JavaScript
import { _ as __assign } from '../tslib.es6-096fffdd.js';
import { sendWxRobotMsg, sendWxRobotMarkdown } from './base.js';
import { sendWxRobotBase64Img } from './send-img.js';
import './helper.js';
import 'axios';
import '../node-img/img.js';
var SEND_TO_ALL = 'ALL';
/**
* 根据chatId批量发送机器人消息
* - 如果传入的chatId不是数组,会转为数组
* - chatId 不能为空,要群发的话,可以设为 ALL
* @param {Function} sendFn 机器人发送消息的方法,如 sendWxRobotBase64Img
* @param {Array<string> | string} chatId 会话Id
* @param {object} args 发送消息的其他参数
* @ignore
*/
function batchSendRobotByChatId(sendFn, chatId, args) {
if (args === void 0) {
args = {};
}
if (!chatId) {
console.error('Error: chatId 不能为空');
return;
}
if (!Array.isArray(chatId)) {
chatId = [chatId];
}
if (chatId.indexOf(SEND_TO_ALL) > -1) {
sendFn(__assign(__assign({}, args || {}), {
chatId: undefined
}));
} else {
for (var _i = 0, chatId_1 = chatId; _i < chatId_1.length; _i++) {
var id = chatId_1[_i];
sendFn(__assign(__assign({}, args || {}), {
chatId: id
}));
}
}
}
/**
* 批量发送企业微信机器人base64图片
* @param {object} config 配置信息
* @param {string} config.img base64图片
* @param {string} config.chatId 会话Id
* @param {string} config.webhookUrl webhook地址
* @returns {Promise<object>} 请求Promise
* @example
*
* batchSendWxRobotBase64Img({
* img: 'xxx',
* chatId: 'xxx', // or ['xxx], or ['ALL'], or 'ALL'
* webhookUrl: 'xxx',
* }).then(() => {
*
* })
*
*/
function batchSendWxRobotBase64Img(_a) {
var img = _a.img,
chatId = _a.chatId,
webhookUrl = _a.webhookUrl;
return batchSendRobotByChatId(sendWxRobotBase64Img, chatId, {
img: img,
webhookUrl: webhookUrl
});
}
function batchSendWxRobotMsg(_a) {
var content = _a.content,
alias = _a.alias,
chatId = _a.chatId,
webhookUrl = _a.webhookUrl;
return batchSendRobotByChatId(sendWxRobotMsg, chatId, {
content: content,
alias: alias,
webhookUrl: webhookUrl
});
}
function batchSendWxRobotMarkdown(_a) {
var content = _a.content,
attachments = _a.attachments,
chatId = _a.chatId,
webhookUrl = _a.webhookUrl;
return batchSendRobotByChatId(sendWxRobotMarkdown, chatId, {
content: content,
attachments: attachments,
webhookUrl: webhookUrl
});
}
export { batchSendWxRobotBase64Img, batchSendWxRobotMarkdown, batchSendWxRobotMsg };