If you're learning about Slack apps, modals, or slash commands for the first time, you've come to the right place! In this tutorial, we'll take a look at setting up your very own server using Glitch, and using that server to run your very own Slack app.
Let's take a look at the technologies we'll use in this tutorial:
If you follow through with the extra credit tasks, your final app will look like this.
Here's a copy of what the modal payload looks like β this is what powers the modal.
{
"type": "modal",
"callback_id": "gratitude-modal",
"title": {
"type": "plain_text",
"text": "Gratitude Box",
"emoji": true
},
"submit": {
"type": "plain_text",
"text": "Submit",
"emoji": true
},
"close": {
"type": "plain_text",
"text": "Cancel",
"emoji": true
},
"blocks": [
{
"type": "input",
"block_id": "my_block",
"element": {
"type": "plain_text_input",
"action_id": "my_action"
},
"label": {
"type": "plain_text",
"text": "Say something nice!",
"emoji": true
}
}
]
}
Find the base path to your server by clicking Share, then copy the Live site link.
On your app page, navigate to Interactivity & Shortcuts. Append "/slack/events" to your base path URL and enter it into the Request URL. e.g. https://festive-harmonious-march.glitch.me/slack/events
. This allows your server to retrieve information from the modal. You can see the code for this within the Glitch project.
Create the slash command so you can access it within Slack. Navigate to the Slash Commands section and create a new command. Note the Request URL is the same link as above, e.g. https://festive-harmonious-march.glitch.me/slack/events
. The code that powers the slash command and opens a modal can be found within the Glitch project.
Select Install App. After you've done this, you'll see a Bot User OAuth Access Token, copy this.
Navigate to your Glitch project and click the .env
file where the credentials are stored, and paste your bot token where the SLACK_BOT_TOKEN
variable is shown. This allows your server to send authenticated requests to the Slack API. You'll also need to head to your app's settings page under Basic Information and copy the Signing secret to place into the SLACK_SIGNING_SECRET
variable.
Test by heading to Slack and typing /thankyou
.
All done! π You've created your first slash command using Block Kit and modals! The world is your oyster; you can create more complex modals by playing around with Block Kit Builder.
For a little extra credit, let's post the feedback we received in a channel.
Add the chat:write
bot scope, this allows your bot to post messages within Slack. You can do this in the OAuth & Permissions section for your Slack app.
Reinstall your app to apply the scope.
Create a channel and name it #thanks
. Next, get its ID by right clicking the channel name, copying the link, and copying the last part starting with the letter C
. For example, if your channel link looks like this, https://my.slack.com/archives/C123FCN2MLM, the ID is C123FCN2MLM
.
Add your bot to the channel by typing the command /invite @your_bots_name
.
Uncomment the Extra Credit
code within your Glitch project and make sure to replace your_channel_id
with the ID above.
Test it out by typing /thankyou
, and watching all the feedback come into your channel!
If you want to learn more about Bolt for Python, refer to Bolt for Python.