/
notifications.js
43 lines (36 loc) · 1.19 KB
/
notifications.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 notificationUrl = process.env.NOTIFICATION_URL
const request = require('request')
const hostname = process.env.HOSTNAME
const notify = function (payload) {
if (notificationUrl === 'false') {
return
}
request.post({
url: notificationUrl,
body: JSON.stringify(payload)
})
}
module.exports.notifyNewChat = function (chat) {
if (!chat) {
throw new Error('Cannot notify without a chat')
}
const chatLink = `${hostname}/chat`
notify({
username: 'chat bot',
icon_emoji: ':ghost:',
text: `A new chat has been requested: by ${chat.clientName}\n<${chatLink}|Go to Chat>`
})
}
module.exports.notifyNewTicket = function (ticket) {
if (!ticket.id) {
throw new Error('Cannot notify about a ticket with no id')
}
const ticketLink = `${hostname}/view-ticket/${ticket.id}?accessToken=${ticket.accessToken}`
notify({text: `A new ticket has been opened:\n"${ticket.details.name} at room #${ticket.details.room}"\n<${ticketLink}|More Details>`})
}
module.exports.notifyNewUser = function (user) {
if (!user.id) {
throw new Error('Cannot notify about a user with no id')
}
notify({text: `A new user has registered: ${user.firstName} ${user.lastName}`})
}