Skip to content

Commit 24b47bc

Browse files
committed
Initial commit
0 parents  commit 24b47bc

File tree

5 files changed

+98
-0
lines changed

5 files changed

+98
-0
lines changed

.gitignore

Whitespace-only changes.

.npmignore

Whitespace-only changes.

index.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
2+
3+
const request = require('request-promise-native');
4+
5+
function sendRequest(namespace, text, level='INFO', options={}) {
6+
if (options.chat == undefined) {
7+
console.error('PushNotice: chat object has to be provided');
8+
return;
9+
}
10+
if (options.chat && options.chat.id == undefined) {
11+
console.error('PushNotice: chat id has to be provided');
12+
return;
13+
}
14+
if (options.chat && options.chat.secret == undefined) {
15+
console.error('PushNotice: chat secret has to be provided');
16+
return;
17+
}
18+
if (namespace == undefined) {
19+
console.error('PushNotice: namespace has to be provided');
20+
return;
21+
}
22+
if (text == undefined) {
23+
console.error('PushNotice: text has to be provided');
24+
return;
25+
}
26+
if (level == undefined) {
27+
console.error('PushNotice: level has to be provided');
28+
return;
29+
}
30+
if (options.url == undefined) options.url = 'https://pushnotice.chat/api/vi/chatnotice';
31+
if (options.debug == undefined) options.debug = false;
32+
let requestOptions = {
33+
method: 'POST',
34+
uri: options.url,
35+
body: {
36+
chatId: options.chat.id,
37+
chatSecret: options.chat.secret,
38+
namespace: namespace,
39+
level: level,
40+
text: text,
41+
},
42+
json: true,
43+
headers: {
44+
'content-type': 'application/json',
45+
}
46+
};
47+
request(requestOptions).then((res) => {
48+
if (options.debug) console.log("Successfully sent Notification to PushNotice API");
49+
}).catch((err) => {
50+
if (options.debug) console.error("Error sending Notification to PushNotice API");
51+
});
52+
}
53+
54+
module.exports = (namespace, options={}) => {
55+
return (text, level='INFO') => {
56+
sendRequest(namespace, text, level, options);
57+
}
58+
}

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"version": "0.1.0",
3+
"name": "pushnotice.chat",
4+
"description": "Application Notifications sent to Telegram. Linking pushnotice.chat into your project.",
5+
"keywords": ["telegram", "notifications", "util", "debug", "logging"],
6+
"license": "ISC",
7+
8+
"main": "index.js",
9+
"scripts": {
10+
"test": "echo \"Error: no test specified\" && exit 1"
11+
},
12+
"files": [
13+
"index.js"
14+
],
15+
16+
"author": "Chris Spiegl <chris@spiegl.io>",
17+
18+
"repository": {
19+
"type": "git",
20+
"url": "https://github.com/spieglio/pushnotice-node-api-client.git"
21+
},
22+
"bugs": {
23+
"url": "https://github.com/spieglio/pushnotice-node-api-client/issues"
24+
},
25+
"homepage": "https://pushnotice.chat",
26+
27+
"dependencies": {
28+
"request": "^2.83.0",
29+
"request-promise-native": "^1.0.5"
30+
}
31+
}

readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# PushNotice API Client for Node.js
2+
3+
[@PushNoticeBot](https://t.me/PushNoticeBot) is a bot that will help you send notifications directly to a chat (or group). Easy to setup and integrate.
4+
5+
* Bot: [@PushNoticeBot](https://t.me/PushNoticeBot)
6+
* Website: [PushNotice.chat](https://pushnotice.chat)
7+
* Developer: Chris ([Telegram](https://t.me/spieglio), [Twitter](https://twitter.com/spieglio), [Email](mailto:hello@pushnotice.chat))
8+
9+
This is work in progress and will be developed further.

0 commit comments

Comments
 (0)