Deploying a bot

Deploy

pnpm site bots/<your-bot>      # knowledge/ → site/, which Wrangler requires
cd bots/<your-bot>
wrangler deploy

The site build comes first because wrangler.jsonc serves site/ as static assets, and Wrangler refuses to start when that directory is missing. It is generated and git-ignored, so a fresh checkout always needs it. See The knowledge-base website.

The Worker exposes:

  • GET / and every *.html under it — the knowledge base as a documentation site, served ahead of the Worker.
  • POST /slack/events — every Slack delivery (events, interactivity, commands).
  • POST /google-chat/events — every Google Chat interaction event.
  • POST /teams/messages — every Bot Framework activity.
  • GET /health — { "status": "ok", "bot": "…", "platforms": […] }.

/health answers without touching a platform, so it is safe as an uptime check. Its platforms array is the fastest way to see which integrations this deployment actually resolved.

Secrets

Only the platforms you want. A platform whose credentials are absent is not served at all.

# Slack
wrangler secret put SLACK_BOT_TOKEN
wrangler secret put SLACK_SIGNING_SECRET
wrangler secret put SLACK_BOT_USER_ID

# Google Chat
wrangler secret put GOOGLE_CHAT_SERVICE_ACCOUNT

# Microsoft Teams
wrangler secret put TEAMS_APP_ID
wrangler secret put TEAMS_APP_PASSWORD

Variables

Set in wrangler.jsonc under vars:

Variable Meaning
Deployment PRODUCTION, DEVELOPMENT or TEST. Drives log environment.
LOG_LEVEL debug, info, warn, error.
AI_SERVICE, AI_MODEL, … The AI provider. See AI and tools.
SLACK_PATH_PREFIX Defaults to /slack.
GOOGLE_CHAT_AUDIENCE Required with Google Chat. See Connecting Google Chat.
GOOGLE_CHAT_HISTORY enabled once the app has admin approval for the history scope.
TEAMS_TENANT_ID Only for a single-tenant Teams bot. See Connecting Microsoft Teams.
TEAMS_SERVICE_URL Fallback Connector URL for proactive Teams messages.
HELP_CHANNEL Where the bot asks a person to take over. Slack C…, Chat spaces/…, Teams 19:….
HELP_PEOPLE Comma-separated email addresses of the people to notify.
HELP_MESSAGE What a user is told when nobody could be reached.
CONVERSATION_MAX_INTERACTIONS The most messages one conversation is answered for. Unset ⇒ no limit.
CONVERSATION_MAX_COST The most AI cost one conversation may run up, in US dollars. Unset ⇒ no limit.
CONVERSATION_CAP_MESSAGE What the bot says, once, when a conversation reaches either limit. Unset ⇒ a standard sentence.

Where the bot asks for a person

HELP_CHANNEL names a channel in one chat system: a C0123 is a channel in one Slack workspace and nothing at all anywhere else. So a bot that is connected to more than one chat system sets it per connection, on that connection's own screen under Integrations, and the value the bot uses is the one belonging to the chat system it is answering in. The variable above is the deploy-time route, for a bot configured entirely from wrangler.jsonc; a value set on a connection wins for that connection.

HELP_PEOPLE is the opposite and is deliberately global: it holds email addresses, and an address is the same person in Slack, in Google Chat and in Teams. The bot resolves each address to that person in whichever chat system it is answering in, @-mentions them in the request, and messages them directly when no channel answered.

Resolving an address needs a directory the chat system lets an app search. Slack has one (the users:read.email scope, which the app manifest already asks for). Google Chat and Microsoft Teams do not — reaching one would mean the Google Workspace Admin SDK or Microsoft Graph, each behind an administrator's consent — so there an entry is used as a raw platform user id instead, which is what this setting held before it held addresses. An address nobody holds is skipped, quietly and with a line in the log: the bot asks everybody it could find, and never claims to have reached somebody it did not.

Two more things the hand-off does on its own. It is rate-limited per conversation: once a request has actually reached somebody, a repeat within ten minutes tells the user it is already in hand rather than paging that person again — a failed attempt is retried at once, because nothing landed. And it passes on the user's email address only when the chat platform vouched for it; an address a web chat visitor typed into a page is never put in front of a colleague, who would otherwise write to it.

The KV store

Optional but recommended:

wrangler kv namespace create BOT_STORE

Paste the id into kv_namespaces in wrangler.jsonc. It backs two things:

  • Event de-duplication. Chat platforms retry deliveries; without a shared store the fallback is in-memory, which is per-isolate and therefore best-effort.
  • Conversation state. conversation.state is scoped per channel and thread, with a one-day default TTL. The hand-off cooldown lives here, so without a namespace it too is per-isolate: one person could page the same engineer twice from two isolates.

Logs

Logs are structured JSON, one object per line, so Cloudflare's observability surfaces the fields as columns. Filter by bot, platform, eventKind, eventId or channel.

wrangler tail --format pretty

The same lines, for one conversation, are on the Operator tab: open the conversation and then its events, under its cost. Everything the bot logged while handling it is there — each AI call with its tokens, cost and duration, each tool call, each question to the decision model — grouped under the message that caused it, warnings in yellow and errors in red. They are kept for seven days, like the conversation.

Capping a conversation

The Limits tab, or the three CONVERSATION_… variables above, stop the bot answering a conversation that has gone on too long or cost too much. The person is told once, in your words; after that the bot stays quiet in that conversation while operators can still write in it. A message the bot only overhears in a channel never counts.

Multiple platforms in one Worker

List every factory. Each returns null when its credentials are absent, so one binary serves a Slack customer, a Google Chat customer, or both at once — with no build flag and no separate artefact:

export default createBotRuntime({
  bot,
  platforms: [slackPlatform, googleChatPlatform, teamsPlatform],
});

Related: Connecting Slack, Connecting Google Chat, Connecting Microsoft Teams, Troubleshooting.

← Running a botTroubleshooting →