-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack.js
64 lines (53 loc) · 1.64 KB
/
slack.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
57
58
59
60
61
62
63
64
const fetch = require('node-fetch');
const too_low= require('./slack_block/too_low_score.js');
const actual_message= require('./slack_block/actual_score.js');
const increasing= require('./slack_block/increasing.js');
const lowing= require('./slack_block/lowing_score.js');
const WEBHOOK= process.env.SLACK_WEBHOOK;
function sendTooLowMessage(score){
sendSlackMessage(setScore(too_low.blocks,score))
}
function sendIncreasingScoreMessage(actual,before){
body=setScore(increasing.blocks,actual)
sendSlackMessage(setChangingScore(body,actual,before))
}
function sendLowingScoreMessage(actual,before){
body=setScore(lowing.blocks,actual)
sendSlackMessage(setChangingScore(body,actual,before))
}
function sendActualScore(actual){
sendSlackMessage(setScore(actual_message.blocks,actual))
}
function setScore(inputBody,score){
inputBody.blocks[2].text.text=score+"⭐️";
inputBody.blocks[4].elements[0].url="https://play.google.com/store/apps/details?id="+process.env.PACKAGE_ID;
return inputBody;
}
function setChangingScore(inputBody,actual,before){
body=setScore(inputBody,actual)
body.blocks[3].elements[0].text="Anterior: "+before;
return body;
}
function sendSlackMessage(body){
console.log("Slack sending message..");
const options = {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify(body)
};
fetch(WEBHOOK, options)
.then(response => response.text())
.then(data => {
console.log(data)
})
.catch(error => console.error(error));
}
module.exports ={
sendTooLowMessage,
sendIncreasingScoreMessage,
sendLowingScoreMessage,
sendActualScore
}