SW engineering, engineering management and the business of software

subscribe for more
stuff like this:

Making a Slack App/Interaction/Bot in 2021

Building a modern slack bot requires a bit of learning. There’s a lot to unpack and many different ways for a third-party app to interact with the Slack platform.

Types of Slack bots/APIs/interactions

  • Classic bot: (aka RTM, real time messaging bot): web socket based, legacy
  • Events API bot: webhook or websocket based.
  • Web API: a large REST API to get at the users, messages and their metadata
    • You call the Web API with different styles of Oath Tokens:
      • Bot user token
        • You call the Web API on behalf of the bot (app). posting will show up as a message from the bot. and read type commands need to have the appropriate privileges and OAuth scopes
      • User token
        • You call the Web API on behalf of the user. This means that Web API request bearing this token are basically done as the user. Any read-type commands are only allowed if the user has permissions for that group/channel/dm, etc. posting a messages posts as that user.
  • Shortcuts:
    • Global shortcut: These are triggered by the little lightning bolt icon in the chat text window (to the left of the formatting widgets)
    • Message shortcut: These are triggered by a user tapping on the the three dots next to a message
    • When a user initiations a shortcut, Slack will post to your Interactive Endpoint webhook.
  • Slash commands: command that are triggered by a user entering a specific command with a slash prefix in the chat window. Slack will then post to your slash command webhook.
  • Workflows: no-code. Setup triggers and steps to automate certain types of chat interactions.

Places of interaction

The relevant Slack API documentation is the Surfaces page.

  • In the conversation stream
    • Any bot or app with the right permissions can read and write chat messages.
  • Modals
    • Using block kit, an app can pop up a modal view directly in the Slack window and present info or interact with the user via pre-specified block widgets.
  • Home Tab
    • Apps may create a home tab. This is like a dedicated page for the app to interact with the user in the Apps section of the sidebar (typically below the list of channels)

What can an app do

The basic stuff is post messages.

Dumb posting, is a bot or app that just posts without needing to know anything about the actual messages. You see this commonly with apps that have a “post notification to slack” type of feature.

If you want to get the firehose from a channel or workspace, you need the Events API. (Or a classic bot using the RTM API, but that’s considered legacy at this time).

You can do some interesting things with workflows. But there are inherent limitations to a no-code solution.

Slash commands and shortcuts are usually the first place an app will start with if there is user action required. The simple case of user enters slash command and app posts something to the channel (ala gyphy) is fairly simple to implement.

More advance interaction is usually done with modal views. The Block Kit api is fairly robust and there’s a nice playground interface to experiment with.

In general, the best and most sophisticated apps will mix and match functionality so that the interaction and user experience feels “natural”.



in lieu of comments, you should follow me on twitter at twitter/amattn and on twitch.tv at twitch.tv/amattn. I'm happy to chat about content here anytime.


the fine print:
aboutarchivemastodontwittertwitchconsulting or speaking inquiries
© matt nunogawa 2010 - 2023 / all rights reserved