前提条件
以下示例需要 slack-sdk
库。
pip install openai slack-sdk
在此处获取 Slack 令牌:https://api.slack.com/tutorials/tracks/getting-a-token。
以下代理将使用 Slack 向频道发送消息、列出所有频道以及获取特定频道的消息历史记录。
cookbook/tools/slack_tools.py
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)
参数 | 类型 | 默认 | 描述 |
---|
token | str | - | 用于身份验证的 Slack API 令牌 |
send_message | bool | True | 启用向 Slack 频道发送消息的功能 |
list_channels | bool | True | 启用列出可用 Slack 频道的功能 |
get_channel_history | bool | True | 启用从频道检索消息历史记录的功能 |
函数 | 描述 |
---|
send_message | 向指定的 Slack 频道发送消息 |
list_channels | 列出 Slack 工作区中所有可用频道 |
get_channel_history | 从指定频道检索消息历史记录 |
开发者资源
Responses are generated using AI and may contain mistakes.