|
| 1 | +# Modals |
| 2 | + |
| 3 | +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 Slack app. |
| 4 | + |
| 5 | +Let's take a look at the technologies we'll use in this tutorial: |
| 6 | + |
| 7 | +* Glitch is a online IDE that allows you to collaboratively work on code and host your own server. Glitch should only be used for development purposes and should not be used in production. |
| 8 | +* We'll use Python in conjunction with our [Bolt for Python](https://github.com/SlackAPI/bolt-python) SDK. |
| 9 | +* [Block Kit](https://api.slack.com/block-kit/building) is a UI framework for Slack apps that allows you to create beautiful, interactive messages within Slack. If you've ever seen a message in Slack with buttons or a select menu, that's Block Kit. |
| 10 | +* Modals are similar to a pop-up window that displays right in Slack. They grab the attention of the user, and are normally used to prompt users to provide some kind of information or input. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## Final product overview {#final_product} |
| 15 | +If you follow through with the extra credit tasks, your final app will look like this: |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## The process {#steps} |
| 22 | + |
| 23 | +1. [Create a new app](https://api.slack.com/apps/new) and name it whatever you like. |
| 24 | + |
| 25 | +2. [Remix (or clone)](https://glitch.com/edit/#!/remix/intro-to-modals-bolt) the Glitch template. |
| 26 | + |
| 27 | +Here's a copy of what the modal payload looks like — this is what powers the modal. |
| 28 | + |
| 29 | +```json |
| 30 | +{ |
| 31 | + "type": "modal", |
| 32 | + "callback_id": "gratitude-modal", |
| 33 | + "title": { |
| 34 | + "type": "plain_text", |
| 35 | + "text": "Gratitude Box", |
| 36 | + "emoji": true |
| 37 | + }, |
| 38 | + "submit": { |
| 39 | + "type": "plain_text", |
| 40 | + "text": "Submit", |
| 41 | + "emoji": true |
| 42 | + }, |
| 43 | + "close": { |
| 44 | + "type": "plain_text", |
| 45 | + "text": "Cancel", |
| 46 | + "emoji": true |
| 47 | + }, |
| 48 | + "blocks": [ |
| 49 | + { |
| 50 | + "type": "input", |
| 51 | + "block_id": "my_block", |
| 52 | + "element": { |
| 53 | + "type": "plain_text_input", |
| 54 | + "action_id": "my_action" |
| 55 | + }, |
| 56 | + "label": { |
| 57 | + "type": "plain_text", |
| 58 | + "text": "Say something nice!", |
| 59 | + "emoji": true |
| 60 | + } |
| 61 | + } |
| 62 | + ] |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +3. Find the base path to your server by clicking **Share**, then copy the Live site link. |
| 67 | + |
| 68 | +  |
| 69 | + |
| 70 | +4. 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. |
| 71 | + |
| 72 | +  |
| 73 | + |
| 74 | +5. 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. |
| 75 | + |
| 76 | +  |
| 77 | + |
| 78 | +6. Select **Install App**. After you've done this, you'll see a **Bot User OAuth Access Token**, copy this. |
| 79 | + |
| 80 | +7. 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. |
| 81 | + |
| 82 | +  |
| 83 | + |
| 84 | +8. Test by heading to Slack and typing `/thankyou`. |
| 85 | + |
| 86 | +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](https://app.slack.com/block-kit-builder). |
| 87 | + |
| 88 | +### Extra credit {#extra_credit} |
| 89 | + |
| 90 | +For a little extra credit, let's post the feedback we received in a channel. |
| 91 | + |
| 92 | +1. Add the `chat:write` bot scope, which allows your bot to post messages within Slack. You can do this in the **OAuth & Permissions** section for your Slack app. |
| 93 | +2. Reinstall your app to apply the scope. |
| 94 | +3. Create a channel and name it `#thanks`. 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`. |
| 95 | +4. Add your bot to the channel by typing the command `/invite @your_bots_name`. |
| 96 | +5. Uncomment the `Extra Credit` code within your Glitch project and make sure to replace `your_channel_id` with the ID above. |
| 97 | +6. Test it out by typing `/thankyou`, and watching all the feedback come into your channel! |
| 98 | + |
| 99 | +## Next steps {#next-steps} |
| 100 | + |
| 101 | +If you want to learn more about Bolt for Python, refer to the [Getting Started guide](/bolt-python/getting-started). |
0 commit comments