Create a Slack bot
A Slack bot is an app, two tokens, and a Socket Mode connection. Arona renders the same components as Blocks.
Create the app
Section titled “Create the app”- Open the Slack API dashboard and select Create New App.
- Choose From scratch, name the app, and pick your workspace.
- Open Socket Mode and turn it on. Socket Mode needs no public URL.
- Create an app-level token with the
connections:writescope. Copy thexapp-token. - Open OAuth & Permissions. Add these bot token scopes:
chat:writechannels:historygroups:historyim:historympim:history
- Open Event Subscriptions and subscribe to these bot events:
message.channelsmessage.groupsmessage.immessage.mpim
- 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.
Configure the environment
Section titled “Configure the environment”Create .env in the project root:
SLACK_BOT_TOKEN=xoxb-your-bot-tokenSLACK_APP_TOKEN=xapp-your-app-tokenSLACK_PORT=3000SLACK_PORT is the local receiver port. Socket Mode ignores it.
Run the bot
Section titled “Run the bot”pnpm devimport { 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.
Render blocks
Section titled “Render blocks”Slack has no root block. Group more than one block in Blocks:
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:
TextandMarkdownmust appear inside aSection.Buttonmust appear insideActions, or be theSectionaccessory.Sectionmust contain aTextorMarkdownchild.Actionsmust contain at least oneButton.
An invalid tree fails when the host serializes it. Arona does not silently drop or wrap a block.
Reply in the channel
Section titled “Reply in the channel”The first render is a thread reply. Pass replyInThread: false to post in the
channel instead:
yield * renderMessage(message, App, {}, { replyInThread: false });- Create a Discord bot with the same component model.
- Read Components for selects, modals, and forms.