Setup and context — Building Slack Bots with Antigravity
Slack is the communication hub for countless development teams. Adding a custom bot can automate repetitive tasks, surface information on demand, and make collaboration genuinely smoother. In this guide, we'll walk through building a Slack Bot using Antigravity as our AI-powered development environment — from initial setup to a fully functional, MCP-connected assistant.
Antigravity's agent capabilities shine here: API spec lookups, code generation, and debugging all happen in a single, conversational flow. You'll finish this project in a fraction of the time compared to traditional development approaches.
What you'll learn:
- Creating a Slack App and setting up Bolt.js
- Implementing slash commands and Event API handlers
- Using Antigravity agents for rapid code generation
- Adding intelligent AI responses through MCP integration
- Debugging the most common Slack Bot errors
This guide is written for developers who are comfortable with Node.js basics and are building their first Slack Bot.
Setup — Creating Your Slack App
Create the Slack App
Head to Slack's API portal (api.slack.com/apps) and create a new app.
- Click "Create New App"
- Select "From scratch"
- Enter an App Name (e.g.
my-antigravity-bot) and choose your workspace
Once created, navigate to "OAuth & Permissions" in the left sidebar and add the following Bot Token Scopes:
chat:write— post messagescommands— handle slash commandsapp_mentions:read— receive mention events
After adding scopes, click "Install to Workspace" and copy the Bot User OAuth Token (starts with xoxb-).
Initialize the Project
# Create project directory
mkdir my-slack-bot && cd my-slack-bot
# Initialize npm and install Bolt.js
npm init -y
npm install @slack/bolt dotenvCreate a .env file with your credentials:
# .env — add this to .gitignore immediately
SLACK_BOT_TOKEN=xoxb-YOUR_BOT_TOKEN_HERE
SLACK_SIGNING_SECRET=YOUR_SIGNING_SECRET_HERE
SLACK_APP_TOKEN=xapp-YOUR_APP_TOKEN_HERE
PORT=3000The Signing Secret is found on the "Basic Information" page of your Slack App. Never hardcode tokens in source files. Always use
.envand.gitignore.
Generating the Bot with Antigravity
This is where Antigravity earns its keep. Open the project in Antigravity and type this prompt in the chat panel:
Create a Slack Bot using Bolt.js with the following features:
- A /hello slash command that sends a greeting message to the channel
- app_mention event handler that replies when the bot is mentioned
- Socket Mode support for local development
Load credentials from .env using dotenv.
Antigravity will generate a working app.js along these lines:
// app.js — Slack Bot entry point
const { App } = require('@slack/bolt');
require('dotenv').config();
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
socketMode: true,
appToken: process.env.SLACK_APP_TOKEN,
port: process.env.PORT || 3000,
});
// ── Slash command: /hello ──
app.command('/hello', async ({ command, ack, say }) => {
// Acknowledge within 3 seconds — required by Slack
await ack();
await say({
text: `Hello, <@${command.user_id}>! Antigravity Bot is live 🚀`,
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `Hello, <@${command.user_id}>!\n*Antigravity Bot* is up and running 🚀`,
},
},
],
});
});
// ── Mention handler ──
app.event('app_mention', async ({ event, say }) => {
await say({
text: `<@${event.user}> How can I help you?`,
});
});
// ── Start the bot ──
(async () => {
await app.start();
console.log(`⚡ Slack Bot running on port ${process.env.PORT || 3000}`);
})();Socket Mode lets you run the bot locally without needing a public HTTPS tunnel. Generate an App-Level Token from the "Socket Mode" section of your Slack App settings.
Extending with Commands and Modals
Once the skeleton works, it's time to add real utility. Ask Antigravity to scaffold a modal-based reminder command:
// /remind command — opens a modal to capture reminder details
app.command('/remind', async ({ command, ack, client }) => {
await ack();
await client.views.open({
trigger_id: command.trigger_id,
view: {
type: 'modal',
callback_id: 'reminder_modal',
title: { type: 'plain_text', text: 'Set a Reminder' },
submit: { type: 'plain_text', text: 'Save' },
blocks: [
{
type: 'input',
block_id: 'reminder_text',
element: {
type: 'plain_text_input',
action_id: 'text_input',
placeholder: { type: 'plain_text', text: 'e.g. Prepare meeting slides' },
},
label: { type: 'plain_text', text: 'What would you like to be reminded about?' },
},
],
},
});
});
// Handle modal submission
app.view('reminder_modal', async ({ ack, body, view, client }) => {
await ack();
const reminderText = view.state.values.reminder_text.text_input.value;
const userId = body.user.id;
// DM the user a confirmation
await client.chat.postMessage({
channel: userId,
text: `✅ Reminder saved: *${reminderText}*`,
});
});Antigravity handles all the Block Kit JSON scaffolding automatically — a part of Slack development that's notoriously tedious to write by hand.
Adding AI Responses via MCP
The MCP integration in Antigravity opens up a powerful next step: connecting your Slack Bot to external data sources and AI tools. Here's a conceptual example that routes mentions through an MCP server to search an internal FAQ database:
// MCP-powered AI response handler (conceptual example)
const { Client } = require('@modelcontextprotocol/sdk/client/index.js');
const { StdioClientTransport } = require('@modelcontextprotocol/sdk/client/stdio.js');
const mcpClient = new Client({ name: 'slack-bot-mcp', version: '1.0.0' }, { capabilities: {} });
app.event('app_mention', async ({ event, say }) => {
// Strip the mention tag from the message text
const userMessage = event.text.replace(/<@[A-Z0-9]+>/g, '').trim();
try {
// Call an MCP tool — e.g. search your team's internal knowledge base
const result = await mcpClient.callTool({
name: 'search_faq',
arguments: { query: userMessage },
});
await say({
text: result.content[0].text,
thread_ts: event.ts, // Reply in thread
});
} catch (error) {
await say({ text: `Sorry, something went wrong on my end.` });
console.error('MCP tool error:', error);
}
});For a deep dive into building production-grade MCP servers, check out Antigravity × Custom MCP Server Guide — it covers everything from schema design to error handling in Cloudflare Workers.
Troubleshooting Common Errors
Error: Missing required field: trigger_id
This happens when client.views.open() is called before ack(). Slack invalidates the trigger_id after a few seconds, and you must acknowledge the command first.
// ❌ Wrong — ack comes after views.open
app.command('/test', async ({ command, client }) => {
await client.views.open({ trigger_id: command.trigger_id, ... });
await ack(); // Too late
});
// ✅ Correct — ack first, always
app.command('/test', async ({ command, ack, client }) => {
await ack();
await client.views.open({ trigger_id: command.trigger_id, ... });
});Error: invalid_auth / not_authed
Your token isn't loading correctly. Check:
require('dotenv').config()appears before any token reference- Environment variable names match exactly (typos like
SLACK_BOT_TOKNEare common) - The app may need to be reinstalled in the workspace after scope changes
Error: dispatch_failed (timeout)
Slack requires a response within 3 seconds. For slow operations (API calls, database queries), call ack() immediately and send the actual response later using respond() or say() from within an async callback.
Deploying to Production
Socket Mode is intended for development only. For production, switch to HTTP Mode and configure a public Request URL endpoint in your Slack App settings.
Popular deployment targets include:
- Railway / Render — easy environment variable setup, free tier available
- Cloudflare Workers — edge execution for minimal latency (HTTP mode recommended)
- Google Cloud Run — containerized, auto-scaling
Ask Antigravity: "Generate a Dockerfile and Cloud Run deployment config for this Slack Bot" — it will produce everything you need in one shot.
Summary
In this guide, you built a Slack Bot with Antigravity — from Slack App creation through to MCP-powered AI responses. Here's what we covered:
- Creating a Slack App and configuring Bolt.js with Socket Mode
- Implementing slash commands and modal interactions
- Using Antigravity agents to generate Bolt.js code and Block Kit structures
- Connecting to MCP for advanced AI-powered replies
- Fixing the most common Slack Bot errors
Antigravity's code generation capabilities make Slack development genuinely enjoyable — the Block Kit JSON that used to take hours to hand-craft is now just a prompt away. Give it a try and see how fast you can ship your next team automation.
To take your Slack Bot further with production-grade MCP integrations, Antigravity × Custom MCP Server Guide is the natural next step.