> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 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.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "SlackTool Flow"
        User[👤 User] --> Agent[🤖 Agent]
        Agent --> Tool[🔧 SlackTool]
        Tool --> Result[✅ Result]
        Result --> Agent
    end

    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef tool fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef output fill:#10B981,stroke:#7C90A0,color:#fff

    class User,Agent agent
    class Tool tool
    class Result output
```

## Installation

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install "praisonai[tools]"
```

## Environment Variables

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
export SLACK_BOT_TOKEN=xoxb-your-bot-token
export SLACK_WEBHOOK_URL=https://hooks.slack.com/services/...  # Optional
```

## Quick Start

<Steps>
  <Step title="Simple Usage">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonai_tools import SlackTool

    # Initialize
    slack = SlackTool()

    # Send message
    slack.send_message("#general", "Hello from PraisonAI!")
    ```
  </Step>

  <Step title="With Configuration">
    Use the same tool with an agent — see **Usage with Agent** below, or pass env vars and options from the sections above.
  </Step>
</Steps>

## Usage with Agent

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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 theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonai_tools import SlackTool

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

### get\_channels()

List available channels.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
channels = slack.get_channels()
```

### get\_history(channel, limit=10)

Get channel message history.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
messages = slack.get_history("#general", limit=20)
```

## Common Errors

| Error                            | Cause              | Solution                 |
| -------------------------------- | ------------------ | ------------------------ |
| `SLACK_BOT_TOKEN not configured` | Missing token      | Set environment variable |
| `channel_not_found`              | Invalid channel    | Check channel name       |
| `not_in_channel`                 | Bot not in channel | Invite bot to channel    |

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Tool as Tool
    participant Svc as Slack API

    User->>Agent: Request
    Agent->>Tool: Call tool
    Tool->>Svc: Query
    Svc-->>Tool: Data
    Tool-->>Agent: Result
    Agent-->>User: Response
```

***

## Best Practices

<AccordionGroup>
  <Accordion title="Store the bot token securely">
    Read the Slack token from the environment, never hard-code it.
  </Accordion>

  <Accordion title="Scope bot permissions">
    Grant only the channel and message scopes the task requires.
  </Accordion>

  <Accordion title="Handle rate limits">
    Slack returns HTTP 429 under load. Retry with backoff so the agent stays responsive.
  </Accordion>
</AccordionGroup>

***

## Related Tools

<CardGroup cols={2}>
  <Card title="Discord" icon="book" href="/docs/tools/external/discord">
    Discord messaging
  </Card>

  <Card title="Telegram" icon="book" href="/docs/tools/external/telegram">
    Telegram bot
  </Card>

  <Card title="Email" icon="book" href="/docs/tools/external/email">
    Email notifications
  </Card>
</CardGroup>
