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="#general",
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 or newer 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/v2
Build a message
package main
import (
"context"
"os"
slackblocks "github.com/nicklambourne/slackblocks/go/v2"
slack "github.com/slack-go/slack"
)
func main() {
client := slack.New(os.Getenv("SLACK_API_TOKEN"))
_, _, err := client.PostMessageContext(
context.Background(),
os.Getenv("SLACK_CHANNEL_ID"),
slack.MsgOptionText("Hello from slackblocks!", false),
slack.MsgOptionBlocks(
slackblocks.NewSectionBlock().Text("Hello, world!"),
),
)
if err != nil {
panic(err)
}
}
The block builder implements slack.Block and validates when slack-go marshals it, before the request is sent. The channel and fallback text stay in slack-go, where its other message options can be added normally. Use NewMessage().Build() instead when you need a complete JSON-compatible Object for another client.
Install the artifact
Java 17 or newer is required. Add slackblocks and the official Slack Java SDK client to your Maven project:
<dependency>
<groupId>io.github.nicklambourne</groupId>
<artifactId>slackblocks</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.slack.api</groupId>
<artifactId>slack-api-client</artifactId>
<version>1.51.0</version>
</dependency>
Build and send a message
import com.slack.api.Slack;
import com.slack.api.methods.MethodsClient;
import com.slack.api.methods.request.chat.ChatPostMessageRequest;
import io.github.nicklambourne.slackblocks.block.SectionBlock;
import java.util.List;
MethodsClient client = Slack.getInstance().methods(System.getenv("SLACK_API_TOKEN"));
SectionBlock block = SectionBlock.builder().markdownText("Hello, world!").build();
client.chatPostMessage(ChatPostMessageRequest.builder()
.channel("C0123456")
.text("Hello from slackblocks!")
.blocks(List.of(block))
.build());
build() validates the completed value and returns an immutable object. Blocks implement the Slack SDK's LayoutBlock directly, so the channel, fallback text, threading, and other delivery options remain on the SDK request where Java developers expect them.
Install the package
.NET 8 or newer is required. Add slackblocks to your project:
dotnet add package Slackblocks
Build and send a message
using System.Net.Http.Headers;
using System.Text;
using Slackblocks.Blocks;
using Slackblocks.Payloads;
var message = new MessagePayload(
"C0123456",
text: "Hello from slackblocks!",
blocks: [new SectionBlock(text: "Hello, world!")]);
using var http = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Post, "https://slack.com/api/chat.postMessage")
{
Content = new StringContent(message.ToJson(), Encoding.UTF8, "application/json"),
};
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("SLACK_BOT_TOKEN"));
using var response = await http.SendAsync(request);
response.EnsureSuccessStatusCode();
Each constructor validates its arguments and returns an immutable value. MessagePayload also checks the message as a whole, including the 50-block limit and which blocks messages accept, before any request is made. Slack reports Web API errors in the response body's ok and error fields, so check those as well as the HTTP status.
Install the gem
MRI Ruby 3.3 or newer is required. After the coordinated Ruby release:
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.
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.