t-comm
Version:
专业、稳定、纯粹的工具库
146 lines (143 loc) • 3.67 kB
JavaScript
import { b as __awaiter, c as __generator } from '../tslib.es6-096fffdd.js';
import { sendToRobot } from './helper.mjs';
import 'axios';
/**
* 给机器人发送普通消息
* @param {Object} config 配置内容
* @param {string} config.webhookUrl - 钩子链接
* @param {string} config.chatId - 会话id
* @param {string} config.alias - 别名
* @param {string} config.content - 内容
* @returns {Promise<object>} Promise
*
* @example
*
* sendWxRobotMsg({
* webhookUrl: 'xxx',
* chatId: 'xxx',
* content: 'xxx',
* alias: 'xxx',
* }).then(() => {
*
* })
*/
function sendWxRobotMsg(_a) {
var webhookUrl = _a.webhookUrl,
chatId = _a.chatId,
alias = _a.alias,
content = _a.content;
return new Promise(function (resolve, reject) {
sendToRobot({
webhookUrl: webhookUrl,
params: {
chatid: chatId,
msgtype: 'text',
text: {
content: content,
mentioned_list: Array.isArray(alias) ? alias : [alias]
}
}
}).then(function (res) {
resolve(res);
})["catch"](function (err) {
reject(err);
});
});
}
/**
* 给机器人发送Markdown消息
* @param {Object} config 配置内容
* @param {string} config.webhookUrl - 钩子链接
* @param {string} config.chatId - 会话id
* @param {string} config.content - 内容
* @param {Array<object>} config.attachments - 附加内容
* @returns {Promise<object>} 请求Promise
* @example
*
* sendWxRobotMarkdown({
* webhookUrl: 'xxx',
* chatId: 'xxx',
* content: 'xxx',
* attachments: []
* }).then(() => {
*
* })
*/
function sendWxRobotMarkdown(_a) {
var webhookUrl = _a.webhookUrl,
chatId = _a.chatId,
content = _a.content,
attachments = _a.attachments,
_b = _a.isV2,
isV2 = _b === void 0 ? false : _b;
return new Promise(function (resolve, reject) {
sendToRobot({
webhookUrl: webhookUrl,
params: {
chatid: chatId,
msgtype: isV2 ? 'markdown_v2' : 'markdown',
markdown: isV2 ? undefined : {
content: content,
attachments: attachments,
at_short_name: true
},
markdown_v2: isV2 ? {
content: content
} : undefined
}
}).then(function (res) {
resolve(res);
})["catch"](function (err) {
reject(err);
});
});
}
/**
* 给机器人发送图片
* @param {Object} config 配置参数
* @param {string} config.webhookUrl 钩子链接
* @param {string} config.chatId 会话id
* @param {string} config.content 内容
* @param {string} config.md5Val md5内容
* @returns {Promise<object>} 请求Promise
*
* @example
*
* sendWxRobotImg({
* webhookUrl: 'xxx',
* chatId: 'xxx',
* content: 'xxx',
* md5Val: 'xxx'
* }).then(() => {
*
* })
*/
function sendWxRobotImg(_a) {
var webhookUrl = _a.webhookUrl,
chatId = _a.chatId,
content = _a.content,
md5Val = _a.md5Val;
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_b) {
return [2 /*return*/, new Promise(function (resolve, reject) {
sendToRobot({
webhookUrl: webhookUrl,
params: {
chatid: chatId,
msgtype: 'image',
image: {
base64: content,
md5: md5Val
}
}
}).then(function (res) {
resolve(res);
})["catch"](function (err) {
console.log('[sendWxRobotImg] err:\n ', err === null || err === void 0 ? void 0 : err.data);
reject(err);
});
})];
});
});
}
export { sendWxRobotImg, sendWxRobotMarkdown, sendWxRobotMsg };