Skip to main content

Approval request with action buttons

Carry a stable request identifier in action values. The application must authenticate callbacks and implement the approve/reject actions.

Output

Local preview of the selected language’s tested example. Slack client appearance may differ; controls here do not send requests.

✋ Approval needed

Requested by: Nick Deploy version 3.1.0?
Request ID: release-42
Serialized output
{
"channel": "C1",
"mrkdwn": true,
"blocks": [
{
"type": "header",
"block_id": "<generated-block-id>",
"text": {
"type": "plain_text",
"text": ":hand: Approval needed"
}
},
{
"type": "section",
"block_id": "<generated-block-id>",
"text": {
"type": "mrkdwn",
"text": "*Requested by:* Nick\n\nDeploy version 3.1.0?"
}
},
{
"type": "actions",
"block_id": "approval:release-42",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Approve"
},
"action_id": "approve",
"style": "primary",
"value": "release-42"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Reject"
},
"action_id": "reject",
"style": "danger",
"value": "release-42"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View details"
},
"action_id": "details",
"url": "https://approvals.example.com/release-42"
}
]
},
{
"type": "context",
"block_id": "<generated-block-id>",
"elements": [
{
"type": "mrkdwn",
"text": "Request ID: `release-42`"
}
]
}
],
"text": "Approval requested by Nick"
}

Code​

An approval flow with approve, reject and details buttons. The buttons carry value or action_id so your interaction handler can identify them.

from slackblocks import (
ActionsBlock,
Button,
ContextBlock,
HeaderBlock,
Message,
SectionBlock,
Text,
)


def approval_request(*, channel: str, request_id: str, requester: str, summary: str) -> Message:
return Message(
channel=channel,
text=f"Approval requested by {requester}",
blocks=[
HeaderBlock(":hand: Approval needed"),
SectionBlock(text=f"*Requested by:* {requester}\n\n{summary}"),
ActionsBlock(
block_id=f"approval:{request_id}",
elements=[
Button(
text="Approve",
action_id="approve",
value=request_id,
style="primary",
),
Button(
text="Reject",
action_id="reject",
value=request_id,
style="danger",
),
Button(
text="View details",
action_id="details",
url=f"https://approvals.example.com/{request_id}",
),
],
),
ContextBlock(
elements=[Text(f"Request ID: `{request_id}`")],
),
],
)
print(approval_request(channel="C1", request_id="release-42", requester="Nick", summary="Deploy version 3.1.0?").json())

When the user clicks a button, Slack will POST an interaction payload to your app. Match on action_id (approve / reject / details) and pull the request ID from block_id or the button's value.