UNPKG

6.9 kBMarkdownView Raw
1#mpns
2
3Send toast and live tile updates to Windows Phones through the Microsoft Push Notification Service (MPNS). Intended for the cloud and Node.js.
4
5## Installation
6
7Via [npm][]:
8
9 $ npm install mpns
10
11As a submodule of your Git project
12
13 $ git submodule add http://github.com/jeffwilcox/mpns.git mpns
14 $ git submodule update --init
15
16## Usage
17### Load in the module
18
19```javascript
20var mpns = require('mpns');
21```
22
23### Sending a toast
24To send a toast, simply call the `sendToast` method on mpns.
25
26```javascript
27var mpns = require('mpns');
28mpns.sendToast(pushUri, 'Bold Text', 'This is normal text');
29
30// Optional callback
31mpns.sendToast(pushUri, text1, text2, callback);
32```
33
34Each of the methods that send tile and toast notifications have two alternative parameter signatures:
35
36```
37send*(pushUri, [options], [callback])
38send*(pushUri, string1, string2, ..., [callback])
39```
40
41The ordering of the parameters in the non-object calling method assumes ordering as documented in the toast or tile-specific sections below.
42
43For toasts, the properties and ordering for them:
44
45* `text1` the text of the toast, this first text will appear bold on the phone
46* `text2` additional toast text, will appear in the normal font. It does not wrap.
47* `param` optional URI parameter within your application specifying the XAML page to open within the app, along with any query string parameters for the page's context
48
49### Sending a live tile update
50To send a tile update, call the `sendTile` method on mpns.
51
52It is recommended that you use the options syntax for this call as it is possible for the live tile update to include just one component in the update, say the tile count, and not update other properties.
53
54The option names or ordering for parameters is:
55
56* `backgroundImage` URI to the background image for the tile. Beware that the URI may be restricted to the whitelisted domain names that you provided in your application.
57* `count` the number to appear in the tile
58* `title` the title of the tile
59* `backBackgroundImage` URI to the image to be on the flip side of the tile
60* `backTitle` optional title for the back tile
61* `backContent` optional content for the back tile (appears in a larger font size)
62
63### Create a new notification object
64You can create a new notification object (either of type live tile or toast). This is the original style for this module but it is now recommended that you use the shorter `send*` syntax on the mpns object itself. This aligns with the WNS module for Windows in its simplicity.
65
66Property names for the notification object directly correlate to the names used in the MPNS XML payload as documented on MSDN. Properties can either be set directly on the object (such as toast.text1) or by passing the values in as options to the constructor.
67
68```javascript
69options = { text1: 'Hello!', text2: 'Great to see you today.' };
70var toast = new mpns.toast(options);
71```
72
73### Sending a raw notification
74When creating the notification object, either provide the raw payload first, or as the `options.payload` property.
75
76```javascript
77var raw = new mpns.rawNotification('My Raw Payload', options);
78```
79
80Today the type on the request is set to UTF8 explicitly.
81
82### Results object information
83A results object is passed back through the callback and has important information from MPNS.
84
85- `deviceConnectionStatus`: The device status as reported by the service.
86- `notificationStatus`: The status of your provided notification.
87- `subscriptionStatus`: The status of the subscription URI.
88
89The object will also contain all the key fields for your toast or live tile update, plus the pushType. This makes it easy to store this information in a history log somewhere in the ether.
90
91### Handling Errors
92It is very important as a consumer that you store appropriate actionable data about failed push notification attempts. As a result, the callback's first parameter (err) is set to the standard results object as well as a few additional fields depending on the returned status code from the server.
93
94Remember to take action on that information in order to be a good MPNS citizen. These values may be set in the error object and of interest to you:
95
96- `minutesToDelay`: If this is present, it is the suggested minimum amount of time that you should wait until making another request to the same subscription URI. For HTTP 412s, for example, the minimum time is one hour and so the returned value defaults to 61.
97- `shouldDeleteChannel`: If this is set to `true`, the channel is gone according to MPNS. Delete it from your channel/subscription database and never look back.
98- `error`: If an error is captured while trying to make the HTTP request, this will be set to that error callback instance.
99
100### A note about Windows Phone 7.5
101This module permits sending toasts and tiles specific to Mango. If you include the `param` field when sending a push to a 7.0 (first Windows Phone release) phone, unfortunately it may not be received, or will error out the subscription.
102
103Take care when registering your subscription channels with your cloud service to include the application platform version of the app (7.1 for Mango apps). To rock, maybe also grab the OS version and deployed app version. That information can be helpful when supporting customers.
104
105## Credits
106
107NPM module written and maintained by [Jeff Wilcox] with contributions from:
108
109- Jeff Wilcox : https://github.com/jeffwilcox
110- Shawn Burke : https://github.com/shawnburke
111- Jeremie Pelletier : https://github.com/ddude
112
113## License
114
115Copyright Jeff Wilcox
116
117Licensed under the Apache License, Version 2.0 (the "License");
118you may not use this file except in compliance with the License.
119You may obtain a copy of the License at
120
121 http://www.apache.org/licenses/LICENSE-2.0
122
123Unless required by applicable law or agreed to in writing, software
124distributed under the License is distributed on an "AS IS" BASIS,
125WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
126See the License for the specific language governing permissions and
127limitations under the License.
128
129[Jeff Wilcox]: http://www.jeff.wilcox.name
130[npm]: http://github.com/isaacs/npm
131
132## Changelog
133
1341.1.1:
135
136* Adds parameter validation that will throw, for robustness.
137
1381.1.0:
139
140* Adds `sendText` and `sendTile` methods more consistent with the WNS module, removing the need to create a new object, only to then call send on it with a push URI.
141
1421.0.4:
143
144* Adds support for Node.js through 0.9.0
145
1461.0.3:
147
148* Addresses issues when using numbers to set the tile data
149* Cleans up string encoding functions.
150
1511.0.2:
152
153* Fixes some small formatting issues.
154
1551.0.1:
156
157* Adds raw notification type support.
158
1591.0.0:
160
161* Initial implementation offering basic live tile and toast (no raw) support.