pushoo
Version:
Instant Messaging Pushing SDK
803 lines • 37.5 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.notice = notice;
exports.noticeQmsg = noticeQmsg;
exports.noticeServerChan = noticeServerChan;
exports.noticePushPlus = noticePushPlus;
exports.noticePushPlusHxtrip = noticePushPlusHxtrip;
exports.noticeDingTalk = noticeDingTalk;
exports.noticeWeCom = noticeWeCom;
exports.noticeBark = noticeBark;
exports.noticeGoCqhttp = noticeGoCqhttp;
exports.noticeNodeOnebot = noticeNodeOnebot;
exports.noticeAtri = noticeAtri;
exports.noticePushdeer = noticePushdeer;
exports.noticeIgot = noticeIgot;
exports.noticeTelegram = noticeTelegram;
exports.noticeFeishu = noticeFeishu;
exports.noticeIfttt = noticeIfttt;
exports.noticeWecombot = noticeWecombot;
exports.noticeDiscord = noticeDiscord;
exports.noticeWxPusher = noticeWxPusher;
exports.noticeJoin = noticeJoin;
var axios_1 = require("axios");
var marked_1 = require("marked");
var markdown_to_txt_1 = require("markdown-to-txt");
function checkParameters(options, requires) {
if (requires === void 0) { requires = []; }
requires.forEach(function (require) {
if (!options[require]) {
throw new Error("".concat(require, " is required"));
}
});
}
function getHtml(content) {
return marked_1.marked.parse(content);
}
function getTxt(content) {
return (0, markdown_to_txt_1.default)(content);
}
function getTitle(content) {
return getTxt(content).split('\n')[0];
}
function removeUrlAndIp(content) {
var urlRegex = /(https?:\/\/[^\s]+)/g;
var ipRegex = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/g;
// 邮箱正则表达式来自 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email#validation
var mailRegExp = /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*/g;
return content
.replace(urlRegex, '')
.replace(ipRegex, '')
.replace(mailRegExp, '');
}
/**
* https://qmsg.zendee.cn/
*/
function noticeQmsg(options) {
return __awaiter(this, void 0, void 0, function () {
var url, msg, param, qq, bot, group, response;
var _a, _b, _c, _d, _e, _f, _g, _h;
return __generator(this, function (_j) {
switch (_j.label) {
case 0:
checkParameters(options, ['token', 'content']);
url = ((_b = (_a = options === null || options === void 0 ? void 0 : options.options) === null || _a === void 0 ? void 0 : _a.qmsg) === null || _b === void 0 ? void 0 : _b.url) || 'https://qmsg.zendee.cn';
msg = getTxt(options.content);
if (options.title) {
msg = "".concat(options.title, "\n").concat(msg);
}
// 移除网址和 IP 以避免 Qmsg 酱被 Tencent 封号
msg = removeUrlAndIp(msg);
param = new URLSearchParams({ msg: msg });
qq = ((_d = (_c = options === null || options === void 0 ? void 0 : options.options) === null || _c === void 0 ? void 0 : _c.qmsg) === null || _d === void 0 ? void 0 : _d.qq) || false;
if (qq) {
param.append('qq', qq);
}
bot = ((_f = (_e = options === null || options === void 0 ? void 0 : options.options) === null || _e === void 0 ? void 0 : _e.qmsg) === null || _f === void 0 ? void 0 : _f.bot) || false;
if (bot) {
param.append('bot', bot);
}
group = ((_h = (_g = options === null || options === void 0 ? void 0 : options.options) === null || _g === void 0 ? void 0 : _g.qmsg) === null || _h === void 0 ? void 0 : _h.group) || false;
return [4 /*yield*/, axios_1.default.post("".concat(url, "/").concat(group ? 'group' : 'send', "/").concat(options.token), param.toString(), {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
})];
case 1:
response = _j.sent();
return [2 /*return*/, response.data];
}
});
});
}
/**
* https://github.com/Tianli0/push-bot-api/
*/
function noticeAtri(options) {
return __awaiter(this, void 0, void 0, function () {
var url, message, param, response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
checkParameters(options, ['token', 'content']);
url = 'http://pushoo.tianli0.top/';
message = getTxt(options.content);
if (options.title) {
message = "".concat(options.title, "\n").concat(message);
}
param = new URLSearchParams({
user_id: options.token,
message: message,
});
return [4 /*yield*/, axios_1.default.post(url, param.toString(), {
headers: { 'X-Requested-By': 'pushoo' },
})];
case 1:
response = _a.sent();
return [2 /*return*/, response.data];
}
});
});
}
/**
* Turbo: https://sct.ftqq.com/
* V3: https://sc3.ft07.com/
*/
function noticeServerChan(options) {
return __awaiter(this, void 0, void 0, function () {
var url, param, response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
checkParameters(options, ['token', 'content']);
if (options.token.startsWith('sctp')) {
url = "https://".concat(options.token.match(/^sctp(\d+)t/)[1], ".push.ft07.com/send");
param = new URLSearchParams({
title: options.title || getTitle(options.content),
desp: options.content,
});
}
else if (options.token.substring(0, 3).toLowerCase() === 'sct') {
url = 'https://sctapi.ftqq.com';
param = new URLSearchParams({
title: options.title || getTitle(options.content),
desp: options.content,
});
}
else {
url = 'https://sc.ftqq.com';
param = new URLSearchParams({
text: options.title || getTitle(options.content),
desp: options.content,
});
}
return [4 /*yield*/, axios_1.default.post("".concat(url, "/").concat(options.token, ".send"), param.toString(), {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
})];
case 1:
response = _a.sent();
return [2 /*return*/, response.data];
}
});
});
}
/**
* https://www.pushplus.plus/
*/
function noticePushPlus(options) {
return __awaiter(this, void 0, void 0, function () {
var ppApiUrl, ppApiParam, response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
checkParameters(options, ['token', 'content']);
ppApiUrl = 'http://www.pushplus.plus/send';
ppApiParam = {
token: options.token,
title: options.title || getTitle(options.content),
content: options.content,
template: 'markdown',
};
return [4 /*yield*/, axios_1.default.post(ppApiUrl, ppApiParam)];
case 1:
response = _a.sent();
return [2 /*return*/, response.data];
}
});
});
}
/**
* https://pushplus.hxtrip.com/
*/
function noticePushPlusHxtrip(options) {
return __awaiter(this, void 0, void 0, function () {
var ppApiUrl, ppApiParam, response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
checkParameters(options, ['token', 'content']);
ppApiUrl = 'http://pushplus.hxtrip.com/send';
ppApiParam = {
token: options.token,
title: options.title || getTitle(options.content),
content: getHtml(options.content),
template: 'html',
};
return [4 /*yield*/, axios_1.default.post(ppApiUrl, ppApiParam)];
case 1:
response = _a.sent();
return [2 /*return*/, response.data];
}
});
});
}
/**
* 文档: https://open.dingtalk.com/document/group/custom-robot-access
* 教程: https://blog.ljcbaby.top/article/Twikoo-DingTalk/
*/
function noticeDingTalk(options) {
return __awaiter(this, void 0, void 0, function () {
var url, msgtype, content, msgBody, response;
var _a, _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
checkParameters(options, ['token', 'content']);
url = 'https://oapi.dingtalk.com/robot/send?access_token=';
if (options.token.substring(0, 4).toLowerCase() === 'http') {
url = options.token;
}
else {
url += options.token;
}
msgtype = ((_b = (_a = options.options) === null || _a === void 0 ? void 0 : _a.dingtalk) === null || _b === void 0 ? void 0 : _b.msgtype) || 'text';
content = msgtype === 'text'
? (options.title ? "".concat(options.title, "\n") : '') + getTxt(options.content)
: options.content;
msgBody = {
msgtype: msgtype,
};
if (msgtype === 'text') {
msgBody[msgtype] = { content: content };
}
else if (msgtype === 'markdown') {
msgBody[msgtype] = { title: options.title || getTitle(options.content), text: content };
}
return [4 /*yield*/, axios_1.default.post(url, msgBody)];
case 1:
response = _c.sent();
return [2 /*return*/, response.data];
}
});
});
}
/**
* 文档: https://developer.work.weixin.qq.com/document/path/90236
* 教程: https://sct.ftqq.com/forward
*/
function noticeWeCom(options) {
return __awaiter(this, void 0, void 0, function () {
var _a, corpid, corpsecret, agentid, _b, touser, accessToken, accessTokenRes, e_1, url, content, param, response;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
checkParameters(options, ['token', 'content']);
_a = options.token.split('#'), corpid = _a[0], corpsecret = _a[1], agentid = _a[2], _b = _a[3], touser = _b === void 0 ? '@all' : _b;
checkParameters({
corpid: corpid,
corpsecret: corpsecret,
agentid: agentid,
}, ['corpid', 'corpsecret', 'agentid']);
_c.label = 1;
case 1:
_c.trys.push([1, 3, , 4]);
return [4 /*yield*/, axios_1.default.get("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=".concat(corpid, "&corpsecret=").concat(corpsecret))];
case 2:
accessTokenRes = _c.sent();
accessToken = accessTokenRes.data.access_token;
return [3 /*break*/, 4];
case 3:
e_1 = _c.sent();
console.error('获取企业微信 access token 失败,请检查 token', e_1);
return [2 /*return*/, {}];
case 4:
url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=".concat(accessToken);
content = getTxt(options.content);
if (options.title) {
content = "".concat(options.title, "\n").concat(content);
}
param = {
touser: touser,
msgtype: 'text',
agentid: agentid,
text: { content: content },
};
return [4 /*yield*/, axios_1.default.post(url, param)];
case 5:
response = _c.sent();
return [2 /*return*/, response.data];
}
});
});
}
/**
* https://github.com/Finb/Bark
*/
function noticeBark(options) {
return __awaiter(this, void 0, void 0, function () {
var url, title, content, params, response;
var _a, _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
checkParameters(options, ['token', 'content']);
url = 'https://api.day.app/';
if (options.token.substring(0, 4).toLowerCase() === 'http') {
url = options.token;
}
else {
url += options.token;
}
if (!url.endsWith('/'))
url += '/';
title = encodeURIComponent(options.title || getTitle(options.content));
content = encodeURIComponent(getTxt(options.content));
params = new URLSearchParams({
url: ((_b = (_a = options === null || options === void 0 ? void 0 : options.options) === null || _a === void 0 ? void 0 : _a.bark) === null || _b === void 0 ? void 0 : _b.url) || '',
});
return [4 /*yield*/, axios_1.default.get("".concat(url).concat(title, "/").concat(content, "/"), { params: params })];
case 1:
response = _c.sent();
return [2 /*return*/, response.data];
}
});
});
}
/**
* 文档: https://docs.go-cqhttp.org/api/
* 教程: https://twikoo.js.org/QQ_API.html
*/
function noticeGoCqhttp(options) {
return __awaiter(this, void 0, void 0, function () {
var url, message, param, response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
checkParameters(options, ['token', 'content']);
url = options.token;
message = getTxt(options.content);
if (options.title) {
message = "".concat(options.title, "\n").concat(message);
}
param = new URLSearchParams({ message: message });
return [4 /*yield*/, axios_1.default.post(url, param.toString())];
case 1:
response = _a.sent();
return [2 /*return*/, response.data];
}
});
});
}
/**
* 文档: https://github.com/botuniverse/onebot-11
* 教程: https://ayakasuki.com/
*/
function noticeNodeOnebot(options) {
return __awaiter(this, void 0, void 0, function () {
var fullUrl, urlObj, baseUrl, actionPath, action, urlParams, accessToken, groupId, userId, params, apiUrl, response, e_2;
var _a, _b, _c, _d, _e, _f;
return __generator(this, function (_g) {
switch (_g.label) {
case 0:
checkParameters(options, ['token', 'content']);
_g.label = 1;
case 1:
_g.trys.push([1, 3, , 4]);
fullUrl = options.token;
urlObj = new URL(fullUrl);
baseUrl = "".concat(urlObj.protocol, "//").concat(urlObj.host);
actionPath = urlObj.pathname.split('/').pop() || '';
action = void 0;
// 自动识别动作类型(群发/私聊)
if (actionPath.includes('group')) {
action = 'send_group_msg';
}
else if (actionPath.includes('private')) {
action = 'send_private_msg';
}
else {
action = actionPath; // 保留原始action
}
urlParams = new URLSearchParams(urlObj.search);
accessToken = urlParams.get('access_token') || '';
groupId = urlParams.get('group_id');
userId = urlParams.get('user_id');
params = {
message: options.title
? "".concat(options.title, "\n").concat(getTxt(options.content))
: getTxt(options.content),
};
// 根据参数类型设置目标
if (groupId) {
params.group_id = Number(groupId);
}
else if (userId) {
params.user_id = Number(userId);
}
else if ((_b = (_a = options === null || options === void 0 ? void 0 : options.options) === null || _a === void 0 ? void 0 : _a.onebot) === null || _b === void 0 ? void 0 : _b.group_id) {
params.group_id = Number(options.options.onebot.group_id);
}
else if ((_d = (_c = options === null || options === void 0 ? void 0 : options.options) === null || _c === void 0 ? void 0 : _c.onebot) === null || _d === void 0 ? void 0 : _d.user_id) {
params.user_id = Number(options.options.onebot.user_id);
}
else {
throw new Error('OneBot 必须提供 group_id 或 user_id');
}
apiUrl = "".concat(baseUrl, "/").concat(actionPath);
return [4 /*yield*/, axios_1.default.post(apiUrl, params, {
timeout: 5000,
headers: __assign({ 'Content-Type': 'application/json' }, (accessToken ? { Authorization: "Bearer ".concat(accessToken) } : {})),
})];
case 2:
response = _g.sent();
// 7. 处理OneBot响应
if (((_e = response.data) === null || _e === void 0 ? void 0 : _e.retcode) !== 0) {
throw new Error("[".concat(response.data.retcode, "] ").concat(response.data.message));
}
return [2 /*return*/, response.data];
case 3:
e_2 = _g.sent();
// 增强错误日志(包含原始URL)
console.error('[ONEBOT] 请求失败:', {
originalUrl: options.token,
error: ((_f = e_2.response) === null || _f === void 0 ? void 0 : _f.data) || e_2.message,
});
throw new Error("OneBot\u63A8\u9001\u5931\u8D25: ".concat(e_2.message));
case 4: return [2 /*return*/];
}
});
});
}
function noticePushdeer(options) {
return __awaiter(this, void 0, void 0, function () {
var url, response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
checkParameters(options, ['token', 'content']);
url = 'https://api2.pushdeer.com/message/push';
return [4 /*yield*/, axios_1.default.post(url, {
pushkey: options.token,
text: options.title || getTitle(options.content),
desp: options.content,
})];
case 1:
response = _a.sent();
return [2 /*return*/, response.data];
}
});
});
}
function noticeIgot(options) {
return __awaiter(this, void 0, void 0, function () {
var url, response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
checkParameters(options, ['token', 'content']);
url = "https://push.hellyw.com/".concat(options.token);
return [4 /*yield*/, axios_1.default.post(url, {
title: options.title || getTitle(options.content),
content: getTxt(options.content),
})];
case 1:
response = _a.sent();
return [2 /*return*/, response.data];
}
});
});
}
/**
* 文档: https://core.telegram.org/method/messages.sendMessage
* 教程: https://core.telegram.org/bots#3-how-do-i-create-a-bot
*/
function noticeTelegram(options) {
return __awaiter(this, void 0, void 0, function () {
var _a, tgToken, chatId, text, response;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
checkParameters(options, ['token', 'content']);
_a = options.token.split('#'), tgToken = _a[0], chatId = _a[1];
checkParameters({
tgToken: tgToken,
chatId: chatId,
}, ['tgToken', 'chatId']);
text = options.content.replace(/([*_])/g, '\\$1');
if (options.title) {
text = "".concat(options.title, "\n\n").concat(text);
}
return [4 /*yield*/, axios_1.default.post("https://api.telegram.org/bot".concat(tgToken, "/sendMessage"), {
text: text,
chat_id: chatId,
parse_mode: 'Markdown',
})];
case 1:
response = _b.sent();
return [2 /*return*/, response.data];
}
});
});
}
/**
* https://www.feishu.cn/hc/zh-CN/articles/360024984973
*/
function noticeFeishu(options) {
return __awaiter(this, void 0, void 0, function () {
var v1, v2, url, params, text, response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
checkParameters(options, ['token', 'content']);
v1 = 'https://open.feishu.cn/open-apis/bot/hook/';
v2 = 'https://open.feishu.cn/open-apis/bot/v2/hook/';
if (options.token.substring(0, 4).toLowerCase() === 'http') {
url = options.token;
}
else {
url = v2 + options.token;
}
if (url.substring(0, v1.length) === v1) {
params = {
title: options.title || getTitle(options.content),
text: getTxt(options.content),
};
}
else {
text = getTxt(options.content);
if (options.title) {
text = "".concat(options.title, "\n").concat(text);
}
params = {
msg_type: 'text',
content: { text: text },
};
}
return [4 /*yield*/, axios_1.default.post(url, params)];
case 1:
response = _a.sent();
return [2 /*return*/, response.data];
}
});
});
}
/**
* https://ifttt.com/maker_webhooks
* http://ift.tt/webhooks_faq
*/
function noticeIfttt(options) {
return __awaiter(this, void 0, void 0, function () {
var _a, token, eventName, url, response;
var _b, _c, _d, _e, _f, _g;
return __generator(this, function (_h) {
switch (_h.label) {
case 0:
checkParameters(options, ['token', 'content']);
_a = options.token.split('#'), token = _a[0], eventName = _a[1];
checkParameters({
token: token,
eventName: eventName,
}, ['token', 'eventName']);
url = "https://maker.ifttt.com/trigger/".concat(eventName, "/with/key/").concat(token);
return [4 /*yield*/, axios_1.default.post(url, {
value1: ((_c = (_b = options.options) === null || _b === void 0 ? void 0 : _b.ifttt) === null || _c === void 0 ? void 0 : _c.value1) || getTxt(options.title),
value2: ((_e = (_d = options.options) === null || _d === void 0 ? void 0 : _d.ifttt) === null || _e === void 0 ? void 0 : _e.value2) || getTxt(options.content),
value3: (_g = (_f = options.options) === null || _f === void 0 ? void 0 : _f.ifttt) === null || _g === void 0 ? void 0 : _g.value3,
}, {
headers: { 'Content-Type': 'application/json' },
})];
case 1:
response = _h.sent();
return [2 /*return*/, response.data];
}
});
});
}
/**
* 文档: https://developer.work.weixin.qq.com/document/path/91770
* 教程: https://developer.work.weixin.qq.com/tutorial/detail/54
*/
function noticeWecombot(options) {
return __awaiter(this, void 0, void 0, function () {
var url, content, response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
checkParameters(options, ['token', 'content']);
url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=".concat(options.token);
content = getTxt(options.content);
return [4 /*yield*/, axios_1.default.post(url, {
msgtype: 'text',
text: {
content: content,
},
}, {
headers: { 'Content-Type': 'application/json' },
})];
case 1:
response = _a.sent();
return [2 /*return*/, response.data];
}
});
});
}
/**
* 文档:https://discord.com/developers/docs/resources/webhook#execute-webhook
*/
function noticeDiscord(options) {
return __awaiter(this, void 0, void 0, function () {
var url, response;
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
checkParameters(options, ['token', 'content']);
url = options.token.startsWith('https://')
? options.token
: "https://discord.com/api/webhooks/".concat(options.token.replace(/#/, '/'));
return [4 /*yield*/, axios_1.default.post(url, {
content: options.content,
username: (_b = (_a = options.options) === null || _a === void 0 ? void 0 : _a.discord) === null || _b === void 0 ? void 0 : _b.userName,
avatar_url: (_d = (_c = options.options) === null || _c === void 0 ? void 0 : _c.discord) === null || _d === void 0 ? void 0 : _d.avatarUrl,
}, {
headers: { 'Content-Type': 'application/json' },
})];
case 1:
response = _e.sent();
return [2 /*return*/, "Delivered successfully, code ".concat(response.status, ".")];
}
});
});
}
/**
* WXPusher 推送
* 教程:https://wxpusher.zjiecode.com/admin/
* 文档: https://wxpusher.zjiecode.com/docs/#/
*/
function noticeWxPusher(options) {
return __awaiter(this, void 0, void 0, function () {
var url, _a, appToken, topicIds, response;
var _b, _c, _d, _e, _f, _g;
return __generator(this, function (_h) {
switch (_h.label) {
case 0:
checkParameters(options, ['token', 'content']);
url = 'http://wxpusher.zjiecode.com/api/send/message';
_a = options.token.split('#'), appToken = _a[0], topicIds = _a[1];
checkParameters({ appToken: appToken, topicIds: topicIds }, ['appToken', 'topicIds']);
return [4 /*yield*/, axios_1.default.post(url, {
appToken: appToken,
content: options.content,
summary: options.title || getTitle(options.content),
contentType: 3,
topicIds: topicIds.split(',').map(function (id) { return Number(id); }),
uids: ((_c = (_b = options === null || options === void 0 ? void 0 : options.options) === null || _b === void 0 ? void 0 : _b.wxpusher) === null || _c === void 0 ? void 0 : _c.uids) || [],
url: ((_e = (_d = options === null || options === void 0 ? void 0 : options.options) === null || _d === void 0 ? void 0 : _d.wxpusher) === null || _e === void 0 ? void 0 : _e.url) || '',
verifyPayload: ((_g = (_f = options === null || options === void 0 ? void 0 : options.options) === null || _f === void 0 ? void 0 : _f.wxpusher) === null || _g === void 0 ? void 0 : _g.verifyPay) || false,
}, {
headers: {
'Content-Type': 'application/json',
},
})];
case 1:
response = _h.sent();
return [2 /*return*/, response.data];
}
});
});
}
/**
* Join 推送
* 文档: https://joaoapps.com/join/api/
*/
function noticeJoin(options) {
return __awaiter(this, void 0, void 0, function () {
var _a, apiKey, deviceId, url, param, response;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
checkParameters(options, ['token', 'content']);
_a = options.token.split('#'), apiKey = _a[0], deviceId = _a[1];
checkParameters({ apiKey: apiKey, deviceId: deviceId }, ['apiKey', 'deviceId']);
url = 'https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush';
param = new URLSearchParams({
apikey: apiKey,
deviceId: deviceId,
title: options.title || getTitle(options.content),
text: options.content,
});
return [4 /*yield*/, axios_1.default.post(url, param.toString(), {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
})];
case 1:
response = _b.sent();
return [2 /*return*/, response.data];
}
});
});
}
function notice(channel, options) {
return __awaiter(this, void 0, void 0, function () {
var data, noticeFn, e_3;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 4, , 5]);
data = void 0;
noticeFn = {
qmsg: noticeQmsg,
serverchan: noticeServerChan,
serverchain: noticeServerChan,
pushplus: noticePushPlus,
pushplushxtrip: noticePushPlusHxtrip,
dingtalk: noticeDingTalk,
wecom: noticeWeCom,
bark: noticeBark,
gocqhttp: noticeGoCqhttp,
onebot: noticeNodeOnebot,
atri: noticeAtri,
pushdeer: noticePushdeer,
igot: noticeIgot,
telegram: noticeTelegram,
feishu: noticeFeishu,
ifttt: noticeIfttt,
wecombot: noticeWecombot,
discord: noticeDiscord,
wxpusher: noticeWxPusher,
join: noticeJoin,
}[channel.toLowerCase()];
if (!noticeFn) return [3 /*break*/, 2];
return [4 /*yield*/, noticeFn(options)];
case 1:
data = _a.sent();
return [3 /*break*/, 3];
case 2: throw new Error("<".concat(channel, "> is not supported"));
case 3:
console.debug("[PUSHOO] Send to <".concat(channel, "> result:"), data);
return [2 /*return*/, data];
case 4:
e_3 = _a.sent();
console.error('[PUSHOO] Got error:', e_3.message);
return [2 /*return*/, { error: e_3 }];
case 5: return [2 /*return*/];
}
});
});
}
exports.default = notice;
//# sourceMappingURL=index.js.map