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

# Slack

## 前提条件

以下示例需要 `slack-sdk` 库。

```shell theme={null}
pip install openai slack-sdk
```

在此处获取 Slack 令牌：[https://api.slack.com/tutorials/tracks/getting-a-token](https://api.slack.com/tutorials/tracks/getting-a-token)。

```shell theme={null}
export SLACK_TOKEN=***
```

## 示例

以下代理将使用 Slack 向频道发送消息、列出所有频道以及获取特定频道的消息历史记录。

```python cookbook/tools/slack_tools.py theme={null}
import os

from agno.agent import Agent
from agno.tools.slack import SlackTools

slack_tools = SlackTools()

agent = Agent(tools=[slack_tools], show_tool_calls=True)

# 示例 1：向 Slack 频道发送消息
agent.print_response("Send a message 'Hello from Agno!' to the channel #general", markdown=True)

# 示例 2：列出 Slack 工作区中的所有频道
agent.print_response("List all channels in our Slack workspace", markdown=True)

# 示例 3：通过频道 ID 获取特定频道的消息历史记录
agent.print_response("Get the last 10 messages from the channel 1231241", markdown=True)

```

## Toolkit 参数

| 参数                    | 类型     | 默认     | 描述                   |
| --------------------- | ------ | ------ | -------------------- |
| `token`               | `str`  | -      | 用于身份验证的 Slack API 令牌 |
| `send_message`        | `bool` | `True` | 启用向 Slack 频道发送消息的功能  |
| `list_channels`       | `bool` | `True` | 启用列出可用 Slack 频道的功能   |
| `get_channel_history` | `bool` | `True` | 启用从频道检索消息历史记录的功能     |

## Toolkit 函数

| 函数                    | 描述                  |
| --------------------- | ------------------- |
| `send_message`        | 向指定的 Slack 频道发送消息   |
| `list_channels`       | 列出 Slack 工作区中所有可用频道 |
| `get_channel_history` | 从指定频道检索消息历史记录       |

## 开发者资源

* 查看 [Tools](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/tools/slack.py)
* 查看 [Cookbook](https://github.com/agno-agi/agno/blob/main/cookbook/tools/slack_tools.py)
