What this post covers
Our earlier post on the Slack Events API and request signing covered how Slack delivers events to your request URL and how to verify them. This post covers the other half of a Slack app: things users trigger on purpose. That means slash commands, interactive Block Kit components such as buttons, and modals.
These features share a small set of rules about timing and one-time tokens. Everything below is based on the official Slack developer documentation at the time of writing. Slack changes its platform over time, so check the sources at the end before you rely on a specific limit.
The flow in one paragraph
A user types a slash command or clicks a button. Slack sends an HTTP POST to your app's Request URL. Your app must answer with HTTP 200 within 3 seconds, and that answer can already include a message. The payload also includes two short-lived tools for doing more: a response_url, which lets you post messages back into the conversation after the fact, and a trigger_id, which lets you open a modal. If the user submits the modal, Slack sends another POST, and you again have 3 seconds to accept it, reject it with validation errors, or swap in a new view.
Setting up the two Request URLs
In your app settings there are two places to configure:
- Slash Commands (under Features). Each command has its own name, Request URL, short description and usage hint. Slack's documentation notes that commands are not namespaced: if two installed apps use the same command name, Slack invokes the one installed most recently. Pick a name tied to your app rather than a generic word.
- Interactivity & Shortcuts. One Request URL receives
block_actionspayloads (buttons, menus), shortcut payloads, and modalview_submissionandview_closedpayloads. Your app tells them apart by thetypefield.
If you use Bolt, both URLs can point at the same endpoint, which by default is /slack/events in Bolt for Python. Slack requires HTTPS for apps with public distribution and does not allow self-signed certificates, and recommends HTTPS for single-workspace apps as well. A stable domain makes this simpler, especially when you run separate development and production apps. You can register one with Namecheap domains and follow our guide to a custom domain and HTTPS for your bot.
If you cannot expose a public URL at all, Socket Mode delivers the same payloads over a WebSocket. Slack states that Socket Mode apps are not currently allowed in the Slack Marketplace, so check our Socket Mode vs HTTP comparison before you choose.
Whichever URL you use, verify every request with your signing secret before acting on it. The verification steps are the same ones described in our request signing post.
What a slash command sends
A slash command arrives as application/x-www-form-urlencoded, not JSON. The fields you will use most:
command: the command name, useful when one URL serves several commands.text: everything after the command, as a single string. Parsing it is your job.user_id,channel_id,team_idand, on Enterprise organizations,enterprise_id.response_url: a temporary webhook URL for message responses.trigger_id: a short-lived ID for opening a modal.api_app_id: your app's ID, handy for telling development and production apps apart.
Two fields are deprecated and should not be used: token (the old verification token; use signed secrets instead) and user_name (use user_id). In general, rely on IDs and not on the *_name fields, because names can change.
If you expect mentions in the command text, turn on Escape channels, users, and links in the command settings. Slack then sends mentions as IDs, such as <@U012ABCDEF>, instead of plain names you would have to resolve yourself.
Rule 1: acknowledge within 3 seconds
Slack's documentation is explicit: the confirmation must reach Slack within 3000 milliseconds, or the user sees an operation_timeout error. The same 3-second rule applies to interaction payloads from buttons, shortcuts and modals.
The acknowledgment can be:
- An empty HTTP 200, if no reply is needed.
- Plain text, which Slack shows as a message.
- JSON with
textorblocks, plusresponse_type.
response_type controls visibility. The default is ephemeral, visible only to the user who ran the command. With in_channel, both your reply and the user's original command appear in the channel. Slack recommends always setting response_type explicitly. If you are not ready to reply yet but want the command to be visible in the channel, you can return only {"response_type": "in_channel"}.
Errors deserve special care. Do not return HTTP 500 because the user typed something invalid. The status code only tells Slack whether you received the payload. Return 200 with an ephemeral message that explains what went wrong. If the signature check fails, though, return an error and ignore the request.
Rule 2: slow work goes through response_url
Anything that may take longer than 3 seconds, such as calling an external API, querying a large database or asking a language model, should happen after the acknowledgment. When the work finishes, POST a JSON message to response_url.
According to the documentation, a response_url can be used up to 5 times within 30 minutes of receiving the payload. Past that, publish a normal message with chat.postMessage. Some useful options when posting to it:
response_type: "in_channel"posts visibly; the default is ephemeral.replace_original: truereplaces the app message that held the button the user clicked. Set it tofalsewhen you want to add a new message instead.delete_original: truedeletes the source app message.
Note that replace_original and delete_original cannot change or remove the message a user typed to run a slash command. They only apply to app messages.
Interaction payloads from global shortcuts do not include a response_url. In those cases you open a modal with the trigger_id instead.
Rule 3: trigger_id is short-lived and single-use
A trigger_id lets you open a modal with views.open. Slack documents two strict limits: triggers expire in three seconds, and they may only be used once. An expired trigger returns trigger_expired; a second use returns trigger_exchanged.
In practice this means you should call views.open first, before any slow lookups. If the modal needs data that takes time to load, open it with a short "Loading" view and fill it in afterwards with views.update, which does not need a trigger.
A modal can hold up to 3 views in its view stack. You can push a new view on top with views.push (which needs a fresh trigger_id from an interaction inside the modal) or with a response_action of push when the user submits.
Rule 4: validate modal input in the acknowledgment
When a user submits a modal, your app receives a view_submission payload. The submitted values are in view.state.values, keyed first by block_id and then by action_id. You have 3 seconds to respond, and the response controls what the user sees:
- An empty HTTP 200 closes the submitted view.
{"response_action": "errors", "errors": {"<block_id>": "message"}}keeps the modal open and shows the message next to that input block.response_action: "update"replaces the view;"push"adds a view on top;"clear"closes the whole modal.
Validation must therefore be fast. Check the input, reply with errors or close the modal, and save the slow work for after the acknowledgment.
To carry context such as the channel where the command was run, use the view's private_metadata string. Users do not see it, and Slack returns it in view_submission and block_actions payloads.
A working example with Bolt for Python
This example registers a /ticket command that opens a modal, validates the summary, posts the ticket to the channel with a button, and replaces that message when the button is clicked. The command name, IDs and text are examples. The bot needs the commands and chat:write scopes and must be a member of the channel it posts in.
import os
from slack_bolt import App
app = App(
token=os.environ["SLACK_BOT_TOKEN"],
signing_secret=os.environ["SLACK_SIGNING_SECRET"],
)
@app.command("/ticket")
def open_ticket_modal(ack, body, client):
ack() # acknowledge first
client.views_open( # then use the trigger_id right away
trigger_id=body["trigger_id"],
view={
"type": "modal",
"callback_id": "ticket_modal",
"private_metadata": body["channel_id"],
"title": {"type": "plain_text", "text": "New ticket"},
"submit": {"type": "plain_text", "text": "Create"},
"blocks": [{
"type": "input",
"block_id": "summary",
"label": {"type": "plain_text", "text": "Summary"},
"element": {"type": "plain_text_input", "action_id": "value"},
}],
},
)
@app.view("ticket_modal")
def create_ticket(ack, body, view, client):
summary = (view["state"]["values"]["summary"]["value"]["value"] or "").strip()
if len(summary) < 5:
ack(response_action="errors",
errors={"summary": "Please write at least 5 characters."})
return
ack() # closes the modal
client.chat_postMessage(
channel=view["private_metadata"],
text=f"New ticket from <@{body['user']['id']}>: {summary}",
blocks=[
{"type": "section",
"text": {"type": "mrkdwn", "text": f"*New ticket:* {summary}"}},
{"type": "actions", "elements": [{
"type": "button", "action_id": "ticket_close",
"text": {"type": "plain_text", "text": "Close"},
"value": "close",
}]},
],
)
@app.action("ticket_close")
def close_ticket(ack, body, respond):
ack()
respond(replace_original=True,
text=f"Ticket closed by <@{body['user']['id']}>.")
if __name__ == "__main__":
app.start(port=3000)
respond posts to the response_url from the button payload, so the 5-uses-in-30-minutes limit applies to it. The built-in app.start server is meant for development; for production, Bolt provides adapters for common web frameworks.
Button value fields are limited to 2000 characters and action_id to 255. Store an ID in value and keep the real data in your database. Our post on versioning callback data explains why that pays off when you change button formats later.
Serverless runtimes and lazy listeners
On platforms that stop your code once the HTTP response is sent, "acknowledge first, work later" does not work as written. Bolt for Python handles this with process_before_response=True plus lazy listeners: one function calls ack() within 3 seconds, and the functions listed in lazy run the slow work separately. Slack notes that lazy listeners exist only in Bolt for Python. In other frameworks, hand the slow work to a queue or a background worker. Our post on the ack-first pattern covers how to do that without losing work.
Checklist before you ship
- Verify the signature on every command and interaction request.
- Call
ack()first, and callviews.openbefore anything slow. - Set
response_typeexplicitly on every reply. - Return 200 with a friendly ephemeral error for bad input, never a 500.
- Validate modal input and answer with
response_action: "errors"within 3 seconds. - Move slow work to
response_url(up to 5 times in 30 minutes) orchat.postMessage. - Use IDs (
user_id,channel_id) and never the deprecateduser_nameortoken. - Give the command a name tied to your app, and answer
/yourcommand helpwith usage. - Publish a short help and privacy page your command can link to. Namecheap hosting can serve a static page like that while the app runs elsewhere, and keeping it with your domain in one Namecheap account keeps renewals in one place.
Sources
- Slack, Implementing slash commands: docs.slack.dev/interactivity/implementing-slash-commands
- Slack, Handling user interaction: docs.slack.dev/interactivity/handling-user-interaction
- Slack, Modals: docs.slack.dev/surfaces/modals
- Slack, block_actions payload: docs.slack.dev/reference/interaction-payloads/block_actions-payload
- Slack, Button element: docs.slack.dev/reference/block-kit/block-elements/button-element
- Slack, Using Socket Mode: docs.slack.dev/apis/events-api/using-socket-mode
- Bolt for Python, Acknowledging requests: docs.slack.dev/tools/bolt-python/concepts/acknowledge
- Bolt for Python, Lazy listeners (FaaS): docs.slack.dev/tools/bolt-python/concepts/lazy-listeners
- Bolt for Python, Listening to views: docs.slack.dev/tools/bolt-python/concepts/view-submissions
- Bolt for Python, Adapters: docs.slack.dev/tools/bolt-python/concepts/adapters