-
Notifications
You must be signed in to change notification settings - Fork 1
/
interactions.js
58 lines (52 loc) · 2.02 KB
/
interactions.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
const { createMessageAdapter } = require('@slack/interactive-messages')
const slackSigningSecret = process.env.SLACK_SIGNING_SECRET
const slackInteractions = createMessageAdapter(slackSigningSecret)
const articleOrBookButton = require('./elements/articleOrBookButton.json')
const respondToButtons = require('./respondToButtons')
module.exports.listenForInteractions = function (app) {
app.use('/interactions', slackInteractions.requestListener())
}
slackInteractions.action({ type: 'select' }, (payload, respond) => {
respondToSelectDropdown(payload, respond)
})
slackInteractions.action({ type: 'button' }, (payload, respond) => {
respondToButtons.respond(payload, respond)
})
function respondToSelectDropdown(payload, respond) {
const selectedOption = payload.actions[0].selected_options[0].value
if (payload.callback_id == 'subjects') {
switch (selectedOption) {
case 'anti_racism':
text = 'You selected anti racism.'
callbackId = 'anti_racism_article_book'
respondWithArticleOrBookNoButton(text, callbackId, respond)
break
case 'anti_sexism':
text = 'You selected anti sexism.'
callbackId = 'anti_sexism_article_book'
respondWithArticleOrBookNoButton(text, callbackId, respond)
break
case 'lgbtq_allyship':
text = 'You selected LGBTQ+ Allyship.'
callbackId = 'lgbtq_allyship_article_book'
respondWithArticleOrBookNoButton(text, callbackId, respond)
break
case 'autism_allyship':
text = 'You selected autism allyship.'
callbackId = 'autism_allyship_article_book'
respondWithArticleOrBookNoButton(text, callbackId, respond)
break
}
}
// Return a replacement message
return { text: 'Processing...' }
}
function respondWithArticleOrBookNoButton(text, callbackId, respond) {
articleOrBookButton.callback_id = callbackId
articleOrBookButton.text = 'Do you prefer an article or a book?'
respond({
text: text,
attachments: [articleOrBookButton],
replace_original: true
})
}