Documentation Index
Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
Use this file to discover all available pages before exploring further.
Slackbot Agent
Build intelligent Slack bots that can respond to messages, handle mentions, and execute tasks.
Quick Start
import { Agent, createSlackBot } from 'praisonai-ts';
// Create an agent
const agent = new Agent({
name: 'SlackAssistant',
instructions: 'You are a helpful Slack assistant.',
});
// Create Slack bot
const bot = createSlackBot({
botToken: process.env.SLACK_BOT_TOKEN!,
signingSecret: process.env.SLACK_SIGNING_SECRET!,
});
// Handle messages
bot.onMessage(async (message) => {
const response = await agent.chat(message.text);
return { text: response, threadTs: message.ts };
});
// Start the bot
bot.listen(3000);
Configuration
import { createSlackBot } from 'praisonai-ts';
const bot = createSlackBot({
// Required
botToken: process.env.SLACK_BOT_TOKEN!,
// For webhook mode (recommended for production)
signingSecret: process.env.SLACK_SIGNING_SECRET!,
// For Socket Mode (development)
appToken: process.env.SLACK_APP_TOKEN,
socketMode: true,
});
Event Handlers
Message Handler
bot.onMessage(async (message) => {
// message.channel - Channel ID
// message.user - User ID
// message.text - Message text
// message.ts - Timestamp
// message.threadTs - Thread timestamp (if in thread)
const response = await agent.chat(message.text);
return {
text: response,
threadTs: message.ts, // Reply in thread
};
});
App Mention Handler
bot.onAppMention(async (message) => {
// Triggered when bot is @mentioned
const response = await agent.chat(message.text);
return { text: response };
});
Reaction Handler
bot.onReactionAdded(async (event) => {
if (event.reaction === 'eyes') {
// Process message when 👀 reaction is added
console.log('Processing message:', event.item.ts);
}
});
Rich Responses
With Blocks
bot.onMessage(async (message) => {
return {
text: 'Here are the results:',
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: '*Results*\n• Item 1\n• Item 2',
},
},
{
type: 'actions',
elements: [
{
type: 'button',
text: { type: 'plain_text', text: 'View More' },
action_id: 'view_more',
},
],
},
],
};
});
Socket Mode (Development)
For local development without exposing a public URL:
const bot = createSlackBot({
botToken: process.env.SLACK_BOT_TOKEN!,
appToken: process.env.SLACK_APP_TOKEN!,
socketMode: true,
});
// No need to call listen() - socket mode connects automatically
await bot.start();
Webhook Mode (Production)
For production deployments:
const bot = createSlackBot({
botToken: process.env.SLACK_BOT_TOKEN!,
signingSecret: process.env.SLACK_SIGNING_SECRET!,
});
// Start HTTP server
bot.listen(3000);
const agent = new Agent({
name: 'SlackAssistant',
instructions: 'You help with tasks in Slack.',
tools: [
{
name: 'search_docs',
description: 'Search documentation',
execute: async ({ query }) => {
// Search implementation
return { results: ['doc1', 'doc2'] };
},
},
],
});
bot.onMessage(async (message) => {
const response = await agent.chat(message.text);
return { text: response };
});
Environment Variables
| Variable | Required | Description |
|---|
SLACK_BOT_TOKEN | Yes | Bot token (xoxb-…) |
SLACK_SIGNING_SECRET | Webhook | Signing secret |
SLACK_APP_TOKEN | Socket | App token (xapp-…) |
OPENAI_API_KEY | Yes | For the agent |
Slack App Setup
- Create a Slack App at https://api.slack.com/apps
- Enable Socket Mode or configure Event Subscriptions
- Add bot scopes:
chat:write, app_mentions:read, channels:history
- Install to workspace
- Copy tokens to environment variables
Best Practices
- Use threads - Reply in threads to keep channels clean
- Handle errors gracefully - Return friendly error messages
- Rate limit - Respect Slack’s rate limits
- Log interactions - Track usage for debugging
- Agent - Core agent documentation
- Tools - Adding tools to agents