{"_id":"wns","_rev":"34-ae1de37774a495af3c5911f4b5412ddc","name":"wns","description":"Send push notifications to Windows 8 devices using WNS","dist-tags":{"latest":"0.5.4"},"versions":{"0.5.2":{"name":"wns","author":{"name":"Tomasz Janczuk","email":"tomasz@janczuk.org","url":"http://tomasz.janczuk.org"},"version":"0.5.2","description":"Send push notifications to Windows 8 devices using WNS","tags":["azure","sdk","windows 8","notifications","wns"],"main":"./lib/wns.js","engines":{"node":">= 0.6.17"},"licenses":[{"type":"Apache","url":"http://www.apache.org/licenses/LICENSE-2.0"}],"dependencies":{},"devDependencies":{"mocha":"1.2.0","nock":"0.13.3"},"homepage":"https://github.com/tjanczuk/wns","repository":{"type":"git","url":"git@github.com:tjanczuk/wns.git"},"bugs":{"url":"http://github.com/tjanczuk/wns/issues"},"readme":"wns\n===\n\nSend push notifications from a node.js application to a Windows 8 device using [Windows Notification Services](http://msdn.microsoft.com/en-us/library/windows/apps/hh913756.aspx). \n\nThis module helps you take care of the interaction #5 on the diagram below: \n\n<img src=\"http://i.msdn.microsoft.com/dynimg/IC554245.png\"/>\n\n## What you need\n\n* Register your cloud service (web application) at https://manage.dev.live.com/build. Your application will be assigned a Package Security Identifier (SID) and Client Secret. These allow your web application to be authenticated to the Windows Notificaton Service.  \n* A channel URL to send notifications to. This is normally created from within your Windows 8 application running on a particular device and securely passed to your web application. The channel URL uniquely identifies the instance of an application running on a particular device.  \n\n## Your first notification\n\nInstall ```wns``` module with\n\n```\nnpm install wns\n```\n\nThen send a notification to your Windows 8 application with\n\n```javascript\nvar wns = require('wns');\n\nvar channelUrl = '{url to your application notification channel}';\nvar options = {\n\tclient_id: '{your Package Security Identifier}',\n\tclient_secret: '{your Client Secret}'\t\n};\n\nwns.sendTileSquareBlock(channelUrl, 'Yes!', 'It worked!', options, function (error, result) {\n\tif (error)\n\t\tconsole.error(error);\n\telse\n\t\tconsole.log(result);\n});\n```\n\n## Notification types\n\nWindows Notification Service supports [tile](http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx), [toast](http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx) and [badge](http://msdn.microsoft.com/en-us/library/windows/apps/br212849.aspx) notification types. The ```wns``` module offers methods to send each type of notification. \n\n### Tile and toast notifications\n\nFor tile notifications, use one of the following methods:\n\n* sendTileSquareBlock\n* sendTileSquareText01\n* sendTileSquareText02\n* sendTileSquareText03\n* sendTileSquareText04\n* sendTileWideText01\n* sendTileWideText02\n* sendTileWideText03\n* sendTileWideText04\n* sendTileWideText05\n* sendTileWideText06\n* sendTileWideText07\n* sendTileWideText08\n* sendTileWideText09\n* sendTileWideText10\n* sendTileWideText11\n* sendTileSquareImage\n* sendTileSquarePeekImageAndText01\n* sendTileSquarePeekImageAndText02\n* sendTileSquarePeekImageAndText03\n* sendTileSquarePeekImageAndText04\n* sendTileWideImage\n* sendTileWideImageCollection\n* sendTileWideImageAndText01\n* sendTileWideImageAndText02\n* sendTileWideBlockAndText01\n* sendTileWideBlockAndText02\n* sendTileWideSmallImageAndText01\n* sendTileWideSmallImageAndText02\n* sendTileWideSmallImageAndText03\n* sendTileWideSmallImageAndText04\n* sendTileWideSmallImageAndText05\n* sendTileWidePeekImageCollection01\n* sendTileWidePeekImageCollection02\n* sendTileWidePeekImageCollection03\n* sendTileWidePeekImageCollection04\n* sendTileWidePeekImageCollection05\n* sendTileWidePeekImageCollection06\n* sendTileWidePeekImageAndText01\n* sendTileWidePeekImageAndText02\n* sendTileWidePeekImage01\n* sendTileWidePeekImage02\n* sendTileWidePeekImage03\n* sendTileWidePeekImage04\n* sendTileWidePeekImage05\n* sendTileWidePeekImage06\n\nFor toast notifications, use one of the following methods:\n\n* sendToastText01\n* sendToastText02\n* sendToastText03\n* sendToastText04\n* sendToastImageAndText01\n* sendToastImageAndText02\n* sendToastImageAndText03\n* sendToastImageAndText04\n\nEach of the methods that send tile and toast notifications have two altenative parameter signatures:\n\n```\nsendXYZ(channel, payload, [options], [callback])\nsendXYZ(channel, string1, string2, ..., [options], [callback])\n```\n\nIn both cases the meaning of ```channel```, ```options```, and ```callback``` is the same:\n\n* ```channel``` [required] - the notification channel URL of the target instance of a Windows 8 application.\n* ```options``` [optional] - allows specifying web application credentials to authenticate the web application to Windows Notification Service. If this parameter is not specified, the ```WNS_CLIENT_ID``` environment variable must be set to the Package Security Identifier (SID), and the ```WNS_CLIENT_SECRET``` environment variable must be set to the Client Secret of the web application. \n  * ```client_id``` [optional] - Package Security Identifier (SID) or the web application. If absent, the value must be provided through ```WNS_CLIENT_ID``` environment variable.\n  * ```client_secret``` [optional] - Client Secret of the web application. If absent, the value must be provided through the ```WNS_CLIENT_SECRET``` environment variable.\n  * ```accessToken``` [optional] - OAuth access token to be used to send notifications. This is normally issued by Windows Notification Service during one of the prior calls to send a notification and passed to the applicaton through the ```callback``` parameter.\n  * ```headers``` [optional] - any additional HTTP request headers to include in the request sent to Windows Notification Service. For a list of available HTTP request headers see [here](http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx).\n* ```callback``` [optional] - a callback function that will be invoked with two parameters: (error, result), where only one is present at any time. The ```error``` parameter is an instance of ```Error``` while ```result``` is a regular object. Both contain the following members:\n  * ```statusCode``` [optional] - the HTTP response status code from Windows Notification Service (for definitions see [here](http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx#send_notification_response)).\n  * ```headers``` [optional] - the HTTP response headers (for WNS specific HTTP response headers see [here](http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx#send_notification_response)).\n  * ```innerError``` [optional] - in case of an error this may contain more information about the condition.\n  * ```newAccessToken``` [optional] - if a new OAuth access token had been obtained in the course of processing the request, it will be provided here. Subsequent calls to ```sendXYZ``` functions should specify this value in the ```options.accessToken``` field. \n\nThe two ```sendXYZ``` method overrides differ in how notification parametrs are specified. Each kind of tile or toast notification contains a specific number of images and text fields. Each image is specified with two strings: its URL and its alternative text. Each text field is specified with just one string. \n\nThe overload that accepts a sequence of ```string1, string2, ...``` parameters requires each of these parameters to be a string corresponding to an image or text field definition. The order of these fields must match the document order of a specific field in the [tile](http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx) or [toast](http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx) notification schema corresponding to the method name (e.g. ```sendTileSquarePeekImageAndText01``` requires a total of 6 parameters in that order: 1 to specify the image URL, 1 to specify the image alt text, and 4 simple text parameters). \n\nThe overload that accepts the ```payload``` parameter requires that ```payload``` is an object. Fields of the object allow specification of image and text parameters using the following naming convention:\n\n* ```image{N}src``` specifies the URL of the N-th image in document order, starting from 1\n* ```image{N}alt``` specifies the alt text of the N-th image in document order, starting from 1\n* ```text{N}``` specifies the value of the N-th text field in document order, starting from 1\n* any parameters that are missing are assumed to be empty strings\n* any extra parameters not required by a particular tile or toast template are ignored\n\nFor example:\n\n```javascript\nvar channel = '{channel_url}';\nvar currentAccessToken;\n\nwns.sendTileSquarePeekImageAndText01(\n\tchannel,\n\t{\n\t\timage1src: 'http://foobar.com/dog.jpg',\n\t\timage1alt: 'A dog',\n\t\ttext1: 'This is a dog',\n\t\ttext2: 'The dog is nice',\n\t\ttext3: 'The dog bites',\n\t\ttext4: 'Beware of dog'\n\t},\n\t{\n\t\tclient_id: '{your Package Security Identifier}',\n\t\tclient_secret: '{your Client Secret}',\n\t\taccessToken: currentAccessToken\n\t}, \n\tfunction (error, result) {\n\t\tcurrentAccessToken = error ? error.newAccessToken : result.newAccessToken;\n\t});\n```\n\n### Badge notifications\n\nTo send a badge notification, use this method:\n\n```javascript\nwns.sendBadge(channel, value, [options], [callback])\n```\n\nThe meaning and behavior of ```channel```, ```options```, and ```callback``` is the same as for tile and toast notifications.\n\nThe ```value``` can be either a simple string or number, in which case it can assume values specified [here](http://msdn.microsoft.com/en-us/library/windows/apps/br212849.aspx), or it can be an object with 2 properties:\n\n* ```value``` [required] - one of the values specified [here](http://msdn.microsoft.com/en-us/library/windows/apps/br212849.aspx).\n* ```version``` [optional] - badge schema version (by default 1).\n\nFor example:\n\n```javascript\nvar channel = '{channel_url}';\nwns.sendBadge(channel, 'alert');\n```\n\n### Low level notifications\n\nThere is one more method that allows sending pre-formatted notifiction messages that adhere to the tile, toast, or badge schema:\n\n```javascript\nwns.send(channel, payload, type, [options], [callback])\n```\n\n The caller takes responsibility for providing a pre-formatted string with XML of the notification as the ```payload``` parameter. The ```type``` parameter specifies the type of the notification as one of the string values specified [here](http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx#pncodes_x_wns_type).\n \n## Running tests\n \nTests are using mocha and nock which are listed as dev dependencies. To run tests invoke mocha from the root of the repository:\n \n```\nmocha\n```","_id":"wns@0.5.2","dist":{"shasum":"92873e95427cde67057a490753956e47eb2c15a6","tarball":"https://registry.npmjs.org/wns/-/wns-0.5.2.tgz","integrity":"sha512-tWYYhr0PRSrGKcBWk3NtsgoHM236N5ivCAbvyAQxUDxTiMA3DSh/2RBWw2F2C0970K3mqTt1WXVYA289CFPu5Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEMCIEvEKVFPZ1zx3hw6uBL2QuJbNISZ6zQChzAS8goM2m7VAh8V8vhhMhZxFQmJSlXAMYNx/7KkmatM6i7V0fzU6w75"}]},"maintainers":[{"name":"tjanczuk","email":"tomasz@janczuk.org"}],"directories":{}},"0.5.3":{"name":"wns","author":{"name":"Tomasz Janczuk","email":"tomasz@janczuk.org","url":"http://tomasz.janczuk.org"},"version":"0.5.3","description":"Send push notifications to Windows 8 devices using WNS","tags":["azure","sdk","windows 8","notifications","wns"],"main":"./lib/wns.js","engines":{"node":">= 0.6.17"},"licenses":[{"type":"Apache","url":"http://www.apache.org/licenses/LICENSE-2.0"}],"dependencies":{},"devDependencies":{"mocha":"1.2.0","nock":"0.13.3"},"homepage":"https://github.com/tjanczuk/wns","repository":{"type":"git","url":"git@github.com:tjanczuk/wns.git"},"bugs":{"url":"http://github.com/tjanczuk/wns/issues"},"readme":"wns\r\n===\r\n\r\nSend push notifications from a node.js application to a Windows 8 device using [Windows Notification Services](http://msdn.microsoft.com/en-us/library/windows/apps/hh913756.aspx). \r\n\r\nThis module helps you take care of the interaction #5 on the diagram below: \r\n\r\n<img src=\"http://i.msdn.microsoft.com/dynimg/IC554245.png\"/>\r\n\r\n## What you need\r\n\r\n* Register your cloud service (web application) at https://manage.dev.live.com/build. Your application will be assigned a Package Security Identifier (SID) and Client Secret. These allow your web application to be authenticated to the Windows Notificaton Service.  \r\n* A channel URL to send notifications to. This is normally created from within your Windows 8 application running on a particular device and securely passed to your web application. The channel URL uniquely identifies the instance of an application running on a particular device.  \r\n\r\n## Your first notification\r\n\r\nInstall ```wns``` module with\r\n\r\n```\r\nnpm install wns\r\n```\r\n\r\nThen send a notification to your Windows 8 application with\r\n\r\n```javascript\r\nvar wns = require('wns');\r\n\r\nvar channelUrl = '{url to your application notification channel}';\r\nvar options = {\r\n\tclient_id: '{your Package Security Identifier}',\r\n\tclient_secret: '{your Client Secret}'\t\r\n};\r\n\r\nwns.sendTileSquareBlock(channelUrl, 'Yes!', 'It worked!', options, function (error, result) {\r\n\tif (error)\r\n\t\tconsole.error(error);\r\n\telse\r\n\t\tconsole.log(result);\r\n});\r\n```\r\n\r\n## Notification types\r\n\r\nWindows Notification Service supports [tile](http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx), [toast](http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx) and [badge](http://msdn.microsoft.com/en-us/library/windows/apps/br212849.aspx) notification types. The ```wns``` module offers methods to send each type of notification. \r\n\r\n### Tile and toast notifications\r\n\r\nFor tile notifications, use one of the following methods:\r\n\r\n* sendTileSquareBlock\r\n* sendTileSquareText01\r\n* sendTileSquareText02\r\n* sendTileSquareText03\r\n* sendTileSquareText04\r\n* sendTileWideText01\r\n* sendTileWideText02\r\n* sendTileWideText03\r\n* sendTileWideText04\r\n* sendTileWideText05\r\n* sendTileWideText06\r\n* sendTileWideText07\r\n* sendTileWideText08\r\n* sendTileWideText09\r\n* sendTileWideText10\r\n* sendTileWideText11\r\n* sendTileSquareImage\r\n* sendTileSquarePeekImageAndText01\r\n* sendTileSquarePeekImageAndText02\r\n* sendTileSquarePeekImageAndText03\r\n* sendTileSquarePeekImageAndText04\r\n* sendTileWideImage\r\n* sendTileWideImageCollection\r\n* sendTileWideImageAndText01\r\n* sendTileWideImageAndText02\r\n* sendTileWideBlockAndText01\r\n* sendTileWideBlockAndText02\r\n* sendTileWideSmallImageAndText01\r\n* sendTileWideSmallImageAndText02\r\n* sendTileWideSmallImageAndText03\r\n* sendTileWideSmallImageAndText04\r\n* sendTileWideSmallImageAndText05\r\n* sendTileWidePeekImageCollection01\r\n* sendTileWidePeekImageCollection02\r\n* sendTileWidePeekImageCollection03\r\n* sendTileWidePeekImageCollection04\r\n* sendTileWidePeekImageCollection05\r\n* sendTileWidePeekImageCollection06\r\n* sendTileWidePeekImageAndText01\r\n* sendTileWidePeekImageAndText02\r\n* sendTileWidePeekImage01\r\n* sendTileWidePeekImage02\r\n* sendTileWidePeekImage03\r\n* sendTileWidePeekImage04\r\n* sendTileWidePeekImage05\r\n* sendTileWidePeekImage06\r\n\r\nFor toast notifications, use one of the following methods:\r\n\r\n* sendToastText01\r\n* sendToastText02\r\n* sendToastText03\r\n* sendToastText04\r\n* sendToastImageAndText01\r\n* sendToastImageAndText02\r\n* sendToastImageAndText03\r\n* sendToastImageAndText04\r\n\r\nEach of the methods that send tile and toast notifications have two altenative parameter signatures:\r\n\r\n```\r\nsendXYZ(channel, payload, [options], [callback])\r\nsendXYZ(channel, string1, string2, ..., [options], [callback])\r\n```\r\n\r\nIn both cases the meaning of ```channel```, ```options```, and ```callback``` is the same:\r\n\r\n* ```channel``` [required] - the notification channel URL of the target instance of a Windows 8 application.\r\n* ```options``` [optional] - allows specifying web application credentials to authenticate the web application to Windows Notification Service. If this parameter is not specified, the ```WNS_CLIENT_ID``` environment variable must be set to the Package Security Identifier (SID), and the ```WNS_CLIENT_SECRET``` environment variable must be set to the Client Secret of the web application. \r\n  * ```client_id``` [optional] - Package Security Identifier (SID) or the web application. If absent, the value must be provided through ```WNS_CLIENT_ID``` environment variable.\r\n  * ```client_secret``` [optional] - Client Secret of the web application. If absent, the value must be provided through the ```WNS_CLIENT_SECRET``` environment variable.\r\n  * ```accessToken``` [optional] - OAuth access token to be used to send notifications. This is normally issued by Windows Notification Service during one of the prior calls to send a notification and passed to the applicaton through the ```callback``` parameter.\r\n  * ```headers``` [optional] - any additional HTTP request headers to include in the request sent to Windows Notification Service. For a list of available HTTP request headers see [here](http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx).\r\n  * ```launch``` [optional; toast notifications only] - application specific string payload that will be delievered to the client device along with the toast notification\r\n  * ```duration``` [optional; toast notifications only] - duration the toast notification will be shown; valid values are ```long``` and ```short```\r\n* ```callback``` [optional] - a callback function that will be invoked with two parameters: (error, result), where only one is present at any time. The ```error``` parameter is an instance of ```Error``` while ```result``` is a regular object. Both contain the following members:\r\n  * ```statusCode``` [optional] - the HTTP response status code from Windows Notification Service (for definitions see [here](http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx#send_notification_response)).\r\n  * ```headers``` [optional] - the HTTP response headers (for WNS specific HTTP response headers see [here](http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx#send_notification_response)).\r\n  * ```innerError``` [optional] - in case of an error this may contain more information about the condition.\r\n  * ```newAccessToken``` [optional] - if a new OAuth access token had been obtained in the course of processing the request, it will be provided here. Subsequent calls to ```sendXYZ``` functions should specify this value in the ```options.accessToken``` field. \r\n\r\nThe two ```sendXYZ``` method overrides differ in how notification parametrs are specified. Each kind of tile or toast notification contains a specific number of images and text fields. Each image is specified with two strings: its URL and its alternative text. Each text field is specified with just one string. \r\n\r\nThe overload that accepts a sequence of ```string1, string2, ...``` parameters requires each of these parameters to be a string corresponding to an image or text field definition. The order of these fields must match the document order of a specific field in the [tile](http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx) or [toast](http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx) notification schema corresponding to the method name (e.g. ```sendTileSquarePeekImageAndText01``` requires a total of 6 parameters in that order: 1 to specify the image URL, 1 to specify the image alt text, and 4 simple text parameters). \r\n\r\nThe overload that accepts the ```payload``` parameter requires that ```payload``` is an object. Fields of the object allow specification of image and text parameters using the following naming convention:\r\n\r\n* ```image{N}src``` specifies the URL of the N-th image in document order, starting from 1\r\n* ```image{N}alt``` specifies the alt text of the N-th image in document order, starting from 1\r\n* ```text{N}``` specifies the value of the N-th text field in document order, starting from 1\r\n* any parameters that are missing are assumed to be empty strings\r\n* any extra parameters not required by a particular tile or toast template are ignored\r\n\r\nFor example:\r\n\r\n```javascript\r\nvar channel = '{channel_url}';\r\nvar currentAccessToken;\r\n\r\nwns.sendTileSquarePeekImageAndText01(\r\n\tchannel,\r\n\t{\r\n\t\timage1src: 'http://foobar.com/dog.jpg',\r\n\t\timage1alt: 'A dog',\r\n\t\ttext1: 'This is a dog',\r\n\t\ttext2: 'The dog is nice',\r\n\t\ttext3: 'The dog bites',\r\n\t\ttext4: 'Beware of dog'\r\n\t},\r\n\t{\r\n\t\tclient_id: '{your Package Security Identifier}',\r\n\t\tclient_secret: '{your Client Secret}',\r\n\t\taccessToken: currentAccessToken\r\n\t}, \r\n\tfunction (error, result) {\r\n\t\tcurrentAccessToken = error ? error.newAccessToken : result.newAccessToken;\r\n\t});\r\n```\r\n\r\n### Sending multiple tile or toast notifications at once\r\n\r\nYou can send multiple toast or tile notifications in a single update to the client. This feature is useful since the client device may then choose one the tile or toast formats that suites its local configuration best. For example, you may send two semantically equivalent tiles, one square and the other wide. The client UI will decide which one to show based on its configuration. \r\n\r\nTo send multiple toasts or tiles in a single update use one of these methods:\r\n\r\n```javascript\r\nwns.sendTile(channel, tile1, tile2, ..., [options], [callback])\r\nwns.sendToast(channel, toast1, toast2, ..., [options], [callback])\r\n``` \r\n\r\nThe meaning and behavior or `channel`, `options`, and `callback` is the same as for the `wns.sendXYZ` APIs which send a single toast or tile. \r\n\r\nThe `tile1`, `tile2`, etc. parameters describe the tile or toast binding which defines its appearance. These are JavaScript objects constructed the same way as you would construct them for use with `wns.sendXYZ` methods, but contain one extra property named `type`. The `type` property is a string name of the tile or toast template, e.g. `TileSquareBlock`. For a complete list of available tile and toast template names see [tile](http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx) and [toast](http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx) documentation.\r\n\r\nFor example:\r\n\r\n```javascript\r\nvar channel = '{channel_url}';\r\n\r\nwns.sendTile(\r\n\tchannel,\r\n\t{\r\n\t\ttype: 'TileSquareText04',\r\n\t\ttext1: 'Hello'\r\n\t},\r\n\t{\r\n\t\ttype: 'TileWideText09',\r\n\t\ttext1: 'Hello',\r\n\t\ttext2: 'How are you?'\r\n\t},\r\n\t{\r\n\t\tclient_id: '{your Package Security Identifier}',\r\n\t\tclient_secret: '{your Client Secret}'\r\n\t}, \r\n\tfunction (error, result) {\r\n\t\t// ...\r\n\t});\r\n```\r\n\r\nThe code above sends an update with two tile definitions: TileSquareText04 and TileWideText09. The client agent will choose the tile update to show. \r\n\r\n### Selecting language and other tile or toast parameters\r\n\r\nYou can add several parameters to tile and toast notifications by adding properties to the object that defines the tile or toast. For example, to indicate the target language is German, you can use the `lang` property as follows:\r\n\r\n```javascript\r\nwns.sendTileSquareText04(\r\n\tchannel,\r\n\t{\r\n\t\ttext1: 'Herzlich Willkommen',\r\n\t\tlang: 'de'\r\n\t},\r\n\t{\r\n\t\tclient_id: '{your Package Security Identifier}',\r\n\t\tclient_secret: '{your Client Secret}'\r\n\t}, \r\n\tfunction (error, result) {\r\n\t\t// ...\r\n\t});\r\n```\r\n\r\nYou can use this method to specify `lang`, `fallback`, `baseUri`, `branding`, and `addImageQuery` parameters of a toast or tile as specified [here](http://msdn.microsoft.com/en-us/library/windows/apps/br230843.aspx). \r\n\r\n### Badge notifications\r\n\r\nTo send a badge notification, use this method:\r\n\r\n```javascript\r\nwns.sendBadge(channel, value, [options], [callback])\r\n```\r\n\r\nThe meaning and behavior of ```channel```, ```options```, and ```callback``` is the same as for tile and toast notifications.\r\n\r\nThe ```value``` can be either a simple string or number, in which case it can assume values specified [here](http://msdn.microsoft.com/en-us/library/windows/apps/br212849.aspx), or it can be an object with 2 properties:\r\n\r\n* ```value``` [required] - one of the values specified [here](http://msdn.microsoft.com/en-us/library/windows/apps/br212849.aspx).\r\n* ```version``` [optional] - badge schema version (by default 1).\r\n\r\nFor example:\r\n\r\n```javascript\r\nvar channel = '{channel_url}';\r\nwns.sendBadge(channel, 'alert');\r\n```\r\n\r\n### Raw notifications\r\n\r\nTo send a raw notification, use this method:\r\n\r\n```javascript\r\nwns.sendRaw(channel, value, [options], [callback])\r\n```\r\n\r\nThe meaning and behavior of ```channel```, ```options```, and ```callback``` is the same as for tile and toast notifications.\r\n\r\nThe ```value``` is an application specific string that will be delivered to the client unchanged.\r\n\r\nFor example:\r\n\r\n```javascript\r\nvar channel = '{channel_url}';\r\nwns.sendRaw(channel, JSON.stringify({ foo: 1, bar: 2 }));\r\n```\r\n\r\n### Low level notifications\r\n\r\nThere is one more method that allows sending pre-formatted notifiction messages that adhere to the tile, toast, or badge schema:\r\n\r\n```javascript\r\nwns.send(channel, payload, type, [options], [callback])\r\n```\r\n\r\nThe caller takes responsibility for providing a pre-formatted string (typically with XML) of the notification as the ```payload``` parameter. The ```type``` parameter specifies the type of the notification as one of the string values specified [here](http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx#pncodes_x_wns_type).\r\n \r\n## Running tests\r\n \r\nTests are using mocha and nock which are listed as dev dependencies. To run tests invoke mocha from the root of the repository:\r\n \r\n```\r\nmocha\r\n```","readmeFilename":"README.md","_id":"wns@0.5.3","dist":{"shasum":"00f4e85cfcf8e3383dcbd81898906f1f6ad4845f","tarball":"https://registry.npmjs.org/wns/-/wns-0.5.3.tgz","integrity":"sha512-rj3Jj0ldFoEGBOlXAIxJnvX44TvXAlXFAkOTrhQisd646YPf3xmaHxSdiQ9Q2vbP8xzgU0ZUTfGYZ8c3I6L8gQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDe3OiSmj0RXWl3T8Qk9OpWepGAeZ79+1aDnjJ3Ch/EDQIgXf10YmCzuQXqhhvwvZ2uAySVfoMftLEIeXXKK+7IHkI="}]},"_from":".","_npmVersion":"1.2.10","_npmUser":{"name":"tjanczuk","email":"tomasz@janczuk.org"},"maintainers":[{"name":"tjanczuk","email":"tomasz@janczuk.org"}],"directories":{}},"0.5.4":{"name":"wns","author":{"name":"Tomasz Janczuk","email":"tomasz@janczuk.org","url":"http://tomasz.janczuk.org"},"version":"0.5.4","description":"Send push notifications to Windows 8 devices using WNS","tags":["azure","sdk","windows 8","notifications","wns"],"main":"./lib/wns.js","engines":{"node":">= 0.6.17"},"licenses":[{"type":"Apache","url":"http://www.apache.org/licenses/LICENSE-2.0"}],"dependencies":{},"devDependencies":{"mocha":"1.2.0","nock":"0.13.3"},"homepage":"https://github.com/tjanczuk/wns","repository":{"type":"git","url":"git+ssh://git@github.com/tjanczuk/wns.git"},"bugs":{"url":"http://github.com/tjanczuk/wns/issues"},"gitHead":"4fcbced22da8eb15dd2f5e2b5eaf05c8b80263b6","_id":"wns@0.5.4","_npmVersion":"5.6.0","_nodeVersion":"8.11.0","_npmUser":{"name":"tjanczuk","email":"tomasz@janczuk.org"},"dist":{"integrity":"sha512-WYiJ7khIwUGBD5KAm+YYmwJDDRzFRs4YGAjtbFSoRIdbn9Jcix3p9khJmpvBTXGommaKkvduAn+pc9l4d9yzVQ==","shasum":"ad8e2ee60e675557da9610d94444a7f59eceaf78","tarball":"https://registry.npmjs.org/wns/-/wns-0.5.4.tgz","fileCount":75,"unpackedSize":262612,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbJqQMCRA9TVsSAnZWagAAH7AQAKDz1DThMYjCc2zWohai\nBCH6FbCKgfIATohHsD+xCd+RCFTgHvHeHK8HKfMAIEtQ8tkqFWLYAwgjpCd8\nDmukg9QtAszlQLHJqedlybqr/S5n5BswSGXhOwtKN036xoy8u+LXkUInv70H\naXS3sKK9jqBQhoX152dUMFbGy81l3/aMXUnBR1zvtKzFd7UfdPPmg4zULzqk\nBb8U2EL5/86oNUJ/b1NEHYw9ecm0YGyW/R7oioQ78coASqjeCBrXKtff3445\nLEP0hA38XpMzl5ddKGAjilprnpmH/R9qZ1j+hZfR1pCAp2XYruUn8OzwrNtQ\nztoq4OrcpDvoGmPs39O+nKM00u1GMcY69+IO4nCz8Xk6NA2n6irEg4bcQfAb\n1gsvhR3SqqH7U1RC0Di6UMNBUsUVKC4HA0OMrBaxOBMVAg29La64hb3pWuo4\n1jlncoO+XTiVLQo8bUhlYMubdIYkCAq9MNiT+9OXrfOam44lzWMGq8QWcPrt\n63L6P68sTU9KLZTXrnecnAG4ToQmR4gwC7//6QN0FvvAneaTy+u36cdWltYQ\nQ4+7O9cU0rcnaGr9l9Hkh1XV43QmVYTrtMvDrs8/UocUCz4e7QLVbpJfYguG\n/xn1PmpQI8+l2aWlbJRtuqbg9IdjKLU8qR9m/h6HTzUfShvHpCvKh0rDDVvS\ncmc9\r\n=5Yxi\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDTYcy/6ZKpJ0AKaa7Ng8YFRq6H4E3YjMh9DRTrL7MbLQIhAObBfdWVwWSIkObiaQT67aoI6ikxom2kRGzbQzFkbrqg"}]},"maintainers":[{"name":"tjanczuk","email":"tomasz@janczuk.org"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/wns_0.5.4_1529259019090_0.6175779269338608"},"_hasShrinkwrap":false}},"readme":"wns\n===\n\nSend push notifications from a node.js application to a Windows 8 device using [Windows Notification Services](http://msdn.microsoft.com/en-us/library/windows/apps/hh913756.aspx). \n\nThis module helps you take care of the interaction #5 on the diagram below: \n\n<img src=\"http://i.msdn.microsoft.com/dynimg/IC554245.png\"/>\n\n## What you need\n\n* Register your cloud service (web application) at https://manage.dev.live.com/build. Your application will be assigned a Package Security Identifier (SID) and Client Secret. These allow your web application to be authenticated to the Windows Notificaton Service.  \n* A channel URL to send notifications to. This is normally created from within your Windows 8 application running on a particular device and securely passed to your web application. The channel URL uniquely identifies the instance of an application running on a particular device.  \n\n## Your first notification\n\nInstall ```wns``` module with\n\n```\nnpm install wns\n```\n\nThen send a notification to your Windows 8 application with\n\n```javascript\nvar wns = require('wns');\n\nvar channelUrl = '{url to your application notification channel}';\nvar options = {\n\tclient_id: '{your Package Security Identifier}',\n\tclient_secret: '{your Client Secret}'\t\n};\n\nwns.sendTileSquareBlock(channelUrl, 'Yes!', 'It worked!', options, function (error, result) {\n\tif (error)\n\t\tconsole.error(error);\n\telse\n\t\tconsole.log(result);\n});\n```\n\n## Notification types\n\nWindows Notification Service supports [tile](http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx), [toast](http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx) and [badge](http://msdn.microsoft.com/en-us/library/windows/apps/br212849.aspx) notification types. The ```wns``` module offers methods to send each type of notification. \n\n### Tile and toast notifications\n\nFor tile notifications, use one of the following methods:\n\n* sendTileSquareBlock\n* sendTileSquareText01\n* sendTileSquareText02\n* sendTileSquareText03\n* sendTileSquareText04\n* sendTileWideText01\n* sendTileWideText02\n* sendTileWideText03\n* sendTileWideText04\n* sendTileWideText05\n* sendTileWideText06\n* sendTileWideText07\n* sendTileWideText08\n* sendTileWideText09\n* sendTileWideText10\n* sendTileWideText11\n* sendTileSquareImage\n* sendTileSquarePeekImageAndText01\n* sendTileSquarePeekImageAndText02\n* sendTileSquarePeekImageAndText03\n* sendTileSquarePeekImageAndText04\n* sendTileWideImage\n* sendTileWideImageCollection\n* sendTileWideImageAndText01\n* sendTileWideImageAndText02\n* sendTileWideBlockAndText01\n* sendTileWideBlockAndText02\n* sendTileWideSmallImageAndText01\n* sendTileWideSmallImageAndText02\n* sendTileWideSmallImageAndText03\n* sendTileWideSmallImageAndText04\n* sendTileWideSmallImageAndText05\n* sendTileWidePeekImageCollection01\n* sendTileWidePeekImageCollection02\n* sendTileWidePeekImageCollection03\n* sendTileWidePeekImageCollection04\n* sendTileWidePeekImageCollection05\n* sendTileWidePeekImageCollection06\n* sendTileWidePeekImageAndText01\n* sendTileWidePeekImageAndText02\n* sendTileWidePeekImage01\n* sendTileWidePeekImage02\n* sendTileWidePeekImage03\n* sendTileWidePeekImage04\n* sendTileWidePeekImage05\n* sendTileWidePeekImage06\n\nFor toast notifications, use one of the following methods:\n\n* sendToastText01\n* sendToastText02\n* sendToastText03\n* sendToastText04\n* sendToastImageAndText01\n* sendToastImageAndText02\n* sendToastImageAndText03\n* sendToastImageAndText04\n\nEach of the methods that send tile and toast notifications have two altenative parameter signatures:\n\n```\nsendXYZ(channel, payload, [options], [callback])\nsendXYZ(channel, string1, string2, ..., [options], [callback])\n```\n\nIn both cases the meaning of ```channel```, ```options```, and ```callback``` is the same:\n\n* ```channel``` [required] - the notification channel URL of the target instance of a Windows 8 application.\n* ```options``` [optional] - allows specifying web application credentials to authenticate the web application to Windows Notification Service. If this parameter is not specified, the ```WNS_CLIENT_ID``` environment variable must be set to the Package Security Identifier (SID), and the ```WNS_CLIENT_SECRET``` environment variable must be set to the Client Secret of the web application. \n  * ```client_id``` [optional] - Package Security Identifier (SID) or the web application. If absent, the value must be provided through ```WNS_CLIENT_ID``` environment variable.\n  * ```client_secret``` [optional] - Client Secret of the web application. If absent, the value must be provided through the ```WNS_CLIENT_SECRET``` environment variable.\n  * ```accessToken``` [optional] - OAuth access token to be used to send notifications. This is normally issued by Windows Notification Service during one of the prior calls to send a notification and passed to the applicaton through the ```callback``` parameter.\n  * ```headers``` [optional] - any additional HTTP request headers to include in the request sent to Windows Notification Service. For a list of available HTTP request headers see [here](http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx).\n  * ```launch``` [optional; toast notifications only] - application specific string payload that will be delievered to the client device along with the toast notification\n  * ```duration``` [optional; toast notifications only] - duration the toast notification will be shown; valid values are ```long``` and ```short```\n* ```callback``` [optional] - a callback function that will be invoked with two parameters: (error, result), where only one is present at any time. The ```error``` parameter is an instance of ```Error``` while ```result``` is a regular object. Both contain the following members:\n  * ```statusCode``` [optional] - the HTTP response status code from Windows Notification Service (for definitions see [here](http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx#send_notification_response)).\n  * ```headers``` [optional] - the HTTP response headers (for WNS specific HTTP response headers see [here](http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx#send_notification_response)).\n  * ```innerError``` [optional] - in case of an error this may contain more information about the condition.\n  * ```newAccessToken``` [optional] - if a new OAuth access token had been obtained in the course of processing the request, it will be provided here. Subsequent calls to ```sendXYZ``` functions should specify this value in the ```options.accessToken``` field. \n\nThe two ```sendXYZ``` method overrides differ in how notification parametrs are specified. Each kind of tile or toast notification contains a specific number of images and text fields. Each image is specified with two strings: its URL and its alternative text. Each text field is specified with just one string. \n\nThe overload that accepts a sequence of ```string1, string2, ...``` parameters requires each of these parameters to be a string corresponding to an image or text field definition. The order of these fields must match the document order of a specific field in the [tile](http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx) or [toast](http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx) notification schema corresponding to the method name (e.g. ```sendTileSquarePeekImageAndText01``` requires a total of 6 parameters in that order: 1 to specify the image URL, 1 to specify the image alt text, and 4 simple text parameters). \n\nThe overload that accepts the ```payload``` parameter requires that ```payload``` is an object. Fields of the object allow specification of image and text parameters using the following naming convention:\n\n* ```image{N}src``` specifies the URL of the N-th image in document order, starting from 1\n* ```image{N}alt``` specifies the alt text of the N-th image in document order, starting from 1\n* ```text{N}``` specifies the value of the N-th text field in document order, starting from 1\n* any parameters that are missing are assumed to be empty strings\n* any extra parameters not required by a particular tile or toast template are ignored\n\nFor example:\n\n```javascript\nvar channel = '{channel_url}';\nvar currentAccessToken;\n\nwns.sendTileSquarePeekImageAndText01(\n\tchannel,\n\t{\n\t\timage1src: 'http://foobar.com/dog.jpg',\n\t\timage1alt: 'A dog',\n\t\ttext1: 'This is a dog',\n\t\ttext2: 'The dog is nice',\n\t\ttext3: 'The dog bites',\n\t\ttext4: 'Beware of dog'\n\t},\n\t{\n\t\tclient_id: '{your Package Security Identifier}',\n\t\tclient_secret: '{your Client Secret}',\n\t\taccessToken: currentAccessToken\n\t}, \n\tfunction (error, result) {\n\t\tcurrentAccessToken = error ? error.newAccessToken : result.newAccessToken;\n\t});\n```\n\n### Sending multiple tile or toast notifications at once\n\nYou can send multiple toast or tile notifications in a single update to the client. This feature is useful since the client device may then choose one the tile or toast formats that suites its local configuration best. For example, you may send two semantically equivalent tiles, one square and the other wide. The client UI will decide which one to show based on its configuration. \n\nTo send multiple toasts or tiles in a single update use one of these methods:\n\n```javascript\nwns.sendTile(channel, tile1, tile2, ..., [options], [callback])\nwns.sendToast(channel, toast1, toast2, ..., [options], [callback])\n``` \n\nThe meaning and behavior or `channel`, `options`, and `callback` is the same as for the `wns.sendXYZ` APIs which send a single toast or tile. \n\nThe `tile1`, `tile2`, etc. parameters describe the tile or toast binding which defines its appearance. These are JavaScript objects constructed the same way as you would construct them for use with `wns.sendXYZ` methods, but contain one extra property named `type`. The `type` property is a string name of the tile or toast template, e.g. `TileSquareBlock`. For a complete list of available tile and toast template names see [tile](http://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx) and [toast](http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx) documentation.\n\nFor example:\n\n```javascript\nvar channel = '{channel_url}';\n\nwns.sendTile(\n\tchannel,\n\t{\n\t\ttype: 'TileSquareText04',\n\t\ttext1: 'Hello'\n\t},\n\t{\n\t\ttype: 'TileWideText09',\n\t\ttext1: 'Hello',\n\t\ttext2: 'How are you?'\n\t},\n\t{\n\t\tclient_id: '{your Package Security Identifier}',\n\t\tclient_secret: '{your Client Secret}'\n\t}, \n\tfunction (error, result) {\n\t\t// ...\n\t});\n```\n\nThe code above sends an update with two tile definitions: TileSquareText04 and TileWideText09. The client agent will choose the tile update to show. \n\n### Selecting language and other tile or toast parameters\n\nYou can add several parameters to tile and toast notifications by adding properties to the object that defines the tile or toast. For example, to indicate the target language is German, you can use the `lang` property as follows:\n\n```javascript\nwns.sendTileSquareText04(\n\tchannel,\n\t{\n\t\ttext1: 'Herzlich Willkommen',\n\t\tlang: 'de'\n\t},\n\t{\n\t\tclient_id: '{your Package Security Identifier}',\n\t\tclient_secret: '{your Client Secret}'\n\t}, \n\tfunction (error, result) {\n\t\t// ...\n\t});\n```\n\nYou can use this method to specify `lang`, `fallback`, `baseUri`, `branding`, and `addImageQuery` parameters of a toast or tile as specified [here](http://msdn.microsoft.com/en-us/library/windows/apps/br230843.aspx). \n\n### Badge notifications\n\nTo send a badge notification, use this method:\n\n```javascript\nwns.sendBadge(channel, value, [options], [callback])\n```\n\nThe meaning and behavior of ```channel```, ```options```, and ```callback``` is the same as for tile and toast notifications.\n\nThe ```value``` can be either a simple string or number, in which case it can assume values specified [here](http://msdn.microsoft.com/en-us/library/windows/apps/br212849.aspx), or it can be an object with 2 properties:\n\n* ```value``` [required] - one of the values specified [here](http://msdn.microsoft.com/en-us/library/windows/apps/br212849.aspx).\n* ```version``` [optional] - badge schema version (by default 1).\n\nFor example:\n\n```javascript\nvar channel = '{channel_url}';\nwns.sendBadge(channel, 'alert');\n```\n\n### Raw notifications\n\nTo send a raw notification, use this method:\n\n```javascript\nwns.sendRaw(channel, value, [options], [callback])\n```\n\nThe meaning and behavior of ```channel```, ```options```, and ```callback``` is the same as for tile and toast notifications.\n\nThe ```value``` is an application specific string that will be delivered to the client unchanged.\n\nFor example:\n\n```javascript\nvar channel = '{channel_url}';\nwns.sendRaw(channel, JSON.stringify({ foo: 1, bar: 2 }));\n```\n\n### Low level notifications\n\nThere is one more method that allows sending pre-formatted notifiction messages that adhere to the tile, toast, or badge schema:\n\n```javascript\nwns.send(channel, payload, type, [options], [callback])\n```\n\nThe caller takes responsibility for providing a pre-formatted string (typically with XML) of the notification as the ```payload``` parameter. The ```type``` parameter specifies the type of the notification as one of the string values specified [here](http://msdn.microsoft.com/en-us/library/windows/apps/hh465435.aspx#pncodes_x_wns_type).\n \n## Running tests\n \nTests are using mocha and nock which are listed as dev dependencies. To run tests invoke mocha from the root of the repository:\n \n```\nmocha\n```","maintainers":[{"name":"tjanczuk","email":"tomasz@janczuk.org"}],"time":{"modified":"2022-06-29T02:58:13.101Z","created":"2012-06-19T06:19:57.981Z","0.1.0-pre":"2012-06-19T06:19:58.677Z","0.1.0":"2012-06-20T00:30:01.339Z","0.2.0":"2012-06-21T22:17:22.711Z","0.3.0":"2012-06-22T18:51:35.377Z","0.4.0":"2012-07-02T21:16:56.884Z","0.5.1":"2012-07-31T17:28:59.781Z","0.5.2":"2012-10-03T00:27:44.141Z","0.5.3":"2013-02-20T08:00:38.966Z","0.5.4":"2018-06-17T18:10:19.154Z"},"author":{"name":"Tomasz Janczuk","email":"tomasz@janczuk.org","url":"http://tomasz.janczuk.org"},"repository":{"type":"git","url":"git+ssh://git@github.com/tjanczuk/wns.git"},"users":{"fgribreau":true},"homepage":"https://github.com/tjanczuk/wns","bugs":{"url":"http://github.com/tjanczuk/wns/issues"},"readmeFilename":"README.md"}