Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# node-pushover-client
Send push notifications to iOS and Android using [Pushover][site].

Compatible with Pushover 3.0 api, it now can send an attached image.

## Usage
[Register an application with Pushover.net][site-app] to get your application and user tokens.

Expand Down Expand Up @@ -33,6 +35,18 @@ Pushover.send({
});
```

You also can attach an image. Full filepath must be specified.
Pushover's api limits must be followed: "Each message may only include one attachment, and attachments are currently limited to 2,621,440 bytes (2.5 megabytes)."

```js
Pushover.send({
token: 'KzGDORePK8gMaC0QOYAMyEEuzJnyUi',
user: 'uQiRzpo4DXghDmr9QzzfQu27cmVRsG',
message: 'Hello World',
attachment: FILEPATH
});
```

## Command Line Usage
```sh
$ npm -g install node-pushover-client
Expand Down
4 changes: 3 additions & 1 deletion bin/pushover
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ program
.option('-i, --timestamp [timestamp]', 'a unix timestamp', parseInt)
.option('-p, --priority [n]', 'priority (-1 to 2)', parseInt)
.option('-d, --device [id]', 'device to send to', String)
.option('-f, --file [file]', 'file to attach', String)
.parse(process.argv);

new PushoverClient()
Expand All @@ -26,7 +27,8 @@ new PushoverClient()
expires: program.expires,
retry: program.retry,
timestamp: program.timestamp,
priority: program.priority
priority: program.priority,
attachment: program.attachment
})
.then(function (res) {
console.log(`Sent request: ${res.request}`);
Expand Down
14 changes: 13 additions & 1 deletion lib/pushover-client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const fs = require('fs');
const fetch = require('node-fetch');
const FormData = require('form-data');
const snakeCase = require('lodash/snakeCase');
require('babel-polyfill');

const endpoint = 'https://api.pushover.net/1/messages.json';

Expand All @@ -20,7 +22,17 @@ class Pushover {
}

for (let [key, value] of filterOptions(this.defaults, options)) {
form.append(key, value);
// If attachment is specified, create a file stream and include it into the form-data object
if (key === 'attachment') {
var stream = fs.readFileSync(value, options);
form.append(key, stream, {
filename: 'image.jpg',
contentType: stream.contentType,
knownLength: stream.byteLength
});
} else {
form.append(key, value);
}
}

return fetch(endpoint, {
Expand Down
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "node-pushover-client",
"version": "2.1.0",
"description": "Send push notifications to iOS and Android using Pushover.",
"version": "2.1.1",
"description": "Send push notifications to iOS and Android using Pushover. Include image attachment support.",
"main": "index.js",
"dependencies": {
"babel-polyfill": "^6.26.0",
"commander": "^2.9.0",
"form-data": "^2.1.2",
"lodash": "^4.17.2",
Expand All @@ -20,6 +21,12 @@
"url": "git://github.com/dvdln/node-pushover-client.git"
},
"author": "David Lane <[email protected]>",
"contributors": [
{
"name": "Carlos Cordero",
"url": "http://www.carloscordero.com"
}
],
"license": "ISC",
"xo": {
"space": true
Expand Down