Skip to content
CloudOps
Newsletter Sign up
All guides
AI for Slack · 9 min read

Building a Slack ChatOps Bot for DevOps Teams: A Practical Guide

How to build a Slack ChatOps bot from scratch — scopes, event handling, command routing, and the safety rails that keep a bot from breaking production.

  • #slack
  • #chatops
  • #devops
  • #bot
  • #automation
  • #slack-api

I’ve run ChatOps for DevOps teams for the better part of two decades, and the single highest-leverage thing I ever built was a Slack bot that let the whole team see and trigger operations from one channel. Done right, a ChatOps bot turns tribal knowledge into shared, auditable actions. Done wrong, it’s a loaded gun with a friendly emoji on the trigger.

This is how I build one that earns its keep without becoming a liability.

What a ChatOps bot actually does

Strip away the hype and a ChatOps bot does three things: it listens for messages and commands, it acts by calling your internal APIs and tooling, and it reports the result back into the channel where everyone can see it. The “everyone can see it” part is the whole point. The channel becomes a living audit log.

A good bot makes the easy things one command and makes the dangerous things require confirmation. That’s the entire design philosophy.

Step 1: Create the app and scope it tightly

Head to api.slack.com/apps, create a new app, and resist the urge to grant every scope. Start with the minimum:

  • chat:write — post messages
  • commands — receive slash commands
  • app_mentions:read — respond when mentioned
  • channels:history — read channel context when needed

Every extra scope is extra blast radius if the token leaks. I add scopes one at a time as features demand them, never up front.

Step 2: Choose your connection model

You have two options. HTTP endpoints (Events API + a public URL) suit bots that already live behind a load balancer. Socket Mode opens a WebSocket from your bot out to Slack, so you need no inbound ports — ideal for bots running inside a private cluster. For most internal DevOps tooling I reach for Socket Mode because it sidesteps a whole class of firewall and TLS headaches.

Step 3: Wire up command routing

Here’s a minimal handler using Bolt for JavaScript:

const { App } = require('@slack/bolt');
const app = new App({
  token: process.env.SLACK_BOT_TOKEN,
  appToken: process.env.SLACK_APP_TOKEN,
  socketMode: true,
});

app.command('/deploy', async ({ command, ack, respond }) => {
  await ack();
  const [service, env] = command.text.split(' ');
  if (env === 'prod') {
    return respond(`:warning: Prod deploy of *${service}* needs approval. Use the button below.`);
  }
  await respond(`:rocket: Deploying *${service}* to *${env}*...`);
  // call your deploy API here
});

(async () => { await app.start(); console.log('bot up'); })();

The pattern that matters: parse, classify by risk, then act. Non-prod runs immediately; prod requires an approval step. I treat every command as guilty until proven safe.

Step 4: Make output readable

Plain text scrolls past. Use Block Kit to give important responses structure — a header, the key fields, and a footer with who triggered it. A deploy result should answer at a glance: what, where, who, and did it work. I’ll cover message design depth elsewhere, but even a header plus two fields beats a wall of text.

Step 5: Build in the safety rails

This is where most ChatOps projects go wrong. My non-negotiables:

  • Allowlist commands, never eval arbitrary input. The bot exposes named operations. It does not run shell strings from chat. Ever.
  • Authorize per action. Reading a deploy status is open; triggering a prod rollback checks the user against an approver list.
  • Confirm destructive actions. Restarts, deletes, scale-to-zero, and migrations get a confirmation button, not a bare command.
  • Log everything to the channel and to your own store. If the bot did it, there’s a record.
  • Rotate tokens and store them in a secrets manager, never in the repo or a plain env file checked into history.

Adding AI assistance

Once the plumbing works, AI makes the bot dramatically more useful. I let it draft the human-readable summary of a command result, translate a vague request (“why is checkout slow?”) into a concrete diagnostic command the human approves, and summarize a noisy incident thread on demand.

The rule is the same one I use everywhere: AI drafts and reasons, the bot executes only allowlisted actions, and a human approves anything destructive. The model never gets a direct line to production. It proposes; the guardrails dispose.

A simple integration: when someone mentions the bot with a question, send the channel context plus the question to your LLM, get back a structured suggestion, and post it with a button the human clicks to actually run the safe diagnostic.

A sensible rollout order

I ship ChatOps bots in this order, and it’s saved me every time:

  1. Read-only commands first — status, logs tail, current deploy version. Zero risk, immediate value, and the team learns to trust the bot.
  2. Non-prod actions — deploy to staging, restart a dev service.
  3. Prod actions behind approval — only after the read-only and non-prod layers have been boring and reliable for a couple of weeks.

Resisting the urge to ship prod actions on day one is the discipline that keeps the bot from becoming the thing that caused the outage.

Where to go from here

Start tonight with a Socket Mode bot that does exactly one read-only thing. Get the team using it. Then layer on actions and AI assistance once the foundation is boring.

If you want prompt patterns for the AI-assisted parts — summarizing threads, drafting command suggestions, classifying risk — we keep a set of Slack and ChatOps prompts and a broader prompt library you can lift directly.

A ChatOps bot is only as safe as its allowlist and its approval gates. Build those first, add capability second.

Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 600+ DevOps AI prompts
  • One practical workflow email per week