Bots

Connect agents to Slack and other platforms

Agents can live inside Slack — chat naturally where your team works.

Diagram

Bot Integration

💬 Slack

🤖 Agent

💬 Response

Quick Start

  1. Simple Usage
    typescript
    import { Agent, createSlackBot } from 'praisonai';
    
    const agent = new Agent({
      instructions: 'You are a helpful team assistant'
    });
    
    const bot = createSlackBot({
      botToken: process.env.SLACK_BOT_TOKEN!,
      appToken: process.env.SLACK_APP_TOKEN!,
      socketMode: true
    });
    
    bot.onMessage(async (message) => {
      const response = await agent.chat(message.text);
      return { text: response, threadTs: message.ts };
    });
    
    await bot.start();
    // ⚡️ Slack bot is running in Socket Mode
  2. With Configuration
    typescript
    bot.onAppMention(async (message) => {
      const response = await agent.chat(message.text);
      return { text: response, threadTs: message.ts };
    });

User Interaction Flow

Diagram
AgentSlack BotSlack UserAgentSlack BotSlack User“@bot help me with…”Process messageResponseReply in thread

Configuration

typescript
import { createSlackBot } from 'praisonai';

// Webhook mode (production)
const bot = createSlackBot({
  botToken: process.env.SLACK_BOT_TOKEN!,
  signingSecret: process.env.SLACK_SIGNING_SECRET!
});

bot.onMessage(async (message) => {
  return { text: 'Hello!' };
});

await bot.listen(3000); // Start webhook server

// Socket Mode (development — no public URL needed)
const devBot = createSlackBot({
  botToken: process.env.SLACK_BOT_TOKEN!,
  appToken: process.env.SLACK_APP_TOKEN!,
  socketMode: true
});

devBot.onMessage(async (message) => {
  return { text: 'Hello!' };
});

await devBot.start();
OptionTypeRequiredDescription
botTokenstring✅Bot OAuth token (xoxb-...)
appTokenstringSocket ModeApp-level token (xapp-...)
signingSecretstringWebhookFor webhook request verification
socketModeboolean—Enable Socket Mode (default: false)

Send Messages Proactively

typescript
// Send a message to any channel
await bot.sendMessage('#general', 'Daily standup reminder!', {
  threadTs: '1234567890.123456'  // optional: reply in thread
});

Other Platforms


Environment Variables

VariableDescription
SLACK_BOT_TOKENBot OAuth token
SLACK_APP_TOKENApp-level token for Socket Mode
SLACK_SIGNING_SECRETFor webhook mode verification

Best Practices

Use Socket Mode for development

No public URL needed — easier for local testing.

Reply in threads

Keep conversations organized by setting threadTs in responses.

Handle errors gracefully

Always return a response, even if just “I couldn’t process that”.


Related