Skip to content

Commit

Permalink
添加NowPush, iGot支持
Browse files Browse the repository at this point in the history
  • Loading branch information
HCLonely committed May 10, 2022
1 parent 15fd877 commit aedf5de
Show file tree
Hide file tree
Showing 8 changed files with 482 additions and 1 deletion.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
- [企业微信群机器人](https://open.work.weixin.qq.com/api/doc/90000/90136/91770)
- [息知](https://xz.qqoq.net/#/index)
- [WxPusher](https://wxpusher.zjiecode.com/docs/)
- [NowPush](https://www.nowpush.app/index.html)
- [iGot](http://hellyw.com/)

## 安装

Expand Down Expand Up @@ -168,6 +170,22 @@ const { PushApi } = require('all-pusher-api'); // 多平台同时推送
user_id: '******'
}
}
},
{
name: 'NowPush',
config: {
key: {
token: '******'
}
}
},
{
name: 'IGot',
config: {
key: {
token: '******'
}
}
}
])
.send({ message: '测试文本' })).map((e) => (e.result.status >= 200 && e.result.status < 300) ? `${e.name} 测试成功` : e));
Expand Down Expand Up @@ -454,6 +472,7 @@ const results: Array<{
- QQ(go-cqhttp): 'text', 'other'
- Discord: 'text', 'other'
- 飞书: 'text', 'other'
- NowPush: 'text', 'other'
- Server酱Turbo: 'text', 'markdown'
- 息知: 'text', 'markdown'
- PushDeer: 'text', 'markdown', 'other'
Expand Down
115 changes: 115 additions & 0 deletions dist/IGot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
'use strict';

var _defineProperty = require("@babel/runtime/helpers/defineProperty");

Object.defineProperty(exports, '__esModule', {
value: true
});

var axios = require('axios');

var tool = require('./tool');

function _interopDefaultLegacy(e) {
return e && typeof e === 'object' && 'default' in e ? e : {
'default': e
};
}

var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);

class IGot {
constructor({
token,
key,
proxy
}) {
_defineProperty(this, "_KEY", void 0);

_defineProperty(this, "baseURL", 'https://push.hellyw.com/');

_defineProperty(this, "httpsAgent", void 0);

if (!token && !(key !== null && key !== void 0 && key.token)) {
throw new Error('Missing Parameter: token');
} // @ts-ignore


this._KEY = token || key.token;

if (proxy) {
this.httpsAgent = tool.proxy2httpsAgent(proxy);
}
}

async send(sendOptions) {
if (!sendOptions.message && !sendOptions.customOptions) {
return {
status: 0,
statusText: 'Missing Parameter: message',
extraMessage: null
};
}

let iGotOptions;

if (sendOptions.customOptions) {
iGotOptions = sendOptions.customOptions;
} else {
iGotOptions = {
title: sendOptions.title || sendOptions.message.split('\n')[0].trim().slice(0, 10),
content: sendOptions.message
};
}

if (sendOptions.extraOptions) {
iGotOptions = { ...iGotOptions,
...sendOptions.extraOptions
};
}

const axiosOptions = {
url: `${this.baseURL}${this._KEY}`,
method: 'POST',
headers: {
'Content-type': 'application/json'
},
data: iGotOptions
};

if (this.httpsAgent) {
axiosOptions.httpsAgent = this.httpsAgent;
}

return axios__default["default"](axiosOptions).then(response => {
if (response.data) {
if (response.data.ret === 0) {
return {
status: 200,
statusText: 'Success',
extraMessage: response
};
}

return {
status: 100,
statusText: 'Error',
extraMessage: response
};
}

return {
status: 101,
statusText: 'No Response Data',
extraMessage: response
};
}).catch(error => ({
status: 102,
statusText: 'Request Error',
extraMessage: error
}));
}

}

exports.IGot = IGot;
118 changes: 118 additions & 0 deletions dist/NowPush.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
'use strict';

var _defineProperty = require("@babel/runtime/helpers/defineProperty");

Object.defineProperty(exports, '__esModule', {
value: true
});

var axios = require('axios');

var tool = require('./tool');

function _interopDefaultLegacy(e) {
return e && typeof e === 'object' && 'default' in e ? e : {
'default': e
};
}

var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);

class NowPush {
constructor({
token,
key,
proxy
}) {
_defineProperty(this, "_KEY", void 0);

_defineProperty(this, "baseURL", 'https://www.api.nowpush.app/v3/sendMessage');

_defineProperty(this, "httpsAgent", void 0);

if (!token && !(key !== null && key !== void 0 && key.token)) {
throw new Error('Missing Parameter: token');
} // @ts-ignore


this._KEY = token || key.token;

if (proxy) {
this.httpsAgent = tool.proxy2httpsAgent(proxy);
}
}

async send(sendOptions) {
if (!sendOptions.message && !sendOptions.customOptions) {
return {
status: 0,
statusText: 'Missing Parameter: message',
extraMessage: null
};
}

let nowPushOptions;

if (sendOptions.customOptions) {
nowPushOptions = sendOptions.customOptions;
} else {
nowPushOptions = {
message_type: 'nowpush_note',
note: sendOptions.message
};
}

nowPushOptions.device_type = 'api';

if (sendOptions.extraOptions) {
nowPushOptions = { ...nowPushOptions,
...sendOptions.extraOptions
};
}

const axiosOptions = {
url: this.baseURL,
method: 'POST',
headers: {
'Content-type': 'application/x-www-form-urlencoded',
Authorization: `Bearer ${this._KEY}`
},
data: tool.queryStringify(nowPushOptions)
};

if (this.httpsAgent) {
axiosOptions.httpsAgent = this.httpsAgent;
}

return axios__default["default"](axiosOptions).then(response => {
if (response.data) {
if (response.data.isError === false) {
return {
status: 200,
statusText: 'Success',
extraMessage: response
};
}

return {
status: 100,
statusText: 'Error',
extraMessage: response
};
}

return {
status: 101,
statusText: 'No Response Data',
extraMessage: response
};
}).catch(error => ({
status: 102,
statusText: 'Request Error',
extraMessage: error
}));
}

}

exports.NowPush = NowPush;
17 changes: 17 additions & 0 deletions dist/types/IGot.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { AxiosRequestConfig } from 'axios';
import { proxy, result, sendOptions } from './tool';
interface IGotConfig {
key?: {
token: string;
};
token?: string;
proxy?: proxy;
}
declare class IGot {
protected _KEY: string;
readonly baseURL = "https://push.hellyw.com/";
httpsAgent?: AxiosRequestConfig['httpsAgent'];
constructor({ token, key, proxy }: IGotConfig);
send(sendOptions: sendOptions): Promise<result>;
}
export { IGot };
17 changes: 17 additions & 0 deletions dist/types/NowPush.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { AxiosRequestConfig } from 'axios';
import { proxy, result, sendOptions } from './tool';
interface NowPushConfig {
key?: {
token: string;
};
token?: string;
proxy?: proxy;
}
declare class NowPush {
protected _KEY: string;
readonly baseURL = "https://www.api.nowpush.app/v3/sendMessage";
httpsAgent?: AxiosRequestConfig['httpsAgent'];
constructor({ token, key, proxy }: NowPushConfig);
send(sendOptions: sendOptions): Promise<result>;
}
export { NowPush };
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "all-pusher-api",
"version": "1.0.2",
"version": "1.0.3",
"description": "统一化推送服务API.",
"main": "dist/index.js",
"scripts": {
Expand Down
Loading

0 comments on commit aedf5de

Please sign in to comment.