working initial commit
commit
b14f45b080
|
@ -0,0 +1,44 @@
|
||||||
|
![Pushsafer](https://www.pushsafer.com/de/assets/logos/logo.png)
|
||||||
|
|
||||||
|
Send [pushsafer.com](https://www.pushsafer.com) notifications from Node.JS
|
||||||
|
|
||||||
|
Pushsafer make it easy and safe to get push-notifications in real time on your
|
||||||
|
- Android device
|
||||||
|
- iOS device (incl. iPhone, iPad, iPod Touch)
|
||||||
|
- Windows Phone & Desktop
|
||||||
|
- Browser (Chrome & Firefox)
|
||||||
|
|
||||||
|
[API description](https://www.pushsafer.com/en/pushapi)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### Install Plugin
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Pushsafer API values
|
||||||
|
|
||||||
|
Any API parameters, as found on https://www.pushsafer.com/en/pushapi, can be passed in the object. Here's an example with many different parameters.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var msg = {
|
||||||
|
m: 'This is a Node.js test message', // Message (required)
|
||||||
|
t: "Node.js Test", // Title (optional)
|
||||||
|
s: '8', // Sound (value 0-60) (optional)
|
||||||
|
v: '2', // Vibration (empty or value 1-3) (optional)
|
||||||
|
i: '5', // Icon (value 1-177) (optional)
|
||||||
|
c: '#FF0000', // Icon color hexadecimal color code (optional)
|
||||||
|
d: '221', // Device or Device group id (optional)
|
||||||
|
u: 'https://www.pushsafer.com', // an URL (optional)
|
||||||
|
ut: 'Pushsafer.com', // URLs title (optional)
|
||||||
|
l: '10', // Time to Live (optional: 0-43200 minutes)
|
||||||
|
pr: '2', // Priority (optional: -2, -1, 0, 1, 2)
|
||||||
|
re: '60', // Retry (optional: 60-10800 seconds)
|
||||||
|
ex: '60', // Expire (optional: 60-10800 seconds)
|
||||||
|
a: '1', // Answer
|
||||||
|
p: '', // Image converted to > Data URL with Base64-encoded string (optional)
|
||||||
|
p2: '', // Image 2 converted to > Data URL with Base64-encoded string (optional)
|
||||||
|
p3: '' // Image 3 converted to > Data URL with Base64-encoded string (optional)
|
||||||
|
};
|
||||||
|
```
|
||||||
|
# Usage
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"name": "@uci-utils/notify-pushsafer-plugin",
|
||||||
|
"version": "0.1.2",
|
||||||
|
"description": "pushsafer uci notifity plugin",
|
||||||
|
"main": "pushsafer.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"notification",
|
||||||
|
"pushsafter"
|
||||||
|
],
|
||||||
|
"author": "codecoots",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"got": "^11.5.1"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
|
||||||
|
import got from 'got'
|
||||||
|
|
||||||
|
const DEFAULT = {
|
||||||
|
m: 'This is the Default Message', // message
|
||||||
|
t: '', // title
|
||||||
|
s: 5, // sound (value 0-28)
|
||||||
|
v: 2, // vibration (empty or value 1-3)
|
||||||
|
i: 5, // icon (value 1-98)
|
||||||
|
c: '#FF0000', // icon color (optional)
|
||||||
|
l: 0, // Time to Live in minutes
|
||||||
|
pr: 2, // Priority (optional: -2, -1, 0, 1, 2)
|
||||||
|
re: 60, // Retry (optional: 60-10800 seconds)
|
||||||
|
ex: 60, // Expire (optional: 60-10800 seconds)
|
||||||
|
a: 0, // Answer
|
||||||
|
p2: '', // Image 2 converted to > Data URL with Base64-encoded string
|
||||||
|
p3: '' // Image 3 converted to > Data URL with Base64-encoded string
|
||||||
|
}
|
||||||
|
|
||||||
|
class Pushsafer {
|
||||||
|
constructor(opts) {
|
||||||
|
this._req = Object.assign({},DEFAULT,opts)
|
||||||
|
this.url = opts.url || 'https://www.pushsafer.com/api'
|
||||||
|
this.key = opts.k
|
||||||
|
this.device = opts.d
|
||||||
|
}
|
||||||
|
|
||||||
|
async send (msg, opts={}) {
|
||||||
|
Object.assign(this._req,opts)
|
||||||
|
this._req.m = typeof msg === 'string' ? msg : msg.msg || msg.message || msg.subject
|
||||||
|
let s = new URLSearchParams (Object.entries(this._req))
|
||||||
|
try {
|
||||||
|
const {body} = await got(this.url,{searchParams:s})
|
||||||
|
return JSON.parse(body)
|
||||||
|
} catch (err) {
|
||||||
|
return {error:err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setOpts (opts) {
|
||||||
|
// missing opts and they are reset to defaults
|
||||||
|
if (!opts) this._req = Object.assign({},DEFAULT,{k:this.key, d:this.device})
|
||||||
|
Object.assign(this._req,opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Pushsafer
|
||||||
|
export { Pushsafer as Service }
|
Loading…
Reference in New Issue