Last active
February 25, 2021 18:24
-
-
Save sweetyclem/9148c7334b90997c54de5c8cfd52a4d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { createMessageAdapter } = require('@slack/interactive-messages') | |
const slackSigningSecret = process.env.SLACK_SIGNING_SECRET | |
const slackInteractions = createMessageAdapter(slackSigningSecret) | |
const articleOrBookButton = require('./elements/articleOrBookButton.json') | |
module.exports.listenForInteractions = function (app) { | |
app.use('/interactions', slackInteractions.requestListener()) | |
} | |
slackInteractions.action({ type: 'select' }, (payload, respond) => { | |
return respondToSelectDropdown(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 | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment