This repository was archived by the owner on Aug 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (45 loc) · 1.36 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var url = require('url');
var http = require('http');
exports.version = "0.0.1";
var sendNotification = function(msg, pushUrl, type) {
var uri = url.parse(pushUrl);
var notificationClass;
var headers = {
"Content-Type": "text/xml",
"Content-Length": msg.length,
"X-NotificationClass": 2,
"X-WindowsPhone-Target": type
};
var options = {
host: uri.host,
port: 80,
path: uri.pathname,
method: 'POST',
headers: headers
};
var req = http.request(options, function(res) {
if (res.statusCode != 200) {
return new Error("The Push Notification wasn't recived by the MSFT Servers. "
+ res.StatusCode);
}
res.setEncoding('utf8');
res.on('data', function(chunk) {
});
});
req.on('error', function(e) {
return new Error("The Push Notification wasn't recived by the MSFT Servers. " +
e.message);
});
req.write(msg);
req.end();
}
exports.sendToastNotification = function(title, subtitle, url) {
var msg = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
"<wp:Toast>" +
"<wp:Text1>" + title + "</wp:Text1>" +
"<wp:Text2>" + subtitle + "</wp:Text2>" +
"</wp:Toast>" +
"</wp:Notification>";
return sendNotification(msg, url, 'toast');
};