Introduction to Modals and Block Kit

By Jason Wong

If you're learning about Slack apps, modals or slash commands for the first time, you've come to the right place! This tutorial will go through setting up your very own server using Glitch and have that server be the backend to your very own Slack app. Let's take a look through the technologies that we'll use in this tutorial.

Glitch

Glitch is a online IDE (Integrated Development Environment) where you can collaboratively work on code and host your very own server. The second point is really important as it is a quick way to get up and running, without having to deal with figuring out which hosting solution you want for your app. Just as a note, Glitch should only be used for development purposes and should not be used in production.

Python and Bolt for Python 🐍

Python is a programming language known for being easy to read and popular among beginner coders. We'll use this in conjunction with Bolt for Python, an in-house SDK that makes it easier to build Slack apps.

Block Kit

Block Kit is a UI framework for Slack apps that allows you to have beautiful, interactive messages within Slack. If you've ever seen a message in Slack with buttons or a select menu, that's Block Kit.

Modals

Modals are similar to a pop up that happen right in Slack. They grab the attention of the user and usually ask them to provide some kind of information or input.


Final Product

If you follow through with the extra credit tasks, your final app will look like this.

remix button


Steps

  1. Create a new app, you're free to name it whatever you like.

Create a Slack app

  1. Next you'll need to remix (or clone) the Glitch template:

Remix the app template

Also, 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
      }
    }
  ]
}
  1. Find the base path to your server by clicking the "Share", then copying the Live site link.

    base link url

  2. Head back to your app page and navigate to Interactivity & Shortcuts. Append "/slack/events" to your base path URL with and enter it into the Request URL. e.g. https://festive-harmonious-march.glitch.me/slack/events. This allows for your server to retrieve information from the modal. You can see the code for this within the Glitch project under Step 4.

    interactivity URL

  3. Next, we're going to create the Slash Command so you can access it within Slack. Head over to the Slash Commands section in the left sidebar 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 up a modal can be found within the Glitch project under Step 5.

    slash command details

  4. Navigate to Install App and install.

  5. After you've done this, you'll see a Bot User OAuth Access Token, copy this.

  6. Head back to your Glitch project and click on 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 and put that into the SLACK_SIGNING_SECRET variable.

    heart icon

  7. Now that everything is set up, let's 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 and more complex modals by playing around first with the Block Kit Builder and if you have any questions please feel free to reach out to developer support at feedback@slack.com.

Extra Credit!

Now to getting the lovely feedback in channel somewhere. This part isn't required but it's nice to have so that you can actually see the feedback people are giving each other somewhere.

  1. Add the chat:write bot scope, this allows for your bot to post messages within Slack. You can do this in the OAuth & Permissions section on your Slack app.

  2. Reinstall your app to make sure the scopes are applied.

  3. Create a channel and name it #thanks. Next, get its ID by right clicking on the channel name, copying the link and taking the last section that starts with the letter C. As an example, if your channel link looks like this, https://my.slack.com/archives/C123FCN2MLM, then the ID is C123FCN2MLM.

  4. Add your bot to the channel by typing the command /invite @your_bots_name.

  5. Uncomment the Extra Credit code within your glitch and make sure to replace your_channel_id with the ID in step 2.

  6. Test it out by typing /thankyou and watch all the feedback come into your channel!

If you want to learn more about Bolt for Python, you can do that here.

Related documentation

Was this page helpful?