-
Notifications
You must be signed in to change notification settings - Fork 0
/
poster.js
36 lines (32 loc) · 883 Bytes
/
poster.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
var https = require('https');
var service = module.exports = {
sendAlert: function(occupied){
var postData = JSON.stringify({
text: "Ping Pong Table: *"+(occupied?'':'un')+"occupied*",
username: "Hall Monitor Bot",
icon_emoji: occupied?":pingpong:":":no_entry:"
});
var options = {
hostname: 'hooks.slack.com',
port: 443,
path: '/services/T025ZF3QJ/B04GP0Y0B/1q0yiLQxAOOFKYImXYa0uDeb',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': postData.length
}
};
var req = https.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
// write data to request body
req.write(postData);
req.end();
}
}