Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
**/.DS_Store
# Node modules
node_modules/

# Environment variables
.env

# Build / output folders
dist/
build/

# Logs
npm-debug.log
*.log

# Windows system files
Thumbs.db
ehthumbs.db
Desktop.ini

# VS Code workspace settings
.vscode/
54 changes: 54 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dependencies": {
"@notionhq/client": "^5.3.0",
"dotenv": "^17.2.3"
},
"devDependencies": {
"@types/node": "^24.8.1"
}
}
91 changes: 91 additions & 0 deletions templates/notionassistant/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Notion Assistant AgentKit

A Notion Assistant AgentKit to query and manage your Notion workspace.

---

## Folder Structure

/actions # Orchestrator / agent actions
/templates/notionassistant # This agent's folder
/lamatic-config.json # Agent configuration
/package.json # Scripts & dependencies
/README.md # This documentation

---

## Setup

### 1. Configure Environment Variables

Create a `.env` file in the **project root** (`AgentKit/.env`) with your configuration:

NOTION_API_KEY=your_notion_secret_key
DATABASE_ID=your_database_id

> Make sure the Notion integration has access to the database you want to use.

---

### 2. Install Dependencies

```bash
cd templates/notionassistant
npm install
```

---

### 3. Run Locally

```bash
npm run dev
```

You should see:

✅ Connected to Notion DB: Tasks

---

## Example Queries

**List databases**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Use proper heading syntax instead of bold text.

Lines 53 and 59 use bold formatting for what should be semantic headings. This affects document structure and accessibility.

