-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpostToHook.js
43 lines (32 loc) · 966 Bytes
/
postToHook.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
const http = require('follow-redirects').https;
const fs = require('fs');
function POSTtoSlack (data){
let options = {
'method': 'POST',
'hostname': 'chat.poff.ee',
'path': '/hook',
'headers': {
'Content-Type': 'application/json'
},
'maxRedirects': 20
};
const req = http.request(options, (res) => {
let chunks = [];
res.on("data", (chunk) => {
chunks.push(chunk);
});
res.on("end", (chunk) => {
let body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", (error) => {
console.error(error);
console.log("post päringus on error")
});
});
console.log ("data jõudis postToHook funktsiooni")
let postData = JSON.stringify(data);
req.write(postData);
req.end();
}
module.exports.POST = POSTtoSlack