Approval request with action buttons
Every language builds the same message: a deployment question, Approve/Reject actions carrying release-42, and a Details link. The application authenticates and acknowledges callbacks through HTTP or Socket Mode and implements the approve/reject actions. No request is sent by these examples.
Output
Local preview of the selected language’s tested example. Slack client appearance may differ; controls here do not send requests.
Approve deployment?
Serialized output
{
"channel": "C1",
"mrkdwn": true,
"blocks": [
{
"type": "section",
"block_id": "<generated-block-id>",
"text": {
"type": "mrkdwn",
"text": "Approve deployment?"
}
},
{
"type": "actions",
"block_id": "<generated-block-id>",
"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": "Details"
},
"action_id": "details",
"url": "https://approvals.example.com/release-42"
}
]
}
],
"text": "Approval requested"
}
Code
Shared example contract: The same release-42 approval message in every language: Approve, Reject and Details, with matching actions and fallback text.
from slackblocks import ActionsBlock, Button, Message, SectionBlock
message = Message(channel="C1", text="Approval requested", blocks=[
SectionBlock("Approve deployment?"),
ActionsBlock(elements=[
Button(text="Approve", action_id="approve", value="release-42", style="primary"),
Button(text="Reject", action_id="reject", value="release-42", style="danger"),
Button(text="Details", action_id="details", url="https://approvals.example.com/release-42"),
]),
])
print(message.json())
import * as S from "@nicklambourne/slackblocks";
const message = S.Message().channel("C1").text("Approval requested").blocks(
S.SectionBlock().text("Approve deployment?"),
S.ActionsBlock().elements(
S.Button().text("Approve").actionId("approve").value("release-42").style("primary"),
S.Button().text("Reject").actionId("reject").value("release-42").style("danger"),
S.Button().text("Details").actionId("details").url("https://approvals.example.com/release-42"),
),
).build();
console.log(JSON.stringify(message));
package main
import (
"encoding/json"
s "github.com/nicklambourne/slackblocks/go/v4"
"os"
)
func main() {
value, err := s.NewMessage().Channel("C1").Text("Approval requested").Blocks(
s.NewSectionBlock().Text("Approve deployment?"),
s.NewActionsBlock().Elements(
s.NewButton().Text("Approve").ActionID("approve").Value("release-42").Style("primary"),
s.NewButton().Text("Reject").ActionID("reject").Value("release-42").Style("danger"),
s.NewButton().Text("Details").ActionID("details").URL("https://approvals.example.com/release-42"),
),
).Build()
if err != nil {
panic(err)
}
if err := json.NewEncoder(os.Stdout).Encode(value); err != nil {
panic(err)
}
}
import io.github.nicklambourne.slackblocks.*;
import io.github.nicklambourne.slackblocks.block.*;
import io.github.nicklambourne.slackblocks.component.*;
import io.github.nicklambourne.slackblocks.element.*;
import io.github.nicklambourne.slackblocks.object.*;
import io.github.nicklambourne.slackblocks.payload.*;
import java.util.List;
import java.util.Map;
public final class Recipe {
public static void main(String[] args) throws Exception {
var value = MessagePayload.builder().channel("C1").text("Approval requested").blocks(
SectionBlock.builder().markdownText("Approve deployment?").build(),
ActionsBlock.builder().elements(
ButtonElement.builder().text("Approve").actionId("approve").value("release-42").style(ButtonStyle.PRIMARY).build(),
ButtonElement.builder().text("Reject").actionId("reject").value("release-42").style(ButtonStyle.DANGER).build(),
ButtonElement.builder().text("Details").actionId("details").url("https://approvals.example.com/release-42").build()).build()).build();
System.out.println(value.toJson());
}
}
using System;
using System.Collections.Generic;
using Slackblocks;
using Slackblocks.Blocks;
using Slackblocks.Components;
using Slackblocks.Elements;
using Slackblocks.Objects;
using Slackblocks.Payloads;
var value = new MessagePayload("C1", text: "Approval requested", blocks: [
new SectionBlock(text: "Approve deployment?"),
new ActionsBlock(elements: [
new ButtonElement("Approve", actionId: "approve", value: "release-42", style: ButtonStyle.Primary),
new ButtonElement("Reject", actionId: "reject", value: "release-42", style: ButtonStyle.Danger),
new ButtonElement("Details", actionId: "details", url: "https://approvals.example.com/release-42"),
]),
]);
Console.WriteLine(value.ToJson());
require "slackblocks"
include Slackblocks
value = MessagePayload.new(channel: "C1", text: "Approval requested", blocks: [
SectionBlock.new(text: "Approve deployment?"),
ActionsBlock.new(elements: [
ButtonElement.new(text: "Approve", action_id: "approve", value: "release-42", style: ButtonStyle::PRIMARY),
ButtonElement.new(text: "Reject", action_id: "reject", value: "release-42", style: ButtonStyle::DANGER),
ButtonElement.new(text: "Details", action_id: "details", url: "https://approvals.example.com/release-42")
])
])
puts value.to_json
Your interaction handler matches the action ID and reads the request ID from the button value.
use slackblocks::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let actions = ActionsBlock::builder()
.element(
ButtonElement::builder()
.text("Approve")
.action_id("approve")
.value("release-42")
.style(ButtonStyle::Primary)
.build()?,
)
.element(
ButtonElement::builder()
.text("Reject")
.action_id("reject")
.value("release-42")
.style(ButtonStyle::Danger)
.build()?,
)
.element(ButtonElement::builder().text("Details").action_id("details").url("https://approvals.example.com/release-42").build()?)
.build()?;
let message = MessagePayload::builder("C1")
.text("Approval requested")
.block(
SectionBlock::builder()
.text("Approve deployment?")
.build()?,
)
.block(actions)
.build()?;
println!("{}", serde_json::to_string(&message)?);
Ok(())
}
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Slackblocks as S;
$message = new S\MessagePayload(channel: 'C1', text: 'Approval requested', blocks: [
new S\SectionBlock('Approve deployment?'),
new S\ActionsBlock(elements: [
new S\ButtonElement(text: 'Approve', actionId: 'approve', value: 'release-42', style: S\ButtonStyle::Primary),
new S\ButtonElement(text: 'Reject', actionId: 'reject', value: 'release-42', style: S\ButtonStyle::Danger),
new S\ButtonElement(text: 'Details', actionId: 'details', url: 'https://approvals.example.com/release-42'),
]),
]);
echo $message->toJson();
alias Slackblocks.{Message, Blocks, Elements.Button}
Message.new!(channel: "C1", text: "Approval requested", blocks: [
Blocks.Section.new!(text: "Approve deployment?"),
Blocks.Actions.new!(elements: [
Button.new!(text: "Approve", action_id: "approve", value: "release-42", style: :primary),
Button.new!(text: "Reject", action_id: "reject", value: "release-42", style: :danger),
Button.new!(text: "Details", action_id: "details", url: "https://approvals.example.com/release-42")
])
]) |> Slackblocks.to_map!()
{-# LANGUAGE OverloadedStrings #-}
import Data.Aeson (encode)
import qualified Data.Map.Strict as Map
import Slackblocks
example = do
question <- buildMarkdownText (markdownText "Approve deployment?")
section <- buildSectionBlock (sectionBlock {sectionBlockText = Just (markdownTextAsText question)})
yes <- buildPlainText (plainText "Approve")
no <- buildPlainText (plainText "Reject")
approve <- buildButtonElement ((buttonElement yes) {buttonElementActionId = Just "approve", buttonElementValue = Just "release-42", buttonElementStyle = Just ButtonStylePrimary})
reject <- buildButtonElement ((buttonElement no) {buttonElementActionId = Just "reject", buttonElementValue = Just "release-42", buttonElementStyle = Just ButtonStyleDanger})
label <- buildPlainText (plainText "Details")
details <- buildButtonElement ((buttonElement label) {buttonElementActionId = Just "details", buttonElementUrl = Just "https://approvals.example.com/release-42"})
actions <- buildActionsBlock (actionsBlock [buttonElementAsElement approve, buttonElementAsElement reject, buttonElementAsElement details])
buildMessagePayload ((messagePayload "C1") {messagePayloadText = Just "Approval requested", messagePayloadBlocks = Just [sectionBlockAsBlock section, actionsBlockAsBlock actions]})