Skip to content

Create a Slack bot

A Slack bot is an app, two tokens, and a Socket Mode connection. Arona renders the same components as Blocks.

  1. Open the Slack API dashboard and select Create New App.
  2. Choose From scratch, name the app, and pick your workspace.
  3. Open Socket Mode and turn it on. Socket Mode needs no public URL.
  4. Create an app-level token with the connections:write scope. Copy the xapp- token.
  5. Open OAuth & Permissions. Add these bot token scopes:
    • chat:write
    • channels:history
    • groups:history
    • im:history
    • mpim:history
  6. Open Event Subscriptions and subscribe to these bot events:
    • message.channels
    • message.groups
    • message.im
    • message.mpim
  7. Select Install to Workspace. Copy the xoxb- bot token.

The history scopes let the bot read messages. chat:write lets it post the rendered message. The message events feed client.messages.

Create .env in the project root:

Terminal window
SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_APP_TOKEN=xapp-your-app-token
SLACK_PORT=3000

SLACK_PORT is the local receiver port. Socket Mode ignores it.

Terminal window
pnpm dev
src/index.ts
import { Telemetry } from "@arona/core";
import { AronaSlackClient, renderMessage } from "@arona/platform-slack";
import { NodeRuntime } from "@effect/platform-node";
import { Config, Effect, Stream } from "effect";
import { App } from "./app";
const program = Effect.gen(function* () {
const config = yield* Config.all({
token: Config.Redacted("SLACK_BOT_TOKEN"),
appToken: Config.Redacted("SLACK_APP_TOKEN"),
port: Config.Number("SLACK_PORT").pipe(Config.withDefault(3000)),
});
return yield* Effect.gen(function* () {
const client = yield* AronaSlackClient;
yield* Effect.forkChild(
client.messages.pipe(
Stream.filter((message) => "text" in message && /hi/i.test(message.text ?? "")),
Stream.runForEach((message) => renderMessage(message, App, {}).pipe(Effect.asVoid)),
),
);
yield* client.start;
return yield* Effect.never;
}).pipe(
Effect.provide(
AronaSlackClient.layer({
token: config.token,
appToken: config.appToken,
socketMode: true,
port: config.port,
}),
),
);
});
const telemetry =
process.env.NODE_ENV === "production"
? Telemetry.layerFromEnv
: Telemetry.layer({ console: true });
NodeRuntime.runMain(program.pipe(Effect.provide(telemetry)));

The client publishes every incoming message on client.messages. The example matches text that contains hi. It renders App as a thread reply.

Slack has no root block. Group more than one block in Blocks:

src/app.ts
import { Actions, Blocks, Button, Divider, Section, Text, component } from "@arona/platform-slack";
import { UiSchema } from "effect/ui";
import { Schema } from "effect";
const AppMessage = UiSchema.TaggedEnum({
ClickedIncrement: {},
ClickedReset: {},
});
/** An interactive Block Kit message with a shared counter. */
export const App = component({
name: "SlackCounter",
model: Schema.Struct({ count: Schema.Finite }),
message: AppMessage,
}).make({
init: () => ({ count: 0 }),
update: {
ClickedIncrement: ($) => $.evolve({ count: (count) => count + 1 }),
ClickedReset: ($) => $.set({ count: 0 }),
},
view: (h, model) =>
Blocks(h, {
children: [
Section(h, {
children: [Text(h, `:wave: Count: *${model.count}*`)],
}),
Divider(h),
Actions(h, {
children: [
Button(h, {
style: "primary",
onClick: AppMessage.ClickedIncrement(),
children: ["+1"],
}),
Button(h, {
style: "danger",
onClick: AppMessage.ClickedReset(),
disabled: model.count === 0,
children: ["Reset"],
}),
],
}),
],
}),
});

Composition is explicit:

  • Text and Markdown must appear inside a Section.
  • Button must appear inside Actions, or be the Section accessory.
  • Section must contain a Text or Markdown child.
  • Actions must contain at least one Button.

An invalid tree fails when the host serializes it. Arona does not silently drop or wrap a block.

The first render is a thread reply. Pass replyInThread: false to post in the channel instead:

yield * renderMessage(message, App, {}, { replyInThread: false });