📝 Fix markdown heading syntax
-**List databases**
+### List databases

 ```javascript
 await handleQuery("list databases");

-Create a new page
+### Create a new page

await handleQuery("create page");
</details>

Based on static analysis hints (markdownlint MD036).


Also applies to: 59-59

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.18.1)</summary>

53-53: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

</details>

</details>

<details>
<summary>🤖 Prompt for AI Agents</summary>

In @templates/notionassistant/README.md at line 53, Replace the bold-format
section titles with proper Markdown headings: change "List databases" to a
heading (e.g., "### List databases") and change the bold "Create a new page" to
"### Create a new page" so these become semantic headings; update the two
occurrences referenced by their text content ("List databases" and "Create a new
page") and keep the surrounding code blocks unchanged.


</details>

<!-- fingerprinting:phantom:triton:puma -->

<!-- This is an auto-generated comment by CodeRabbit -->


```javascript
await handleQuery("list databases");
```

**Create a new page**

```javascript
await handleQuery("create page");
```

Pages are created in the database specified in your `.env`.

---

## Dependencies

- `@notionhq/client` → Notion SDK
- `dotenv` → Load environment variables
- `lamatic` → Lamatic AgentKit support
- `ts-node` → Run TypeScript files directly
- `typescript` → TypeScript support

---

## Contributing

Follow `CONTRIBUTING.md` guidelines. Make sure:

- `.env` is never committed
- All changes are tested locally
- Pull request includes updated `README.md` and `lamatic-config.json`

---

## Author

Meghana-2124
83 changes: 83 additions & 0 deletions templates/notionassistant/actions/orchestrate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import dotenv from "dotenv";
import { Client } from "@notionhq/client";

dotenv.config();

// ✅ Load environment variables (matching your .env exactly)
const NOTION_API_KEY = process.env.NOTION_API_KEY;
let DATABASE_ID = process.env.DATABASE_ID;

if (!NOTION_API_KEY) {
throw new Error("❌ NOTION_API_KEY is missing in your .env file!");
}
if (!DATABASE_ID) {
throw new Error("❌ DATABASE_ID is missing in your .env file!");
}

// ✅ Clean DATABASE_ID (remove dashes if present)
DATABASE_ID = DATABASE_ID.replace(/-/g, '');

// Optional: check ID length (Notion database IDs are 32 chars)
if (DATABASE_ID.length !== 32) {
throw new Error(
"❌ Database_Id seems invalid. It should be a 32-character Notion database ID (no dashes)."
);
}

// ✅ Initialize Notion client
const notion = new Client({ auth: NOTION_API_KEY });

// ✅ Step 1: Test connection to your Notion database
async function testNotionConnection() {
try {
// Use non-null assertion directly to satisfy TypeScript
const res: any = await notion.databases.retrieve({
database_id: DATABASE_ID!,
});

const dbTitle = res?.title?.[0]?.plain_text || "Untitled Database";
console.log("✅ Connected to Notion DB:", dbTitle);
} catch (err: any) {
console.error("❌ Notion connection failed:", err.message);
if (err.code === "unauthorized") {
console.error(
"⚠️ Your Notion_Api_Key might be invalid or the integration does not have access to the database."
);
}
}
}

// Run the test immediately
testNotionConnection();

// ✅ Step 2: Handle queries dynamically
export async function handleQuery(query: string) {
if (query.toLowerCase().includes("list databases")) {
const res = await notion.search({
filter: { property: "object", value: "database" } as any,
});

return res.results.map((db: any) => ({
name: db?.title?.[0]?.plain_text || "Untitled DB",
id: db.id,
}));
}

if (query.toLowerCase().includes("create page")) {
// Use non-null assertion directly for TypeScript
const res = await notion.pages.create({
parent: { database_id: DATABASE_ID! },
properties: {
// Cast to any to satisfy strict TypeScript types
Name: {
title: [{ text: { content: "New Task from Assistant AgentKit" } }],
} as any,
Priority: { select: { name: "High" } } as any,
},
});

return { success: true, pageId: res.id };
}

return { message: "Command not recognized." };
}
Comment on lines +54 to +83
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Missing error handling in handleQuery.

The handleQuery function doesn't wrap Notion API calls in try-catch blocks. If the API call fails (network error, rate limit, invalid permissions), the error will propagate unhandled, potentially crashing the application.

Suggested fix with error handling
 export async function handleQuery(query: string) {
+  try {
   if (query.toLowerCase().includes("list databases")) {
     const res = await notion.search({
       filter: { property: "object", value: "database" } as any,
     });

     return res.results.map((db: any) => ({
       name: db?.title?.[0]?.plain_text || "Untitled DB",
       id: db.id,
     }));
   }

   if (query.toLowerCase().includes("create page")) {
-    // Use non-null assertion directly for TypeScript
     const res = await notion.pages.create({
       parent: { database_id: DATABASE_ID! },
       properties: {
-        // Cast to any to satisfy strict TypeScript types
         Name: {
           title: [{ text: { content: "New Task from Assistant AgentKit" } }],
         } as any,
         Priority: { select: { name: "High" } } as any,
       },
     });

     return { success: true, pageId: res.id };
   }

   return { message: "Command not recognized." };
+  } catch (err: any) {
+    return { success: false, error: err.message || "Notion API error" };
+  }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export async function handleQuery(query: string) {
if (query.toLowerCase().includes("list databases")) {
const res = await notion.search({
filter: { property: "object", value: "database" } as any,
});
return res.results.map((db: any) => ({
name: db?.title?.[0]?.plain_text || "Untitled DB",
id: db.id,
}));
}
if (query.toLowerCase().includes("create page")) {
// Use non-null assertion directly for TypeScript
const res = await notion.pages.create({
parent: { database_id: DATABASE_ID! },
properties: {
// Cast to any to satisfy strict TypeScript types
Name: {
title: [{ text: { content: "New Task from Assistant AgentKit" } }],
} as any,
Priority: { select: { name: "High" } } as any,
},
});
return { success: true, pageId: res.id };
}
return { message: "Command not recognized." };
}
export async function handleQuery(query: string) {
try {
if (query.toLowerCase().includes("list databases")) {
const res = await notion.search({
filter: { property: "object", value: "database" } as any,
});
return res.results.map((db: any) => ({
name: db?.title?.[0]?.plain_text || "Untitled DB",
id: db.id,
}));
}
if (query.toLowerCase().includes("create page")) {
const res = await notion.pages.create({
parent: { database_id: DATABASE_ID! },
properties: {
Name: {
title: [{ text: { content: "New Task from Assistant AgentKit" } }],
} as any,
Priority: { select: { name: "High" } } as any,
},
});
return { success: true, pageId: res.id };
}
return { message: "Command not recognized." };
} catch (err: any) {
return { success: false, error: err.message || "Notion API error" };
}
}

Empty file.
6 changes: 6 additions & 0 deletions templates/notionassistant/lamatic-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "notionassistant",
"description": "A Notion Assistant AgentKit to query and manage your Notion workspace.",
"api_keys_required": ["NOTION_API_KEY"],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing DATABASE_ID in required keys.

The orchestrate.ts module requires both NOTION_API_KEY and DATABASE_ID environment variables, but only NOTION_API_KEY is listed here. Consider adding DATABASE_ID to ensure users know all required configuration:

Suggested fix
-  "api_keys_required": ["NOTION_API_KEY"],
+  "api_keys_required": ["NOTION_API_KEY", "DATABASE_ID"],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"api_keys_required": ["NOTION_API_KEY"],
"api_keys_required": ["NOTION_API_KEY", "DATABASE_ID"],
🤖 Prompt for AI Agents
In @templates/notionassistant/lamatic-config.json at line 4, The config lists
only "NOTION_API_KEY" under the api_keys_required array but orchestrate.ts
expects both NOTION_API_KEY and DATABASE_ID; update the "api_keys_required"
value to include "DATABASE_ID" alongside "NOTION_API_KEY" so the
lamatic-config.json explicitly declares both required environment keys
referenced by orchestrate.ts.

"author": "Meghana-2124"
}
Empty file.
Loading