跳转到内容

Notion 集成

让你的智能体通过 Notion 管理用户并创建评论。你可以访问工作区用户信息,并在页面和讨论中创建评论,从而借助 AI 驱动的自动化简化协作工作流。

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

  • 一个拥有有效订阅的 CrewAI AMP 账户
  • 一个具备相应工作区权限的 Notion 账户
  • 通过 集成页面 连接了你的 Notion 账户
  1. 访问 CrewAI AMP Integrations
  2. 在 Authentication Integrations 部分找到 Notion
  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
notion/list_users

说明: 列出工作区中的所有用户。

参数:

  • page_size (integer, optional): 响应中返回的项目数量。最小值:1,最大值:100,默认值:100
  • start_cursor (string, optional): 分页游标。返回此游标之后的结果。
notion/get_user

说明: 通过 ID 检索某个用户。

参数:

  • user_id (string, required): 要检索的用户 ID。
notion/create_comment

说明: 在页面或讨论中创建评论。

参数:

  • parent (object, required): 要评论的父级页面或讨论。
    {
    "type": "page_id",
    "page_id": "PAGE_ID_HERE"
    }
    {
    "type": "discussion_id",
    "discussion_id": "DISCUSSION_ID_HERE"
    }
  • rich_text (array, required): 评论的富文本内容。
    [
    {
    "type": "text",
    "text": {
    "content": "This is my comment text"
    }
    }
    ]
from crewai import Agent, Task, Crew
# Create an agent with Notion capabilities
notion_agent = Agent(
role="Workspace Manager",
goal="Manage workspace users and facilitate collaboration through comments",
backstory="An AI assistant specialized in user management and team collaboration.",
apps=['notion'] # All Notion actions will be available
)
# Task to list workspace users
user_management_task = Task(
description="List all users in the workspace and provide a summary of team members",
agent=notion_agent,
expected_output="Complete list of workspace users with their details"
)
# Run the task
crew = Crew(
agents=[notion_agent],
tasks=[user_management_task]
)
crew.kickoff()
comment_manager = Agent(
role="Comment Manager",
goal="Create and manage comments on Notion pages",
backstory="An AI assistant that focuses on facilitating discussions through comments.",
apps=['notion/create_comment']
)
# Task to create comments on pages
comment_task = Task(
description="Create a summary comment on the project status page with key updates",
agent=comment_manager,
expected_output="Comment created successfully with project status updates"
)
crew = Crew(
agents=[comment_manager],
tasks=[comment_task]
)
crew.kickoff()
from crewai import Agent, Task, Crew
team_coordinator = Agent(
role="Team Coordinator",
goal="Coordinate team activities and manage user information",
backstory="An AI assistant that helps coordinate team activities and manages user information.",
apps=['notion']
)
# Task to coordinate team activities
coordination_task = Task(
description="""
1. List all users in the workspace
2. Get detailed information for specific team members
3. Create comments on relevant pages to notify team members about updates
""",
agent=team_coordinator,
expected_output="Team coordination completed with user information gathered and notifications sent"
)
crew = Crew(
agents=[team_coordinator],
tasks=[coordination_task]
)
crew.kickoff()
from crewai import Agent, Task, Crew
collaboration_facilitator = Agent(
role="Collaboration Facilitator",
goal="Facilitate team collaboration through comments and user management",
backstory="An AI assistant that specializes in team collaboration and communication.",
apps=['notion']
)
# Task to facilitate collaboration
collaboration_task = Task(
description="""
1. Identify active users in the workspace
2. Create contextual comments on project pages to facilitate discussions
3. Provide status updates and feedback through comments
""",
agent=collaboration_facilitator,
expected_output="Collaboration facilitated with comments created and team members notified"
)
crew = Crew(
agents=[collaboration_facilitator],
tasks=[collaboration_task]
)
crew.kickoff()
from crewai import Agent, Task, Crew
communication_automator = Agent(
role="Communication Automator",
goal="Automate team communication and user management workflows",
backstory="An AI assistant that automates communication workflows and manages user interactions.",
apps=['notion']
)
# Complex communication automation task
automation_task = Task(
description="""
1. List all workspace users and identify team roles
2. Get specific user information for project stakeholders
3. Create automated status update comments on key project pages
4. Facilitate team communication through targeted comments
""",
agent=communication_automator,
expected_output="Automated communication workflow completed with user management and comments"
)
crew = Crew(
agents=[communication_automator],
tasks=[automation_task]
)
crew.kickoff()