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

  1. Go to api.slack.com/apps and click Create New App → From scratch.
  2. Under OAuth & Permissions, add these Bot Token Scopes:
    • channels:history to read messages in public channels
    • channels:read to get channel info
    • chat:write to post messages
    • groups:history, only if your bot channel is private
  3. Install the app to your workspace and copy the Bot User OAuth Token (xoxb-...).
  4. In Slack, create a channel for the bot and run /invite @YourBotName.
  5. 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:

KeyValue
slack.api.keythe Bot User OAuth Token (xoxb-...)
slack.channel.idthe bot channel's ID (C...)
anthropic.api.keyyour 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:

CommandModel
!aishow the current model and every option
!ai claude or !ai sonnetclaude-sonnet-5-5
!ai opusclaude-opus-5-5
!ai haikuclaude-haiku-5-5
!ai gptgpt-5.2
!ai gpt-minigpt-5-mini
!ai grokgrok-4.3
!ai geminigemini-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:check event, both into check-channel-poll,
  • the POST /events webhook into on-slack-event,
  • both triggers sending slack-bot:message into route-message,
  • route-message sending slack-bot:list-models, slack-bot:switch-model, or slack-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-if returns false and 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-message calls put-if-missing with 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.

  1. Create an API key at app.hot.dev → API Keys and export it as HOT_API_KEY.

  2. 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.

  3. Comment out the schedule line in check-channel-poll:

    check-channel-poll
    meta {
      agent: SlackBot,
      // schedule: "every 15 seconds",
      on-event: "slack-bot:check",
    }
    fn (event) { ... }
    
  4. Deploy:

    hot deploy
    
  5. In 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_verification challenge, and on-slack-event answers it.

  6. Under Subscribe to bot events, add message.channels (and message.groups for 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-selection in the slack-bot agent config.
  • Add a model. Add an entry to MODEL_ALIASES; !ai <name> works at once.
  • Add a command. Add a branch to route-message that sends a new event, and one on-event handler for it. The graph picks it up without extra wiring.
  • Answer in threads. Pass the message through to post and add thread_ts: message.ts to its ChatPostMessageRequest.
  • Add memory and tools. Replace the model call in reply-to-message with ::ai::agent::chat-turn/run-chat-turn from the agent harness package. That is what Hot Chat uses, and its team-agent takes the same session and identity shape a Slack channel gives you.

Source

The runnable project lives in hot-dev/hot-demos/slack-bot.