Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Service Bus Notification Hubs

glennblock edited this page Feb 13, 2013 · 31 revisions

This feature will enable developers to send push notifications from their node.js applications simultaneously to hundreds of thousands or mobile clients across IOS and Windows 8. Each message has a tag associated with it. When clients subscribe, they can choose which tags are of interest. As messages are published, Notification Hubs will ensure messages go only to those clients who subscribed to that.

Types of messages

  • Template: Template messages are a collection of key/value pairs which are agnostic to a specific push mechanism and which notification hubs will send to all platforms.
  • Targeted: Targeted messages target a specific platform / push mechanism.

Windows notification template references

Sample snippets

Below is a quick snippet for how to use the new api. In the snippet below a new Notification Hub is created, configuring credentials for both apns and wns. Two messages are then sent with different tags to both IOS and Windows 8 devices.

var azure = require('azure');

var credentials = new azure.PushCredentials();
credentials.wns = new azure.WnsCredential(packageSid, clientSecret),
credentials.apns = new azure.ApnsCredential(keydata, certData);

var hub='myhub';

//conn is either a service level or entity level connection string
//hub is the hub to use for the app
var nhs = azure.createNotificationHubService(conn, myhub);

//to create a new hub
nhs.createNotificationHub(name, credentials, function(err, response){..});

//send using wns
var msg = nhs.wins.createTileSquarePeekImageAndText01(language);
msg.image1src = 'http://foobar.com/dog.jpg';
msg.image1alt = 'A dog';
msg.text1 = 'This is a dog';
msg.text2 = 'The dog is nice';
msg.text3 = 'The dog bites';
msg.text4 = 'Beware of dog';

nhs.wns.sendTile('tag', msg, headers, function(err, response) {...});

// send using apns
var msg = nhc.apns.createPayload();
msg.alert = "You got your emails";
msg.badge = 9;
msg.sound = 'bingbong.aiff';

nhs.apns.send('tag2', apnsPayload, function(err, response) {...});

//send using a template
var msg = {}
msg.foo = "foo"
msg.bar = "bar";

nh.send("tag3", msg, function(err, response) {...});

API

createNotificationHubService

azure.createNotificationHubService(conn, hub)

returns NotificationHubService

  • conn - connection string
  • hub - hub name

NotificationHubService

PushCredentials

ctor

azure.PushCredentails()

Create new push credentials

properties

  • wns - WnsCredential
  • apns - ApnsCredential

WnsCredential

ctor

azure.WnsCredential(packageSid, clientSecret)
  • packageSid - wns package sid
  • clientSecret - wns client secret

properties

  • packageSid - wns package sid
  • clientSecret - wns client secret

ApnsCredential

ctor

azure.ApnsCredential(keyData, certData)
  • keyData - apns key
  • certData - apns cert

properties

  • keyData - apns key
  • certData - apns cert

methods

createNotificationHub(name, credentials) 
  • name - hub name
  • credentials - PushCredentials instance

WnsPush

ctor

WnsPush(pushCredentials)

methods

send(tag, xmlString, headers, callback) 
  • tag - tag for the payload
  • xmlString - xml payload for the message
  • headers - wns headers
  • callback - callback with err and response
sendRaw(tag, stringPayload, headers, callback) 
  • tag - tag for the payload
  • stringPayload - raw payload for the message
  • headers - wns headers
  • callback - callback with err and response
sendToast(tag, toastPayload, headers, callback) 
  • tag - tag for the payload
  • toastPayload - toast JSON payload
  • headers - wns headers
  • callback - callback with err and response
sendTile(tag, tilePayload, headers, callback) 
  • tag - tag for the payload
  • tilePayload - tile JSON payload
  • headers - wns headers
  • callback - callback with err and response
sendBadge(tag, badgePayload, headers, callback) 
  • tag - tag for the payload
  • badgePayload - badge JSON payload
  • headers - wns headers
  • callback - callback with err and response
createTileSquarePeekImageAndText01(language)

returns: tileSquarePeekImageAndText01

  • language - language override for tile

tileSquarePeekImageAndText01

properties

  • image1src - Source for the image
  • image1alt - alternate for the image
  • text1 - first line of text
  • text2 - second line of text
  • text3 - third line of text
  • text4 - fourth line of text.
Clone this wiki locally