Build a Slack AI Assistant with Antbase
ยท5 min read
๐Ÿ’ผ

Build a Slack AI Assistant with Antbase

Create a Slack bot that responds to messages with AI-powered answers via Antbase. Covers Bolt framework, slash commands, and thread context.

slackbotworkspace

Every engineering team eventually builds a Slack bot. It starts as a fun side project โ€” wire up the Bolt framework, call GPT-4, reply in threads. Then people start actually using it. A lot. Suddenly your "fun side project" is handling 200 messages a day, and your OpenAI bill looks like a phone bill from the 90s. Most of those messages are things like "what does this acronym mean" and "summarize this thread" โ€” tasks that absolutely do not need a $10/million-token model.

Antbase turns your Slack bot from a cost liability into a sustainable tool. Every message gets classified independently: simple questions, definitions, and translations go to fast free models that respond in under a second. Complex analysis, code review, and multi-step reasoning go to premium models. Your team gets instant responses for the quick stuff and thoughtful responses for the hard stuff, with the cost profile of a bot that barely uses premium models at all.

There is a practical reliability benefit too. Slack bots are highly visible โ€” when the bot goes silent during an outage, the whole team notices immediately. Antbase provides automatic failover across providers, so your bot stays responsive even when individual LLM providers have issues. For a tool that your entire team depends on daily, that resilience is worth more than the cost savings.

A Slack bot backed by Antbase gives your workspace an AI assistant that answers questions, summarizes threads, and helps with tasks. Antbase routes each request to the best model โ€” simple Q&A gets fast models, complex analysis gets premium ones.

Setup with Bolt

bash
npm install @slack/bolt openai
typescript
import { App } from '@slack/bolt';
import OpenAI from 'openai';

const app = new App({
  token: process.env.SLACK_BOT_TOKEN,
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  socketMode: true,
  appToken: process.env.SLACK_APP_TOKEN,
});

const ai = new OpenAI({
  baseURL: 'https://antbase.ai/v1',
  apiKey: process.env.ANTBASE_API_KEY,
});

// Respond to @mentions
app.event('app_mention', async ({ event, say }) => {
  const text = event.text.replace(/<@[A-Z0-9]+>/g, '').trim();

  const response = await ai.chat.completions.create({
    model: 'auto',
    messages: [
      { role: 'system', content: 'You are a helpful Slack assistant. Be concise and use Slack formatting.' },
      { role: 'user', content: text },
    ],
  });

  await say({
    text: response.choices[0].message.content ?? 'No response.',
    thread_ts: event.ts,
  });
});

// Slash command: /ask
app.command('/ask', async ({ command, ack, respond }) => {
  await ack();

  const response = await ai.chat.completions.create({
    model: 'auto',
    messages: [{ role: 'user', content: command.text }],
  });

  await respond(response.choices[0].message.content ?? 'No response.');
});

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

Thread Context

For multi-turn conversations in threads, fetch the thread history and include it as context. Use the Slack conversations.replies API to get previous messages in the thread before sending to Antbase.

Tips

  • โ€ขReply in threads (using thread_ts) to keep channels clean.
  • โ€ขSlack messages have a 40,000-character limit, but keep AI responses short โ€” under 2,000 characters works best.
  • โ€ขUse Socket Mode during development (no public URL needed). Switch to HTTP mode with a public endpoint for production.
  • โ€ขCreate the Slack app at api.slack.com/apps with bot scopes: app_mentions:read, chat:write, commands.

Try ANT routing today

Drop-in OpenAI-compatible API. Change your base URL and every request gets intelligent routing across 30+ providers.