-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack.js
73 lines (67 loc) · 1.97 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
65
66
67
68
69
70
71
72
73
const axios = require('axios')
const {SLACK_URL, HOST} = require('./config')
function payloadProblem(train, carriage, seat, manager, issue) {
return {
text: `Train *${train}* | Carriage \`${carriage}\` | _Seat ${seat}_`,
attachments: [
{
color: '#ff0000',
author_name: `for ${manager}`,
title: issue,
actions: [
{
name: 'issue',
text: 'Resolve',
type: 'button',
value: 'resolved',
style: 'primary',
url: HOST,
confirm: {
title: 'Are you sure?',
text: 'Have you solved the problem?',
ok_text: 'Yes',
dismiss_text: 'No'
}
}
],
footer_icon: 'https://img.icons8.com/ios/50/000000/high-speed-train-filled.png',
footer: 'Reported at',
ts: Date.now()
}
]
}
}
function payloadSolution(train, carriage, seat, manager, issue) {
return {
text: `Train *${train}* | Carriage \`${carriage}\` | _Seat ${seat}_`,
attachments: [
{
color: '00ff00',
author_name: `by ${manager}`,
pretext: `~${issue}~ :white_check_mark:`,
fields: [
{
title: 'Status',
value: 'Solved'
}
],
image_url: 'https://image.ibb.co/ezD0LA/car-box-our-company-2018.jpg',
footer: 'Resolved at',
footer_icon: 'https://img.icons8.com/ios/50/000000/high-speed-train.png',
ts: Date.now()
}
]
}
}
function postToSlack(payload) {
axios.post(SLACK_URL, payload)
.then(console.log.bind(console))
.catch(console.log.bind(console))
}
function reportProblem({train, carriage, seat, manager, issue}) {
postToSlack(payloadProblem(train, carriage, seat, manager, issue))
}
function resolveProblem({train, carriage, seat, manager, issue}) {
postToSlack(payloadSolution(train, carriage, seat, manager, issue))
}
module.exports = {reportProblem, resolveProblem}