How to Build a Slack AI Bot With Bolt for Node
Use Slack Bolt and Socket Mode to answer app mentions with AI, no public URL required.
Slack's Bolt framework plus Socket Mode lets you build a bot that responds to mentions without exposing a public endpoint. That makes it perfect for testing from your laptop. Here you will create a Slack app, grab the two tokens it needs, and answer @-mentions with an LLM.
What you need
- A Slack workspace where you can install apps
- Node 18+ installed
- An AI API key
- Permission to create a Slack app at api.slack.com/apps
Step 1: Create the Slack app and enable Socket Mode
At api.slack.com/apps click Create New App, choose From scratch, and pick your workspace. Under Socket Mode, flip it on and generate an app-level token with the connections:write scope. This token starts with xapp-.
Step 2: Add scopes and subscribe to events
Under OAuth & Permissions add the bot scopes app_mentions:read and chat:write. Under Event Subscriptions, turn events on and subscribe the bot to app_mention. Then click Install to Workspace and copy the Bot User OAuth token that starts with xoxb-.
Step 3: Install Bolt and write the app
import "dotenv/config";
import pkg from "@slack/bolt";
import OpenAI from "openai";
const { App } = pkg;
const ai = new OpenAI();
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
appToken: process.env.SLACK_APP_TOKEN,
socketMode: true,
});
app.event("app_mention", async ({ event, say }) => {
const prompt = event.text.replace(/<@[^>]+>/g, "").trim();
const res = await ai.chat.completions.create({
model: "gpt-5-mini",
messages: [{ role: "user", content: prompt }],
});
await say({
text: res.choices[0].message.content,
thread_ts: event.ts,
});
});
await app.start();
console.log("Slack AI bot is running");Step 4: Run and mention it
Result
Your Slack workspace now has an AI teammate that answers when mentioned, all without a single inbound webhook. To go to production, deploy the same file to a server and keep the process alive with pm2 or a systemd unit.
Watch related tutorials
22:00
20:00
05:00
30:00
26:00
5:42