Slack Bot Demo
Slack Bot is an AI bot for one Slack channel, written entirely in Hot as a
SlackBot agent. It reads recent channel history, replies with
the model you pick, and lets anyone in the channel switch providers by typing
!ai gpt or !ai grok.
It is also the demo to read for triggers. New messages reach the agent from two places, and everything after that is shared:
- Local dev: a schedule. A poll every 15 seconds reads the channel. No public URL needed.
- Production: a webhook. Slack's Events API calls a verified Hot webhook, which queues the message as an event and answers Slack at once.
Expected time: 20 minutes, most of it creating the Slack app. Cost: the model calls you make. You need an Anthropic API key; the other providers are optional.
What You'll Get To See
- an agent type that holds the bot's config, with every handler grouped under it on one agent dashboard,
- a schedule and a webhook feeding the same event,
- one event handler per command, so each shows up in the agent graph,
- a webhook that verifies Slack's signature, acks within Slack's 3-second limit, and moves the slow work to an event handler,
- atomic store writes (
put-if,put-if-missing) that guarantee one reply per message, even with retries and redelivery, - live provider switching across Anthropic, OpenAI, xAI, and Gemini, with the choice kept in the channel's own history,
- context variables for every secret, locally and in Hot Cloud.
Prerequisites
- Hot CLI 3.0.16 or newer: hot.dev/download
- A Slack workspace where you can create and install apps
- An Anthropic API key. OpenAI, xAI, and Gemini keys are optional.
The project's hot.hot declares published packages (hot.dev/hot-ai,
hot.dev/slack, hot.dev/anthropic, hot.dev/openai, hot.dev/xai, and
hot.dev/gemini), so dependencies resolve from the Hot package registry
automatically. The pinned versions are in
hot.hot.
Step 1: Clone
git clone https://github.com/hot-dev/hot-demos
cd hot-demos/slack-bot
Step 2: Verify The Project
hot test
The tests cover !ai parsing, the agent config, the message filter, the
handled mark, routing (including a redelivered message), and the webhook's
signature check, URL verification, retry handling, and channel filter. None of
them call Slack or a model.
Step 3: Create The Slack App
- Go to api.slack.com/apps and click Create New App → From scratch.
- Under OAuth & Permissions, add these Bot Token Scopes:
channels:historyto read messages in public channelschannels:readto get channel infochat:writeto post messagesgroups:history, only if your bot channel is private
- Install the app to your workspace and copy the Bot User OAuth Token
(
xoxb-...). - In Slack, create a channel for the bot and run
/invite @YourBotName. - Copy the channel ID (
C...) from the channel's details.
Step 4: Boot The Bot
hot dev --open
hot dev opens the Hot App at http://localhost:4680. Leave it running.
Step 5: Set Context Variables
In the Hot App, open Context Variables and set:
| Key | Value |
|---|---|
slack.api.key | the Bot User OAuth Token (xoxb-...) |
slack.channel.id | the bot channel's ID (C...) |
anthropic.api.key | your Anthropic API key |
Add openai.api.key, xai.api.key, or gemini.api.key to turn on those
providers. No code change is needed: ask-ai calls a provider once its key is
set.
Step 6: Talk To It
Type a message in the bot channel. Within 15 seconds the poll picks it up and the bot replies. To skip the wait, trigger a poll yourself:
hot eval 'send("slack-bot:check")'
Then try the model commands:
| Command | Model |
|---|---|
!ai | show the current model and every option |
!ai claude or !ai sonnet | claude-sonnet-5-5 |
!ai opus | claude-opus-5-5 |
!ai haiku | claude-haiku-5-5 |
!ai gpt | gpt-5.2 |
!ai gpt-mini | gpt-5-mini |
!ai grok | grok-4.3 |
!ai gemini | gemini-3.8-flash |
The bot finds the most recent !ai selection in the last 100 messages, so the
choice is shared by everyone in the channel and survives restarts with no
stored state. !ai alone marks providers that still need a key.
Send two messages quickly. The bot answers once, after the second, and its reply reads both from the channel history.
Step 7: Open The Agent
In the Hot App, open Workflows in the sidebar and choose Slack Bot. The dashboard opens on the Graph tab:
- the 15-second schedule and the
slack-bot:checkevent, both intocheck-channel-poll, - the
POST /eventswebhook intoon-slack-event, - both triggers sending
slack-bot:messageintoroute-message, route-messagesendingslack-bot:list-models,slack-bot:switch-model, orslack-bot:reply, each into its own handler.
The Runs tab shows every run tagged with the agent. Most polls return
no new messages. One that found work returns queued N of M new message(s),
and the reply itself is a separate reply-to-message run with its Slack and
model calls.
The agent is a type with config fields, and every handler declares
agent: SlackBot:
SlackBot
meta {
agent: {name: "Slack Bot", tags: ["slack", "ai", "chat"]},
}
type {
default-selection: Map,
system: Str,
context-messages: Int,
poll-window-ms: Int,
}
reply-to-message
meta {
agent: SlackBot,
on-event: "slack-bot:reply",
}
fn (event) { ... }
Handlers read config from the slack-bot instance, as in
slack-bot.default-selection.
How One Reply Per Message Works
Slack timestamps ("1732900000.123456") order the messages in a channel. The
agent keeps two kinds of entry in the slack-bot-state store:
- A handled mark per channel: the timestamp of the newest message it has
taken. Each poll reads the last two minutes of the channel, keeps messages
from people that are newer than the mark, and claims them by moving the mark
with
put-if. If another poll moved the mark first,put-ifreturnsfalseand this poll leaves those messages alone. The claim happens before any model call, so a poll that fires during a slow reply sees nothing new. - A reservation per message:
route-messagecallsput-if-missingwith the message's channel and timestamp. Hot delivers events at least once, and Slack retries webhooks, so the same message can arrive twice. Only the first delivery wins the reservation, so the model is never called twice for one message.
route-message also moves the handled mark, so if you leave polling on in
production it skips what the webhook already took. mark-handled only moves
the mark forward, retrying put-if when another handler wrote in between.
Step 8: Deploy With Webhooks
Polling is fine for development. In production, Slack should push events to you instead.
Create an API key at app.hot.dev → API Keys and export it as
HOT_API_KEY.In app.hot.dev → Context Variables, set the same keys as local plus
slack.signing.secret, the Signing Secret under Basic Information in your Slack app. Set it first: the webhook checks Slack's signature on every request, including the URL check in step 5.Comment out the
scheduleline incheck-channel-poll:check-channel-poll meta { agent: SlackBot, // schedule: "every 15 seconds", on-event: "slack-bot:check", } fn (event) { ... }Deploy:
hot deployIn your Slack app, open Event Subscriptions, turn it on, and set the Request URL to the webhook's URL from app.hot.dev/webhooks. Slack sends a
url_verificationchallenge, andon-slack-eventanswers it.Under Subscribe to bot events, add
message.channels(andmessage.groupsfor a private channel), then reinstall the app when Slack asks.
Slack expects a 2xx response within 3 seconds and retries when it doesn't get
one. on-slack-event only verifies, filters, and calls send, so it answers
in milliseconds. It also ignores any request with an x-slack-retry-num
header, because the first delivery was already queued. If a retry gets through
anyway, the reservation in route-message drops it.
Project Layout
slack-bot/
hot.hot # project, packages, and the local-dev profile
README.md
.env.example # HOT_API_KEY for hot deploy
hot/
src/
slack-bot/
bot.hot # SlackBot agent, triggers, routing, and command handlers
test/
slack-bot/
bot.hot # parsing, routing, handled-mark, and webhook tests
Everything is in one source file, in reading order: the agent type and its
config, !ai parsing and model selection, provider dispatch, the handled mark,
Slack helpers, the two triggers, then routing and the three command handlers.
Going Further
- Change the default model. Edit
default-selectionin theslack-botagent config. - Add a model. Add an entry to
MODEL_ALIASES;!ai <name>works at once. - Add a command. Add a branch to
route-messagethat sends a new event, and oneon-eventhandler for it. The graph picks it up without extra wiring. - Answer in threads. Pass the message through to
postand addthread_ts: message.tsto itsChatPostMessageRequest. - Add memory and tools. Replace the model call in
reply-to-messagewith::ai::agent::chat-turn/run-chat-turnfrom the agent harness package. That is what Hot Chat uses, and itsteam-agenttakes the same session and identity shape a Slack channel gives you.
Source
The runnable project lives in hot-dev/hot-demos/slack-bot.