🎯 Task: Create a Slack Bot Integration in 20 Minutes
Build a new platform service that connects AIRI’s AI brain to Slack channels, following the established Discord/Telegram pattern.
Task Description
Create a standalone Node.js service that:
- Connects to Slack via their SDK and WebSocket API.
- Forwards messages to AIRI’s central AI server via
@proj-airi/server-sdk
. - Streams AI responses back to Slack channels.
- Handles authentication, reconnection, and error states.
📜 Complete LLM Prompt (Copy-Paste Ready)
"You are PlatformBuilderGPT. Help me create a Slack bot service for the AIRI project using the existing platform adapter pattern.
CONTEXT:
- AIRI has services/discord-bot and services/telegram-bot as reference implementations
- All platform services use @proj-airi/server-sdk Client for WebSocket communication to central AI
- Pattern: Platform SDK → normalize events → forward to AI → stream responses back
- Entry point: src/index.ts, bot logic in src/bots/slack/, package.json for dependencies
EXISTING IMPLEMENTATIONS TO REFERENCE:
- Discord: services/discord-bot/src/index.ts (uses discord.js Client, handles slash commands)
- Telegram: services/telegram-bot/src/index.ts (uses grammy Bot, tick-based agent)
- Server SDK: packages/server-sdk/src/client.ts (WebSocket client with auto-reconnect)
NEW SLACK SERVICE REQUIREMENTS:
1. SERVICE STRUCTURE: Create services/slack-bot/ with proper TypeScript setup
2. SLACK SDK: Use @slack/bolt framework for WebSocket connection
3. MESSAGE HANDLING: Listen for app_mention and direct messages
4. AI INTEGRATION: Forward text to AiriClient, stream responses back
5. AUTH: Slack app token + bot token authentication
TASKS (provide exact diffs):
1. Create services/slack-bot/package.json with dependencies (@slack/bolt, @proj-airi/server-sdk)
2. Create src/index.ts with Slack App initialization and AiriClient connection
3. Create src/bots/slack/handlers.ts for message and mention handling
4. Add environment variables for SLACK_BOT_TOKEN, SLACK_APP_TOKEN
5. Implement message normalization and response streaming
TECHNICAL REQUIREMENTS:
- Use Slack's Socket Mode for WebSocket connection (no HTTP webhooks needed)
- Handle thread replies and direct messages
- Graceful error handling and reconnection logic
- Follow existing service patterns from discord-bot/telegram-bot
OUTPUT: Unified diff patches for new files, no explanations."
🔧 Prerequisites & Setup
- Slack App: Created in Slack API dashboard with bot token permissions
- Socket Mode: Enabled for WebSocket connection (no public URL needed)
- Permissions:
app_mentions:read
,chat:write
,im:read
,im:write
- Node.js: Version 18+ for compatibility with existing services
Pro Tip: Start with Socket Mode to avoid webhook complexity—upgrade to HTTP later if needed.
✅ Detailed Task Checklist
Phase 1: Service Scaffold
- Create
services/slack-bot/
directory - Copy
package.json
fromservices/discord-bot/
and modify:{ "name": "@proj-airi/slack-bot", "dependencies": { "@slack/bolt": "^3.17.0", "@proj-airi/server-sdk": "workspace:*", "@guiiai/logg": "^0.1.0" } }
- Create
tsconfig.json
and basic project structure
Phase 2: Slack App Connection
- Create
src/index.ts
with Slack App initialization:import { App } from '@slack/bolt' import { Client as AiriClient } from '@proj-airi/server-sdk' const app = new App({ token: process.env.SLACK_BOT_TOKEN, appToken: process.env.SLACK_APP_TOKEN, socketMode: true }) const airiClient = new AiriClient({ name: 'slack-bot', possibleEvents: ['input:text'], token: 'abcd' })
- Test connection with
await app.start()
Phase 3: Message Handlers
- Create
src/bots/slack/handlers.ts
:export async function handleMention({ event, say }) { // Forward to AIRI, stream response back const response = await airiClient.sendEvent('input:text', { text: event.text, user: event.user, channel: event.channel }) await say(response) }
- Register handlers in
index.ts
:app.event('app_mention', handleMention)
- Add direct message handler for DMs
Phase 4: AI Integration
- Implement message normalization (Slack format → AIRI format)
- Add streaming response handling (AIRI → Slack messages)
- Handle thread replies and mentions properly
- Test with “Hey @airi-bot, what’s the weather?”
Phase 5: Error Handling & Polish
- Add reconnection logic for both Slack and AIRI connections
- Implement rate limiting (Slack has strict limits)
- Add logging with
@guiiai/logg
like other services - Create
.env.example
with required tokens
Phase 6: Deployment Ready
- Add Docker support (copy from
telegram-bot
) - Create README.md with setup instructions
- Test in production Slack workspace
- Add to main project’s service orchestration
🧑🔬 Troubleshooting Guide
Issue | Solution |
---|---|
”Invalid token” error | Verify SLACK_BOT_TOKEN starts with xoxb- and SLACK_APP_TOKEN starts with xapp- |
Bot doesn’t respond to mentions | Check Slack app has app_mentions:read scope and is added to channels |
WebSocket connection fails | Ensure Socket Mode is enabled in Slack app settings |
AIRI connection timeout | Verify central AI server is running and server-sdk URL is correct |
Rate limit errors | Implement exponential backoff, Slack allows 1 message/second per channel |
🔗 Key Files Deep Dive
What You’re Creating | Exact File Path | Key Sections |
---|---|---|
Service entry point | services/slack-bot/src/index.ts | Slack App + AiriClient initialization |
Message handlers | services/slack-bot/src/bots/slack/handlers.ts | Event processing and response logic |
Package config | services/slack-bot/package.json | Dependencies and scripts |
Environment template | services/slack-bot/.env.example | Required tokens and config |
🎯 Success Criteria
✅ Mention @airi-bot in Slack → AI responds in same thread
✅ Send DM to bot → AI responds in DM
✅ Service auto-reconnects if Slack or AIRI connection drops
✅ Proper error handling for rate limits and API failures
✅ Production ready with Docker and environment config
✅ Follows existing patterns from Discord/Telegram services
🚀 Extension Ideas
Once basic Slack works, try these advanced features:
- Slash Commands:
/airi weather Tokyo
for quick queries - Interactive Buttons: Let users vote on AI responses
- File Upload: Send documents to AI for analysis
- Workflow Integration: Connect to Slack workflows and automations
📋 Reference Architecture
Based on existing services, here’s the proven pattern:
💡 Pro Tip: Copy extensively from services/discord-bot/
and services/telegram-bot/
—the patterns are battle-tested. Focus on Slack-specific APIs, not reinventing the wheel!