npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

parse-to-anh

v1.0.2

Published

migrates parse users to Azure Notification Hubs

Downloads

9

Readme

parse-to-anh

Node.js module and tool to migrate android and ios users from parse to Azure Notification Hubs. The script updates the _Installation collection with a new property anhRegistrationId that can later be used to send puah notifications for the user.

Sending a notification to a user is done by sending a notification to a tag of the user's anhRegistrationId. Example below.

In addition, you can provide a handler function that will get the RegistrationId and run your own logic. For example, if you wish to save this registrationId in another collection, or provision it against an addition API.

First thing first

  • First you'll need to export Parse db to your own mongo db instance. Deatils here
  • Create an Azure Notification Hub as explained here

Usage- As a Tool

npm install parse-to-anh -g

Create a configuration file: config.json:

{
  "mongoUrl": "yourMongoUrl",
  "hubName": "yourAzureHubName",
  "hubConnection": "yourAzureHubConnectionString",
  "tags": [],
  "reRegister": true,
  "batchSize": 100,
  "limit": 0
}

options

  • mongoUrl- The Url for your mongo db that was migrated from parse

  • hubName- The Azure Notification Hub name

  • hubConnection- The Azure Notification Hub connection string

  • tags- Default list of tags that will be added to the user

  • reRegister- [Optional, default false] ReRegister users that were already registered. This can be used if for some reason you run the script again on a db that was only partially processed.

  • batchSize- [Optional] The size of the batch used by mongo client

  • limit- [Optional] Use that to limit the number of items to process. Can be used to test with a small amount of items, before processing the whole collection.

  • registrationHandler- [Optional]- a callback function that gets an _Installation document containing the new anhRegistrationId field. This handler will be called for each successfull user registration. This is the place for you to add your own custom code to handle the registrationId.

Executing

run:

parse-to-anh config.json

Grab a coffee and relax...

Usage- As a module

Check the sample file for a reference

var migrator = require('parse-to-anh');
var config = {
 "mongoUrl": "yourMongoUrl",
  "hubName": "yourAzureHubName",
  "hubConnection": "yourAzureHubConnectionString",
  "tags": [],
  "reRegister": true,
  "batchSize": 100,
  "limit": 0,
  "registrationHandler": myHandler
};


function myHandler(installation, cb) {
  // TODO: custom code to use installation.anhRegistrationId 
  // and the rest of the properties of the installation document
  return cb();
}

console.log('starting registering to Azure Notification Hub...');

migrator.start(config, function (err) {
  if (err) return console.error('error occurred:', err);
  console.log('migration completed successfully');
});

Sending a notification to a user from your node.js server

Use the anhRegistrationId to send a notification to the user. The below example assumes an ios user, using apns to send the notification:

var azure = require('azure');
var hubService = azure.createNotificationHubService(hubName, hubConn);

var payload = {
  alert: 'Hello from Azure Notification Hubs!'
};

var tags = [anhRegistrationId];

hubService.apns.send(tags, payload, function (err) {
    if (err) return console.error('error sending notification', err);
    console.log('Success: notification sent');
});

Notes

  • Currently supports ios and android
  • Failed users will not stop the process. An error log will be sent to the console.

License

MIT