Slack

Send messages and interact with Slack workspaces

Overview

Slack tool allows you to send messages, read channels, and interact with Slack workspaces.

The user asks to post or read messages; the agent calls Slack and returns the outcome.

Diagram

SlackTool Flow

👤 User

🤖 Agent

🔧 SlackTool

✅ Result

Installation

bash
pip install "praisonai[tools]"

Environment Variables

bash
export SLACK_BOT_TOKEN=xoxb-your-bot-token
export SLACK_WEBHOOK_URL=https://hooks.slack.com/services/...  # Optional

Quick Start

  1. Simple Usage
    python
    from praisonai_tools import SlackTool
    
    # Initialize
    slack = SlackTool()
    
    # Send message
    slack.send_message("#general", "Hello from PraisonAI!")
  2. With Configuration

    Use the same tool with an agent — see Usage with Agent below, or pass env vars and options from the sections above.

Usage with Agent

python
from praisonaiagents import Agent
from praisonai_tools import SlackTool

agent = Agent(
    name="SlackBot",
    instructions="You send notifications to Slack.",
    tools=[SlackTool()]
)

response = agent.chat("Send a message to #alerts saying the deployment is complete")
print(response)

Available Methods

send_message(channel, text)

Send a message to a channel.

python
from praisonai_tools import SlackTool

slack = SlackTool()
slack.send_message("#general", "Hello!")

get_channels()

List available channels.

python
channels = slack.get_channels()

get_history(channel, limit=10)

Get channel message history.

python
messages = slack.get_history("#general", limit=20)

Common Errors

ErrorCauseSolution
SLACK_BOT_TOKEN not configuredMissing tokenSet environment variable
channel_not_foundInvalid channelCheck channel name
not_in_channelBot not in channelInvite bot to channel

How It Works

Diagram
Slack APIToolAgentUserSlack APIToolAgentUserRequestCall toolQueryDataResultResponse

Best Practices

Store the bot token securely

Read the Slack token from the environment, never hard-code it.

Scope bot permissions

Grant only the channel and message scopes the task requires.

Handle rate limits

Slack returns HTTP 429 under load. Retry with backoff so the agent stays responsive.


Related Tools