-
Notifications
You must be signed in to change notification settings - Fork 566
Service Bus Notification Hubs
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. Each message published is associated with a tag. Notification Hubs will ensure all messages are broadcasted to subscribers of that tag.
- 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.
- Tile: http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx
- Toast: http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx
- Badge: http://msdn.microsoft.com/en-us/library/windows/apps/hh779719.aspx
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 = {
wns: {packageSid:"...", clientSecret:"..."},
apns: {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);
//to create a new hub
nhs.createNotificationHub(hub, credentials, function(err, response){..});
//send using wns wit a payload object
nhs.wns.sendTileSquarePeekImageAndText01(
hub,
tag,
{
image1src: 'http://foobar.com/dog.jpg',
image1alt: 'A dog',
text1: 'This is a dog',
text2: 'The dog is nice',
text3: 'The dog bites',
text4: 'Beware of dog'
},
function (error, result) {
currentAccessToken = error ? error.newAccessToken : result.newAccessToken;
});
//send using wns with flat params in order based on the definition as defined in the wns schema docs.
nhs.wns.sendTileSquarePeekImageAndText01(hub, tag, 'http://foobar.com/dog.jpg', 'A dog', 'This is a dog', 'The dog is nice', 'The dog bites', 'Beware of dog',
function(error, result) {
currentAccessToken = error ? error.newAccessToken : result.newAccessToken;
}
);
// send using apns
var msg = nhs.apns.createPayload();
msg.alert = "You got your emails";
msg.badge = 9;
msg.sound = 'bingbong.aiff';
nhs.apns.send(hub,'tag2', apnsPayload, function(err, response) {...});
//send using a template
var msg = {}
msg.foo = "foo"
msg.bar = "bar";
nh.send(hub, "tag3", msg, function(err, response) {...});
azure.createNotificationHubService(conn)
returns NotificationHubService
- conn - connection string
createNotificationHub(name, credentials)
- name - hub name
- credentials - A hash containing wns and apns properties with the credentials.
send(hub, tag, xmlString, headers, callback)
- hub - hub to send message on
- tag - tag for the payload
- xmlString - xml payload for the message
- headers - wns headers
- callback - callback with err and response
WnsPush(pushCredentials)
send(hub, tag, payload, headers, callback)
- hub - hub to send message on
- tag - tag for the payload
- payload - xml string payload for the message
- headers - wns headers
- callback - callback with err and response
Additional convenience methods will be provided for each Toast/Tile type
- sendTileSquareBlock
- sendTileSquareText01
- sendTileSquareText02
- sendTileSquareText03
- sendTileSquareText04
- sendTileWideText01
- sendTileWideText02
- sendTileWideText03
- sendTileWideText04
- sendTileWideText05
- sendTileWideText06
- sendTileWideText07
- sendTileWideText08
- sendTileWideText09
- sendTileWideText10
- sendTileWideText11
- sendTileSquareImage
- sendTileSquarePeekImageAndText01
- sendTileSquarePeekImageAndText02
- sendTileSquarePeekImageAndText03
- sendTileSquarePeekImageAndText04
- sendTileWideImage
- sendTileWideImageCollection
- sendTileWideImageAndText01
- sendTileWideImageAndText02
- sendTileWideBlockAndText01
- sendTileWideBlockAndText02
- sendTileWideSmallImageAndText01
- sendTileWideSmallImageAndText02
- sendTileWideSmallImageAndText03
- sendTileWideSmallImageAndText04
- sendTileWideSmallImageAndText05
- sendTileWidePeekImageCollection01
- sendTileWidePeekImageCollection02
- sendTileWidePeekImageCollection03
- sendTileWidePeekImageCollection04
- sendTileWidePeekImageCollection05
- sendTileWidePeekImageCollection06
- sendTileWidePeekImageAndText01
- sendTileWidePeekImageAndText02
- sendTileWidePeekImage01
- sendTileWidePeekImage02
- sendTileWidePeekImage03
- sendTileWidePeekImage04
- sendTileWidePeekImage05
- sendTileWidePeekImage06
- sendToastText01
- sendToastText02
- sendToastText03
- sendToastText04
- sendToastImageAndText01
- sendToastImageAndText02
- sendToastImageAndText03
- sendToastImageAndText04
- sendBadge
Each of the methods that send tile and toast notifications have two altenative parameter signatures:
sendXYZ(hub, tag, payload, [options], [callback])
sendXYZ(hub, tag, channel, string1, string2, ..., [options], [callback])
For the string param versions all parameters must be passed in the proper order per the binding schemas specified below:
- Tile: http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx
- Toast: http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx
For badge, the syntax is fixed.
sendBadge(channel, value, [options], [callback])
The value can be either a simple string or number, in which case it can assume values specified here, or it can be an object with 2 properties:
- value [required] - one of the values specified here http://msdn.microsoft.com/en-us/library/windows/apps/br212849.aspx
- version [optional] - badge schema version (by default 1).