DEVSAIO

Build an AI Slack bot with Bolt for JavaScript

A Slack app that answers when mentioned, replies in threads, and uses any model through one API key.

DEVSAIO team · 2 min read
Share on X

1. Create the Slack app

At api.slack.com/apps, create an app from scratch. Add the bot scopes app_mentions:read and chat:write, enable Socket Mode (so you don't need a public URL), subscribe to the app_mention event, and install it to your workspace. Note the bot token (xoxb-…) and the app-level token (xapp-…).

2. Install

bash
npm install @slack/bolt openai

3. The app

js
import { App } from "@slack/bolt";
import OpenAI from "openai";

const ai = new OpenAI({ baseURL: "https://devsaio.lol/v1", apiKey: process.env.DEVSAIO_API_KEY });
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 question = event.text.replace(/<@[^>]+>/g, "").trim().slice(0, 3000);
  const r = await ai.chat.completions.create({
    model: "claude-sonnet-4-6",
    max_tokens: 600,
    messages: [
      { role: "system", content: "You are a helpful assistant in a company Slack. Use Slack markdown: *bold*, bullet lists. Be concise." },
      { role: "user", content: question },
    ],
  });
  await say({ text: r.choices[0].message.content, thread_ts: event.thread_ts ?? event.ts });
});

await app.start();
console.log("Bot running");

Replying with thread_ts keeps channels tidy.

Ideas to extend it

  • Summarise a thread on request by fetching its messages with conversations.replies.
  • Add a /ask slash command.
  • Give the bot a team-specific system prompt (product names, internal links).

Use a dedicated key with a monthly limit for the bot.

Try it with one API key

Claude, GPT, Gemini, DeepSeek, image and video models through one OpenAI- and Anthropic-compatible endpoint. Prepaid, pay only for what you use.

Keep reading