UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

113 lines (110 loc) 3.25 kB
import { b as __awaiter, c as __generator, _ as __assign } from '../tslib.es6-096fffdd.js'; import { sendWxRobotMsg, sendWxRobotMarkdown } from './base.mjs'; import { sendWxRobotBase64Img } from './send-img.mjs'; import './helper.mjs'; import 'axios'; import '../node-img/img.mjs'; 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 = {}; } return __awaiter(this, void 0, void 0, function () { var _i, chatId_1, id; return __generator(this, function (_a) { switch (_a.label) { case 0: if (!chatId) { console.error('Error: chatId 不能为空'); return [2 /*return*/]; } if (!Array.isArray(chatId)) { chatId = [chatId]; } if (chatId.indexOf(SEND_TO_ALL) > -1) { return [2 /*return*/, sendFn(__assign(__assign({}, args || {}), { chatId: undefined }))]; } _i = 0, chatId_1 = chatId; _a.label = 1; case 1: if (!(_i < chatId_1.length)) return [3 /*break*/, 4]; id = chatId_1[_i]; return [4 /*yield*/, sendFn(__assign(__assign({}, args || {}), { chatId: id }))]; case 2: _a.sent(); _a.label = 3; case 3: _i++; return [3 /*break*/, 1]; case 4: return [2 /*return*/]; } }); }); } /** * 批量发送企业微信机器人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, _b = _a.isV2, isV2 = _b === void 0 ? false : _b; return batchSendRobotByChatId(sendWxRobotMarkdown, chatId, { content: content, attachments: attachments, webhookUrl: webhookUrl, isV2: isV2 }); } export { batchSendWxRobotBase64Img, batchSendWxRobotMarkdown, batchSendWxRobotMsg };