t-comm
Version:
专业、稳定、纯粹的工具库
99 lines (94 loc) • 2.79 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var tslib_es6 = require('../tslib.es6-01322ba9.js');
var wecomRobot_base = require('./base.js');
var wecomRobot_sendImg = require('./send-img.js');
require('./helper.js');
require('axios');
require('../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(tslib_es6.__assign(tslib_es6.__assign({}, args || {}), {
chatId: undefined
}));
} else {
for (var _i = 0, chatId_1 = chatId; _i < chatId_1.length; _i++) {
var id = chatId_1[_i];
sendFn(tslib_es6.__assign(tslib_es6.__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(wecomRobot_sendImg.sendWxRobotBase64Img, chatId, {
img: img,
webhookUrl: webhookUrl
});
}
function batchSendWxRobotMsg(_a) {
var content = _a.content,
alias = _a.alias,
chatId = _a.chatId,
webhookUrl = _a.webhookUrl;
return batchSendRobotByChatId(wecomRobot_base.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(wecomRobot_base.sendWxRobotMarkdown, chatId, {
content: content,
attachments: attachments,
webhookUrl: webhookUrl
});
}
exports.batchSendWxRobotBase64Img = batchSendWxRobotBase64Img;
exports.batchSendWxRobotMarkdown = batchSendWxRobotMarkdown;
exports.batchSendWxRobotMsg = batchSendWxRobotMsg;