Pushover notifications for node.js (JavaScript,NodeJS)
  • JavaScript 100%
Find a file
2024-05-29 13:36:44 -06:00
img add local header 2017-05-31 07:02:23 -06:00
lib add a fix for pushover returning html 2020-01-30 16:17:15 -07:00
test add a fix for pushover returning html 2020-01-30 16:17:15 -07:00
.gitignore Update .gitignore - ignore tinyproxy.log 2024-05-29 13:55:08 -05:00
.travis.yml . 2020-01-30 16:36:58 -07:00
index.js Convert to using "standard" js 2018-01-15 10:28:23 -07:00
LICENSE added license 2012-12-02 07:24:38 -07:00
package.json bump to 1.2.3 2024-05-29 13:36:44 -06:00
README.md put creation of Push object in callback to avoid async issues 2018-10-22 16:22:29 -06:00

Pushover

Send pushover.net notifications from Node.JS

Build Status Coverity Scan Build Status

NPM

Usage

Install

npm install pushover-notifications

Pushover API values

Any API parameters, as found on https://pushover.net/api, can be passed in the object. For example, retry and expire can be added to the object being passed to .send! Here's an example with many different parameters.

var msg = {
  message: "This is a message",
  title: "Well - this is fantastic",
  sound: 'magic',
  device: 'test_device',
  priority: 2,
  url: "http://pushover.net",
  url_title: "Pushover Website"
}

Examples

Sending a message


var Push = require( 'pushover-notifications' )

var p = new Push( {
  user: process.env['PUSHOVER_USER'],
  token: process.env['PUSHOVER_TOKEN'],
  // httpOptions: {
  //   proxy: process.env['http_proxy'],
  //},
  // onerror: function(error) {},
  // update_sounds: true // update the list of sounds every day - will
  // prevent app from exiting.
})

var msg = {
  // These values correspond to the parameters detailed on https://pushover.net/api
  // 'message' is required. All other values are optional.
  message: 'omg node test',	// required
  title: "Well - this is fantastic",
  sound: 'magic',
  device: 'devicename',
  priority: 1
}

p.send( msg, function( err, result ) {
  if ( err ) {
    throw err
  }

  console.log( result )
})

Sending a message with an attachment (blocking)


var Push = require( 'pushover-notifications' )

var p = new Push( {
  user: process.env['PUSHOVER_USER'],
  token: process.env['PUSHOVER_TOKEN'],
  // httpOptions: {
  //   proxy: process.env['http_proxy'],
  //},
  // onerror: function(error) {},
  // update_sounds: true // update the list of sounds every day - will
  // prevent app from exiting.
})

var msg = {
  // These values correspond to the parameters detailed on https://pushover.net/api
  // 'message' is required. All other values are optional.
  message: 'omg node test',	// required
  title: "Well - this is fantastic",
  sound: 'magic',
  device: 'devicename',
  priority: 1,
  file: '/tmp/fantastic.png' // this will read using fs.readFileSync()!
}

p.send( msg, function( err, result ) {
  if ( err ) {
    throw err
  }

  console.log( result )
})

Sending a message with an attachment (non-blocking)


var Push = require( 'pushover-notifications' )
var fs = require( 'fs' )

fs.readFile('/tmp/fantastic.png', function(err, data) {
  var p = new Push( {
    user: process.env['PUSHOVER_USER'],
    token: process.env['PUSHOVER_TOKEN'],
    // httpOptions: {
    //   proxy: process.env['http_proxy'],
    //},
    // onerror: function(error) {},
    // update_sounds: true // update the list of sounds every day - will
    // prevent app from exiting.
  })

  var msg = {
    // These values correspond to the parameters detailed on https://pushover.net/api
    // 'message' is required. All other values are optional.
    message: 'omg node test',	// required
    title: "Well - this is fantastic",
    sound: 'magic',
    device: 'devicename',
    priority: 1,
    file: { name: 'fantastic.png', data: data }
  }
  
  p.send( msg, function( err, result ) {
    if ( err ) {
      throw err
    }
  
    console.log( result )
  })
})

Sending a message to multiple users


var users = [
  'token1',
  'token2',
  'token3'
]

var msg = {
  message: 'omg node test',
  title: "Well - this is fantastic",
  sound: 'magic' // optional
  priority: 1 // optional,
  file: '/tmp/fancy_image.png' // optional
  // see test/test_img.js for more examples of attaching images
}

for ( var i = 0, l = users.length; i < l; i++ ) {
  msg.user = users[i]
  // token can be overwritten as well.

  p.send( msg, function( err, result ) {
    if ( err ) {
      throw err
    }

    console.log( result )
  })
}