Quick Start
Install slackblocks and build your first valid Block Kit message. The language selector in the top navigation controls the instructions and examples on this page.
Install the package
Python 3.10 or newer is required.
pip install slackblocks
Build a message
from slackblocks import Message, SectionBlock
message = Message(
channel="C0123456",
text="Hello from slackblocks!",
blocks=[SectionBlock("Hello, world!")],
)
print(message.json())
Message validates the payload as it is constructed and renders it as Slack-compatible JSON. The text value is the plain-text fallback Slack uses for notifications and accessibility.
Install the package
Node.js ^20.19.0 || >=22.12.0 (20.19+ within Node 20, or 22.12+) is required. The package is ESM-only.
pnpm add @nicklambourne/slackblocks
Build a message
import { Message, SectionBlock } from "@nicklambourne/slackblocks";
const payload = Message()
.channel("C0123456")
.text("Hello from slackblocks!")
.blocks(SectionBlock().text("Hello, world!"))
.build();
console.log(JSON.stringify(payload, null, 2));
Each builder uses typed camelCase setters. .build() validates the completed
payload and returns the plain snake_case object expected by Slack.
Install the module
Go 1.22 or newer is required.
mkdir slackblocks-hello
cd slackblocks-hello
go mod init example.com/slackblocks-hello
go get github.com/nicklambourne/slackblocks/go/v4
Build a message
package main
import (
"encoding/json"
"os"
slackblocks "github.com/nicklambourne/slackblocks/go/v4"
)
func main() {
payload, err := slackblocks.NewMessage().
Channel("C0123456").
Text("Hello from slackblocks!").
Blocks(slackblocks.NewSectionBlock().Text("Hello, world!")).
Build()
if err != nil { panic(err) }
if err := json.NewEncoder(os.Stdout).Encode(payload); err != nil { panic(err) }
}
Build() validates and returns a JSON-compatible Object. No request is sent. When using slack-go, block builders also implement its slack.Block interface directly; see Sending Messages.
Install the artifact
Java 17 or newer is required. Add the core artifact to your Maven project:
<dependency>
<groupId>io.github.nicklambourne</groupId>
<artifactId>slackblocks</artifactId>
<version>4.0.0</version>
</dependency>
Build a message
import io.github.nicklambourne.slackblocks.SlackblocksJson;
import io.github.nicklambourne.slackblocks.block.SectionBlock;
import io.github.nicklambourne.slackblocks.payload.MessagePayload;
var message = MessagePayload.builder()
.channel("C0123456")
.text("Hello from slackblocks!")
.blocks(SectionBlock.builder().markdownText("Hello, world!").build())
.build();
System.out.println(SlackblocksJson.write(message));
build() validates and returns an immutable value. No client or token is needed for this example. Blocks also implement the official Slack SDK’s LayoutBlock interface for native handoff; see Sending Messages.
Install the package
.NET 8 or newer is required. Add slackblocks to your project:
dotnet add package Slackblocks
Build a message
using Slackblocks.Blocks;
using Slackblocks.Payloads;
var message = new MessagePayload(
"C0123456",
text: "Hello from slackblocks!",
blocks: [new SectionBlock(text: "Hello, world!")]);
Console.WriteLine(message.ToJson());
Each constructor validates its arguments and returns an immutable value. MessagePayload checks the complete message; ToJson() prints it without sending a request.
Install the gem
MRI Ruby 3.3 or newer is required:
gem install slackblocks
Build a message
require "slackblocks"
message = Slackblocks::MessagePayload.new(
channel: "C01234567",
text: "Hello from slackblocks!",
blocks: [Slackblocks::SectionBlock.new(text: "Hello, world!")]
)
puts message.to_json
text is the plain-text fallback for notifications and accessibility. Values are validated when constructed, and to_json emits Slack-compatible JSON.
Install the crate
Rust 1.85 or newer is required; the crate uses edition 2024.
cargo add slackblocks@4.0.0
cargo add serde_json
Build a message
use slackblocks::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let message = MessagePayload::builder("C01234567")
.text("Hello from slackblocks!")
.block(SectionBlock::builder().text("Hello, world!").build()?)
.build()?;
println!("{}", serde_json::to_string(&message)?);
Ok(())
}
Builders consume themselves and return Result from build(). Use ? to
propagate ValidationError. Built values own their data; getters borrow it.
text on the message is Slack's notification and accessibility fallback.
Install the package
PHP 8.2 or newer is required, on a 64-bit build with the JSON and PCRE extensions. The core has no third-party runtime dependencies. Composer 2 handles PSR-4 autoloading.
PHP support begins with coordinated version 2.7.0. Install the Packagist package:
composer require nicklambourne/slackblocks:^4.0
Stable installs download a PHP-only archive. Composer's --prefer-source option
checks out the monorepo and is required for unreleased development branches.
Keep vendor/autoload.php in your application's entry point and use
declare(strict_types=1) in your calling PHP files. PHP 8.2's named arguments,
readonly classes and backed enums are the public API; named parameter spelling
is part of compatibility.
Build a message
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Slackblocks as S;
$message = new S\MessagePayload(
channel: 'C0123456789',
text: 'Build #482 passed',
blocks: [
new S\HeaderBlock('Build #482 passed'),
new S\SectionBlock(fields: ["*Branch*\n`main`", "*Tests*\n1,247 passed"]),
new S\ActionsBlock(elements: [
new S\ButtonElement(text: 'View build', actionId: 'view', url: 'https://ci.example.com/482'),
]),
],
);
echo $message->toJson();
Send the resulting payload with JoliCode, cURL, or Laravel.
Install
Elixir 1.16.3+, compatible OTP 26.2+ and a 64-bit runtime are required.
Install {:slackblocks, "~> 4.0"} from Hex; follow Installation
for setup and the existing-Jason rebuild step.
Build a message
alias Slackblocks.{Message, Blocks, Elements}
message = Message.new!(
channel: "C0123456789",
text: "Build #482 passed",
blocks: [
Blocks.Header.new!(text: "Build #482 passed"),
Blocks.Section.new!(fields: ["*Branch*\n`main`", "*Tests*\n1,247 passed"]),
Blocks.Actions.new!(elements: [
Elements.Button.new!(text: "View build", action_id: "view", url: "https://ci.example.com/482")
])
]
)
Slackblocks.to_map!(message)
Send the validated string-keyed map with the community Slack client or Req; see Sending Messages. Pattern matching, immutable edits and tagged errors are covered in the Recipe Book.
Install
Add slackblocks >= 4.0 && < 4.1 to your application's Cabal build-depends,
then run cabal update and cabal build. See Installation.
GHC 9.6.7 is the minimum tested compiler.
Build a message
{-# LANGUAGE OverloadedStrings #-}
import Data.Aeson (encode)
import qualified Data.Map.Strict as Map
import Slackblocks
example :: Result MessagePayload
example = do
title <- buildPlainText (plainText "Build #482 passed")
heading <- buildHeaderBlock (headerBlock title)
branch <- buildMarkdownText (markdownText "*Branch*\n`main`")
tests <- buildMarkdownText (markdownText "*Tests*\n1,247 passed")
details <-
buildSectionBlock
( sectionBlock
{ sectionBlockFields = Just (map markdownTextAsText [branch, tests])
}
)
label <- buildPlainText (plainText "View build")
button <-
buildButtonElement
( (buttonElement label)
{ buttonElementActionId = Just "view",
buttonElementUrl = Just "https://ci.example.com/482"
}
)
actions <- buildActionsBlock (actionsBlock [buttonElementAsElement button])
buildMessagePayload
( (messagePayload "C0123456789")
{ messagePayloadText = Just "Build #482 passed",
messagePayloadBlocks = Just [headerBlockAsBlock heading, sectionBlockAsBlock details, actionsBlockAsBlock actions]
}
)
Factories create editable field records. build… validates and returns Either
with structured errors; the do block stops on the first failed construction.
On Right payload, Data.Aeson.encode payload produces the complete wire JSON.
Keep the fallback text useful for notifications and accessibility. Sending is
application-owned; see Sending Messages.
Where to go next
slackblocks constructs the Block Kit content while the established Slack client handles delivery. Continue with Sending Messages for more client options, or explore Using Blocks to build richer layouts.
For package-manager alternatives and environment details, see Installation.
Send the message when your app is ready
The examples above construct and print JSON without network access. To deliver it, follow Sending Messages: choose a client, configure a bot token with chat:write, select a channel ID the app can access, and ensure the bot has joined it where required. Check both transport failures and Slack’s ok/error response. For incoming webhooks use the app’s configured webhook URL; interactions and views have different request envelopes and lifecycle requirements.