Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pushy

Package Overview
Dependencies
Maintainers
0
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pushy

The official Node.js package for sending push notifications with Pushy.

  • 4.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.6K
increased by200.47%
Maintainers
0
Weekly downloads
 
Created
Source

pushy-node

npm version

The official Node.js package for sending push notifications with Pushy.

Pushy is the most reliable push notification gateway, perfect for real-time, mission-critical applications.

Note: If you don't have an existing Node.js project, consider using our Node.js backend API sample project as a starting point to make things easier for you.

Usage

First, install the package using npm:

npm install pushy --save

Then, use the following code to send a push notification to target devices using the Send Notifications API:

var Pushy = require('pushy');

// Plug in your Secret API Key
// Get it from the Pushy Dashboard: https://dashboard.pushy.me/apps
var pushy = new Pushy('SECRET_API_KEY');

// Set push payload data to deliver to device(s)
var data = {
    message: 'Hello World!'
};

// Insert target device token(s), or set to Pub/Sub topic
var to = ['DEVICE_TOKEN'];

// Set optional push notification options (such as iOS notification fields)
var options = {
    notification: {
        badge: 1,
        sound: 'ping.aiff',
        body: 'Hello World \u270c'
    },
};

// Send push notification using the Send Notifications API
pushy.sendPushNotification(data, to, options, function (err, result) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }
    
    // Log success
    console.log('Push sent successfully! (ID: ' + result.id + ')');
});

Note: Make sure to replace SECRET_API_KEY with your app's Secret API Key, available in the Pushy Dashboard (Click your app -> API Authentication tab).


The library also supports using promise syntax instead of callbacks for all API methods:

pushy.sendPushNotification(data, tokens, options)
    .then(function (result) {
        // Log success
        console.log('Push sent successfully! (ID: ' + result.id + ')');
    }).catch(function (err) {
        // Log errors to console
        return console.error(err);
    });

Push APIs

pushy.sendPushNotification(data, to, options)

Instantly send push notifications to your users using the Send Notifications API (see example above):

pushy.sendPushNotification(data, to, options, function (err, result) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }
    
    // Log success
    console.log('Push sent successfully! (ID: ' + result.id + ')');
});

pushy.getNotificationStatus(pushId)

Check the delivery status of your push notifications using the Notification Status API:

pushy.getNotificationStatus('PUSH_ID', function (err, status) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }

    // Log notification status
    console.log('Notification Status: ', JSON.stringify(status, null, 2));
});

pushy.deletePushNotification(pushId)

Permanently delete a pending notification using the Notification Deletion API:

pushy.deletePushNotification('PUSH_ID', function (err) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }

    // Log success
    console.log('Pending notification deleted successfully');
});

Device APIs

pushy.getDeviceInfo(deviceToken)

Fetch device info, presence, undelivered notifications, and more by device token using the Device Info API:

pushy.getDeviceInfo('DEVICE_TOKEN', function (err, deviceInfo) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }

    // Log device info
    console.log('Device Info: ', JSON.stringify(deviceInfo, null, 2));
});

pushy.getDevicePresence(deviceTokens)

Check the presence and connectivity status of multiple devices using the Device Presence API:

pushy.getDevicePresence(['DEVICE_TOKEN', 'DEVICE_TOKEN_2'], function (err, devicePresence) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }

    // Log device presence array
    console.log('Device Presence: ', JSON.stringify(devicePresence, null, 2));
});

Pub/Sub APIs

pushy.getTopics()

Retrieve a list of your app's topics and subscribers count using the Pub/Sub Topics API:

pushy.getTopics(function (err, topics) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }

    // Log subscribed topics
    console.log('Subscribed topics: \n' + JSON.stringify(topics, null, 2));
});

pushy.getSubscribers(topic)

Retrieve a list of devices subscribed to a certain topic using the Pub/Sub Subscribers API:

pushy.getSubscribers('news', function (err, subscribers) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }

    // Log subscribed devices
    console.log('Devices subscribed to topic: \n' + JSON.stringify(subscribers, null, 2));
});

pushy.subscribe(topics, deviceToken)

Subscribe a device to one or more topics using the Pub/Sub Subscribe API:

pushy.subscribe(['news', 'weather'], 'DEVICE_TOKEN', function (err) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }

    // Log success
    console.log('Subscribed device to topic(s) successfully');
});

pushy.unsubscribe(topics, deviceToken)

Unsubscribe a device from one or more topics using the Pub/Sub Unsubscribe API

pushy.unsubscribe(['news', 'weather'], 'DEVICE_TOKEN', function (err) {
    // Log errors to console
    if (err) {
        return console.error(err);
    }

    // Log success
    console.log('Unsubscribed device from topic(s) successfully');
});

License

Apache 2.0

FAQs

Package last updated on 07 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc