跳转到内容

Slack 集成

让你的智能体通过 Slack 管理团队沟通。你可以发送消息、搜索对话、管理频道,并协调团队活动,从而借助 AI 驱动的自动化简化协作工作流。

在使用 Slack 集成之前,请确保你已具备:

  • 一个拥有有效订阅的 CrewAI AMP 账户
  • 一个具备相应权限的 Slack 工作区
  • 通过 集成页面 连接了你的 Slack 工作区
  1. 访问 CrewAI AMP Integrations
  2. 在 Authentication Integrations 部分找到 Slack
  3. 点击 Connect 并完成 OAuth 流程
  4. 授予团队沟通所需权限
  5. Integration Settings 复制你的 Enterprise Token
Terminal window
uv add crewai-tools
Terminal window
export CREWAI_PLATFORM_INTEGRATION_TOKEN="your_enterprise_token"

或者将其添加到你的 .env 文件中:

CREWAI_PLATFORM_INTEGRATION_TOKEN=your_enterprise_token
slack/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 - 搜索在特定频道中且早于昨天的消息

Slack 的 Block Kit 让你可以创建富有交互性的消息。以下是 blocks 参数的一些用法示例:

[
{
"text": "I am a test message",
"attachments": [
{
"text": "And here's an attachment!"
}
]
}
]
[
{
"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."
}
}
]
from crewai import Agent, Task, Crew
# Create an agent with Slack capabilities
slack_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 updates
update_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 task
crew = Crew(
agents=[slack_agent],
tasks=[update_task]
)
crew.kickoff()
from crewai import Agent, Task, Crew
# Create agent with specific Slack actions only
communication_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 communication
coordination_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()
from crewai import Agent, Task, Crew
# Create agent with Slack messaging capabilities
notification_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 notifications
notification_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()
from crewai import Agent, Task, Crew
# Create agent with Slack search and user management capabilities
analytics_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 analysis
analysis_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 集成设置或故障排查方面的帮助。