Giter Site home page Giter Site logo

chump's Introduction

Chump

Chump - Pushover.net client for Node.js

NPM Version Build Status Dependency Status

Chump is a client for the popular Pushover.net real-time notification service.

Use Chump to send Android, iOS, watchOS, and desktop notifications.

Chump makes full use of Pushover.net's API.

Installation

Chump was written for Node.js 4+.

npm install --save chump

Basic Usage

It is easy to send messages via Pushover.net using Chump.

Sending Messages

let chump = require('chump');

// Instantiate client with your api token
let client = new chump.Client('yourApiToken');

// Instantiate a destination user
let user = new chump.User('userIdHere', 'optionalUserDeviceHere');

// Instantiate a message
let message = new chump.Message({
  title:      'Example title',
  message:    'Example message',
  enableHtml: false,
  user:       user,
  url:        'http://example.org',
  urlTitle:   'Example.org',
  priority:   new chump.Priority('low'),
  sound:      new chump.Sound('magic')
});

// Send the message, handle result within a Promise
client.sendMessage(message)
  .then(() => {
	  console.log('Message sent.');
  })
  .catch(error => {
  	console.log('An error occurred.');
    console.log(error.stack);
  });

All client methods that send a command return a Promise.

Sending Messages With Emergency Priority

An emergency priority can be attached to a message. This requires that the message is acknowledged by the user, and can renotify the user on failure to acknowledge. Pushover.net can also call an optional callback URL after the user acknowledges the message. A message receipt is returned to the resolved Promise on successful delivery of emergency priority messages.

let priority = new chump.Priority('emergency', {
  retry:    300,  // Optional: Notify user every 5 minutes (300 seconds) until acknowledged
  expire:   3600, // Optional: Expire the message in 1 hour (3600 seconds)
  callback: 'http://example.org' // Optional: Callback URL
});

let message = new chump.Message({
  title:    'Example emergency',
  message:  'Super important message',
  user:     user,
  priority: priority
});

client.sendMessage(message)
  .then(receipt => {
    console.log(`Message sent. Receipt is ${receipt}`);
  });

Advanced Usage

Chump supports the entire Pushover.net API. The client offers convenience methods that correspond to each Pushover.net endpoint.

As documented earlier, all client methods that send a command return a Promise.

.verifyUser

Verify that a user (and optionally, the user's device) exists on Pushover.net

let user = new chump.user('userIdHere', 'optionalUserDeviceHere');

// Verify the user exists
client.verifyUser(user)
  .then(() => {
    console.log('User exists.');
  })
  .catch(error => {
    console.log('User may not exist.');
    console.log(error.stack);
  });

.getReceipt

Additional receipt information can be retrieved from Pushover.net. Receipts are only returned for messages sent with an emergency priority.

client.getReceipt(receipt)
  .then(receipt => {
    console.log(`Receipt: ${receipt.id}`);
    console.log(`Acknowledged: ${receipt.isAcknowledged}`);
    console.log(`Acknowledged by: ${receipt.acknowledgedBy}`);
    console.log(`Last delivered at: ${receipt.lastDeliveredAt}`);
    console.log(`Is expired: ${receipt.isExpired}`);
    console.log(`Expires at: ${receipt.expiresAt}`);
    console.log(`Has called back: ${receipt.hasCalledBack}`);
    console.log(`Called back at: ${receipt.calledBackAt}`);
  });

.cancelEmergency

A message with an emergency priority can be cancelled.

client.cancelEmergency(receipt);

.getGroupDetails

Pushover.net supports managing users within groups. Creating groups can only be done through Pushover.net's website. Assuming you know the group Id, you can use Chump to retrieve information for the group from Pushover.net.

let group = new chump.Group(groupId);

client.getGroupDetails(group)
  .then(group => {
    console.log(`Group name: ${group.name}`);

    for (let user of group.users) {
      console.log(`User: ${user.id}, ${user.device}`);
    }
  });

.addUserToGroup

Add a user to a known group.

let user  = new chump.User(userId);
let group = new chump.Group(groupId);

client.addUserToGroup(user, group);

.removeUserFromGroup

Remove a user from a known group.

let user  = new chump.User(userId);
let group = new chump.Group(groupId);

client.removeUserFromGroup(user, group);

.enableGroupUser

Enable a user in a known group.

let user  = new chump.User(userId);
let group = new chump.Group(groupId);

client.enableGroupUser(user, group);

.disableGroupUser

Disable a user in a known group.

let user  = new chump.User(userId);
let group = new chump.Group(groupId);

client.disableGroupUser(user, group);

.renameGroup

Rename a known group.

let group = new chump.Group(groupId);

client.renameGroup(group, 'New name');

Track Application Limitations

Pushover.net limits the number of messages emitted from its service. Chump keeps track of these limitations after each successful message sent. You can access app limitations from the following client properties:

// Maximum number of messages that can be sent
let appLimit = client.appLimit;

// Number of messages remaining in time period
let appRemaining = client.appRemaining;

// Date when app remaining resets to app limit
let appReset = client.appReset;

Examples

Want to see more examples? View them in the examples directory included in this repository.

Logo

Chump's initial logo was designed by scorpion6 on Fiverr. Font used is Lato Bold.

License

This software is licensed under the MIT License. View the license.

Copyright © 2015 Michael K. Squires

chump's People

Contributors

sqmk avatar xapphire13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

chump's Issues

Pushover API v.3.0

Hi,

thanks for this great Pushover Node implementation.

It would be great if chump could be updated to the Pushover API 3.0 functions.

For example support for attachments.

Thx and happy coding
Nez

SyntaxError: Unexpected token <

Since the response from pushover is this one:

<!DOCTYPE html>
<html>
<head>
  <title>Pushover: Simple Mobile Notifications</title>
  <link rel="shortcut icon" href="https://pushover.net/favicon.ico" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="https://pushover.net/assets/application.css" media="all" rel="stylesheet" type="text/css" />
  <script src="https://pushover.net/assets/application.js" type="text/javascript"></script>
</head>
<body>
  <div id="whitey" class="">
    <div class="navbar navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <a class="brand" href="https://pushover.net/" style="width: 83px; height: 18px;">
            <img alt="Pushover" height="18"
                src="https://pushover.net/assets/writing-header.png"
                style="margin-bottom: -1px;" width="83" />
          </a>
        </div>
      </div>
    </div>

    <div class="container" style="min-height: 400px;">
  <div class="row">
    <div class="span12">
      <h2>Resource Not Found (or Incorrect Method)</h2>

      <p>
      The page or resource you requested could not be found.
      </p>
      <p>
      If you are attempting an <a href="https://pushover.net/api">API</a> call,
      verify the URL and the HTTP method (e.g., retry as a POST request instead
      of GET).
      </p>
      <p>
      Please try navigating through our <a
      href="https://pushover.net/">homepage</a> or view our <a
      href="https://pushover.net/api">API documentation</a>.
      </p>
    </div>
  </div>
</div>

  </div>

  <div class="dark_footer">
    <div class="container" style="padding: 2em;">

      <div class="row">
        <div class="span6" id="trademark">
          Pushover is a trademark and product of
          <a href="http://superblock.net/">Superblock, LLC</a>.
        </div>
        <div class="span6" id="copyright">
          Copyright &copy; 2012-2014 Superblock, LLC.  All rights reserved.
        </div>
      </div>

    </div>
  </div>
</body>
</html>

This line https://github.com/sqmk/chump/blob/master/lib/Transport.js#L59 is not catching parse error

Or maybe I'm missing something. I'm using same example as describe in the README file and my credentials works

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.