Skip to Content

Introduction


Made by luke0408, Korean military soldier

Set up a fully functional Notion Agent powered by OpenAIโ€™s GPT model quickly using the Agentica CLI. This agent lets you read, create, and update Notion pages effortlessly.

Quick CLI Setup

Start the Agentica Setup Wizard with a single command:

npx agentica start notion-agent

The wizard will guide you through:

  • Installing required packages (e.g., [email protected])
  • Choosing your package manager and project type
  • Selecting the NOTION controller
  • Entering your OPENAI_API_KEY

Once complete, Agentica automatically generates your code, creates a .env file, and installs all dependencies.

Generated Code Overview

The generated code looks like this:

import { Agentica } from "@agentica/core"; import typia from "typia"; import dotenv from "dotenv"; import { OpenAI } from "openai"; import { NotionService } from "@wrtnlabs/connector-notion"; dotenv.config(); export const agent = new Agentica({ model: "chatgpt", vendor: { api: new OpenAI({ apiKey: process.env.OPENAI_API_KEY!, }), model: "gpt-4o-mini", }, controllers: [ { name: "Notion Connector", protocol: "class", application: typia.llm.application<NotionService, "chatgpt">(), execute: new NotionService(), }, ], }); const main = async () => { console.log(await agent.conversate("What can you do?")); }; main();

This code instantly sets up your Notion Agent, ready to interact with your Notion workspace by reading pages, retrieving content, and creating or updating pages using natural language commands.

Notion API Setup

Before running the agent, configure your Notion API credentials:

  1. Integration:

  2. Permissions:

    • Enable the necessary permissions (reading, updating, creating pages, etc.) during setup.
  3. Data Sharing:

    • Share your relevant Notion pages or databases with your integration.

Add the following to your .env file:

OPENAI_API_KEY=your-openai-api-key NOTION_SECRET_KEY=your-notion-secret-key

What This Does

Your Notion Agent can:

  • Retrieve a List of Pages: Use readPageList to get your Notion pages.
  • Read Page Contents: Fetch detailed content via readPageContents.
  • Create New Pages: Automatically format and create pages using createPageByMarkdown.
  • Update Existing Pages: Modify page content with updatePageContent.

Leveraging OpenAIโ€™s GPT model, the agent translates natural language queries into API calls, making it easy to interact with your Notion workspace.

Use Case Example

Imagine asking the agent:

โ€œSummarize the latest meeting discussion and create a new page with the summary.โ€

The agent will process your query by summarizing the content and execute createPageByMarkdown to create a new page with the formatted summary. You can also update existing pages through natural language commands.

Available Functions

For a complete list of functions available in NotionService, check out the source code:
๐Ÿ‘‰ wrtnlabs/connectors - NotionService.tsโ€‰

Your AI-powered Notion Agent is now ready to streamline your Notion interactions! Enjoy harnessing the power of natural language with your Notion data. ๐Ÿš€

Last updated on