Button element
Example:
Fields
| Field | Type | Description | Required? |
|---|---|---|---|
type | String | The type of element. In this case type is always button. | Required |
text | Object | A text object that defines the button's text. Can only be of type: plain_text. text may truncate with ~30 characters. Maximum length for the text in this field is 75 characters. | Required |
action_id | String | An identifier for this action. You can use this when you receive an interaction payload to identify the source of the action. Should be unique among all other action_ids in the containing block. Maximum length is 255 characters. | Optional |
url | String | A URL to load in the user's browser when the button is clicked. Maximum length is 3000 characters. If you're using url, you'll still receive an interaction payload and will need to send an acknowledgement response. | Optional |
value | String | The value to send along with the interaction payload. Maximum length is 2000 characters. | Optional |
style | String | Decorates buttons with alternative visual color schemes. Use this option with restraint.primary gives buttons a green outline and text, ideal for affirmation or confirmation actions. primary should only be used for one button within a set.danger gives buttons a red outline and text, and should be used when the action is destructive. Use danger even more sparingly than primary.If you don't include this field, the default button style will be used. | Optional |
confirm | Object | A confirm object that defines an optional confirmation dialog after the button is clicked. | Optional |
accessibility_label | String | A label for longer descriptive text about a button element. This label will be read out by screen readers instead of the button text object. Maximum length is 75 characters. | Optional |
agent_prompt | String | A prompt to hand off to Slackbot, Slack's AI assistant, when the button is clicked. Any app can set this field. When the user who clicks the button has Slackbot AI available to them, clicking opens Slackbot seeded with this prompt instead of sending an interaction payload to your app; otherwise the button sends a standard interaction payload. Maximum length is 4000 characters. | Optional |
Examples
A regular interactive button:
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Click Me"
},
"value": "click_me_123",
"action_id": "button"
}
A button with a primary style attribute:
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Save"
},
"style": "primary",
"value": "click_me_123",
"action_id": "button"
}
A link button:
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Link Button"
},
"url": "https://docs.slack.dev/block-kit"
}
A button that hands off to Slackbot with a pre-filled prompt:
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Summarize with Slackbot"
},
"action_id": "summarize_incident",
"agent_prompt": "Summarize this incident and suggest next steps."
}
agent_prompt behavior depends on the userAny app can attach an agent_prompt. Whether it takes effect depends on the person who clicks the button, not the app that sent it: if the user has Slackbot AI available, clicking opens Slackbot seeded with the prompt and no interaction payload is sent. Otherwise the button falls back to sending a standard interaction payload. Keep an action_id on the button and handle that payload as usual so the button still works for everyone.
The button element must be used inside either the section or actions block, like this:
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "This is a section block with a button."
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Click Me"
},
"value": "click_me_123",
"action_id": "button"
}
},
{
"type": "actions",
"block_id": "actionblock789",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Primary Button"
},
"style": "primary",
"value": "click_me_456"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Link Button"
},
"url": "https://api.slack.com/block-kit"
}
]
}
]
}