Slack 集成
让你的智能体通过 Slack 管理团队沟通。你可以发送消息、搜索对话、管理频道,并协调团队活动,从而借助 AI 驱动的自动化简化协作工作流。
在使用 Slack 集成之前,请确保你已具备:
- 一个拥有有效订阅的 CrewAI AMP 账户
- 一个具备相应权限的 Slack 工作区
- 通过 集成页面 连接了你的 Slack 工作区
设置 Slack 集成
Section titled “设置 Slack 集成”1. 连接你的 Slack 工作区
Section titled “1. 连接你的 Slack 工作区”- 访问 CrewAI AMP Integrations
- 在 Authentication Integrations 部分找到 Slack
- 点击 Connect 并完成 OAuth 流程
- 授予团队沟通所需权限
- 从 Integration Settings 复制你的 Enterprise Token
2. 安装所需包
Section titled “2. 安装所需包”uv add crewai-tools3. 环境变量设置
Section titled “3. 环境变量设置”export CREWAI_PLATFORM_INTEGRATION_TOKEN="your_enterprise_token"或者将其添加到你的 .env 文件中:
CREWAI_PLATFORM_INTEGRATION_TOKEN=your_enterprise_tokenslack/list_members
说明: 列出 Slack 频道中的所有成员。
参数:
- 不需要参数 - 将检索该频道的所有成员
slack/get_user_by_email
说明: 通过电子邮件地址在 Slack 工作区中查找用户。
参数:
email(string, required): 工作区中某个用户的电子邮件地址
slack/get_users_by_name
说明: 通过姓名或显示名称搜索用户。
参数:
name(string, required): 要搜索的用户真实姓名displayName(string, required): 要搜索的用户显示名称paginationParameters(object, optional): 分页设置pageCursor(string, optional): 分页游标
slack/list_channels
说明: 列出 Slack 工作区中的所有频道。
参数:
- 不需要参数 - 将检索所有可访问的频道
slack/send_message
说明: 向 Slack 频道发送消息。
参数:
channel(string, required): 频道名称或 ID - 使用 Connect Portal Workflow Settings 让用户选择频道,或者输入频道名称来创建新频道message(string, required): 要发送的消息文本botName(string, required): 发送此消息的机器人名称botIcon(string, required): 机器人图标 - 可以是图片 URL 或表情符号(例如":dog:")blocks(object, optional): 用于富消息格式化的 Slack Block Kit JSON,可包含附件和交互元素authenticatedUser(boolean, optional): 如果为 true,消息会显示为来自你已认证的 Slack 用户,而不是应用程序(默认值为 false)
slack/send_direct_message
说明: 向 Slack 中的某个特定用户发送直接消息。
参数:
memberId(string, required): 收件人用户 ID - 使用 Connect Portal Workflow Settings 让用户选择工作区成员message(string, required): 要发送的消息文本botName(string, required): 发送此消息的机器人名称botIcon(string, required): 机器人图标 - 可以是图片 URL 或表情符号(例如":dog:")blocks(object, optional): 用于富消息格式化的 Slack Block Kit JSON,可包含附件和交互元素authenticatedUser(boolean, optional): 如果为 true,消息会显示为来自你已认证的 Slack 用户,而不是应用程序(默认值为 false)
slack/search_messages
说明: 搜索 Slack 工作区中的消息。
参数:
query(string, required): 使用 Slack 搜索语法的查询,用于查找符合指定条件的消息
搜索查询示例:
"project update"- 搜索包含 “project update” 的消息from:@john in:#general- 搜索来自 John 且位于 #general 频道中的消息has:link after:2023-01-01- 搜索 2023 年 1 月 1 日之后包含链接的消息in:@channel before:yesterday- 搜索在特定频道中且早于昨天的消息
Block Kit 集成
Section titled “Block Kit 集成”Slack 的 Block Kit 让你可以创建富有交互性的消息。以下是 blocks 参数的一些用法示例:
带附件的简单文本
Section titled “带附件的简单文本”[ { "text": "I am a test message", "attachments": [ { "text": "And here's an attachment!" } ] }]使用区块进行富格式化
Section titled “使用区块进行富格式化”[ { "type": "section", "text": { "type": "mrkdwn", "text": "*Project Update*\nStatus: ✅ Complete" } }, { "type": "divider" }, { "type": "section", "text": { "type": "plain_text", "text": "All tasks have been completed successfully." } }]基础 Slack 智能体设置
Section titled “基础 Slack 智能体设置”from crewai import Agent, Task, Crew
# Create an agent with Slack capabilitiesslack_agent = Agent( role="Team Communication Manager", goal="Facilitate team communication and coordinate collaboration efficiently", backstory="An AI assistant specialized in team communication and workspace coordination.", apps=['slack'] # All Slack actions will be available)
# Task to send project updatesupdate_task = Task( description="Send a project status update to the #general channel with current progress", agent=slack_agent, expected_output="Project update message sent successfully to team channel")
# Run the taskcrew = Crew( agents=[slack_agent], tasks=[update_task])
crew.kickoff()筛选特定 Slack 工具
Section titled “筛选特定 Slack 工具”from crewai import Agent, Task, Crew
# Create agent with specific Slack actions onlycommunication_manager = Agent( role="Communication Coordinator", goal="Manage team communications and ensure important messages reach the right people", backstory="An experienced communication coordinator who handles team messaging and notifications.", apps=[ 'slack/send_message', 'slack/send_direct_message', 'slack/search_messages' ] # Using canonical action names from canonical_integrations.yml)
# Task to coordinate team communicationcoordination_task = Task( description="Send task completion notifications to team members and update project channels", agent=communication_manager, expected_output="Team notifications sent and project channels updated successfully")
crew = Crew( agents=[communication_manager], tasks=[coordination_task])
crew.kickoff()使用 Block Kit 的高级消息
Section titled “使用 Block Kit 的高级消息”from crewai import Agent, Task, Crew
# Create agent with Slack messaging capabilitiesnotification_agent = Agent( role="Notification Manager", goal="Create rich, interactive notifications and manage workspace communication", backstory="An AI assistant that specializes in creating engaging team notifications and updates.", apps=['slack/send_message'] # Specific action for sending messages)
# Task to send rich notificationsnotification_task = Task( description=""" 1. Send a formatted project completion message to #general with progress charts 2. Send direct messages to team leads with task summaries 3. Create interactive notification with action buttons for team feedback """, agent=notification_agent, expected_output="Rich notifications sent with interactive elements and formatted content")
crew = Crew( agents=[notification_agent], tasks=[notification_task])
crew.kickoff()消息搜索与分析
Section titled “消息搜索与分析”from crewai import Agent, Task, Crew
# Create agent with Slack search and user management capabilitiesanalytics_agent = Agent( role="Communication Analyst", goal="Analyze team communication patterns and extract insights from conversations", backstory="An analytical AI that excels at understanding team dynamics through communication data.", apps=[ 'slack/search_messages', 'slack/get_user_by_email', 'slack/list_members' ] # Using canonical action names from canonical_integrations.yml)
# Complex task involving search and analysisanalysis_task = Task( description=""" 1. Search for recent project-related messages across all channels 2. Find users by email to identify team members 3. Analyze communication patterns and response times 4. Generate weekly team communication summary """, agent=analytics_agent, expected_output="Comprehensive communication analysis with team insights and recommendations")
crew = Crew( agents=[analytics_agent], tasks=[analysis_task])
crew.kickoff()需要帮助?
联系我们的支持团队,获取 Slack 集成设置或故障排查方面的帮助。