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
npm install @slack/bolt openai3. The app
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
/askslash command. - Give the bot a team-specific system prompt (product names, internal links).
Use a dedicated key with a monthly limit for the bot.
Claude, GPT, Gemini, DeepSeek, image and video models through one OpenAI- and Anthropic-compatible endpoint. Prepaid, pay only for what you use.