Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Commit 96de48a

Browse files
committed
Clean up code, rename action
1 parent e84f7f4 commit 96de48a

File tree

2 files changed

+30
-36
lines changed

2 files changed

+30
-36
lines changed

src/actions/askNotionPage.ts renamed to src/actions/getNotionPageContent.ts

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ActionDefinition, ActionContext, OutputObject } from 'connery';
2-
import { Client, iteratePaginatedAPI, isFullBlock } from '@notionhq/client'; // Import Client and types from Notion
2+
import { Client, iteratePaginatedAPI, isFullBlock } from '@notionhq/client';
33

44
const actionDefinition: ActionDefinition = {
5-
key: 'askNotionPage',
5+
key: 'getNotionPageContent',
66
name: 'Get Notion Page Content',
77
description:
88
'This action retrieves the content of a Notion page using its URL and the Notion API. It can optionally include instructions before the page content. The action required the Notion page URL and Notion API key connected to this URL. It fetches all content elements including text, media, and toggles, and returns the page content as a single string. It does not extract content form inline DBs.',
@@ -41,8 +41,8 @@ const actionDefinition: ActionDefinition = {
4141
},
4242
outputParameters: [
4343
{
44-
key: 'notionContent',
45-
name: 'Notion Content',
44+
key: 'notionPageContent',
45+
name: 'Notion Page Content',
4646
type: 'string',
4747
validation: {
4848
required: true,
@@ -54,40 +54,35 @@ const actionDefinition: ActionDefinition = {
5454
export default actionDefinition;
5555

5656
export async function handler({ input }: ActionContext): Promise<OutputObject> {
57-
try {
58-
// Extract the page ID from the provided Notion URL
59-
const notionPageId = extractPageIdFromUrl(input.notionPageUrl);
57+
// Extract the page ID from the provided Notion URL
58+
const notionPageId = extractPageIdFromUrl(input.notionPageUrl);
6059

61-
// Initialize the Notion client
62-
const notion = new Client({ auth: input.notionApiKey });
60+
// Initialize the Notion client
61+
const notion = new Client({ auth: input.notionApiKey });
6362

64-
// Retrieve all blocks of the Notion page
65-
const blocks = await retrieveBlockChildren(notion, notionPageId);
63+
// Retrieve all blocks of the Notion page
64+
const blocks = await retrieveBlockChildren(notion, notionPageId);
6665

67-
// Process the blocks to get the content as a single string
68-
const pageContent = blocks.map(getTextFromBlock).join('\n');
66+
// Process the blocks to get the content as a single string
67+
const pageContent = blocks.map(getTextFromBlock).join('\n');
6968

70-
// Check if the content length is less than 5 characters
71-
if (pageContent.length < 5) {
72-
throw new Error(
73-
`The extracted content is too short: ${pageContent.length} characters. It must be at least 5 characters long.`,
74-
);
75-
}
76-
77-
// Prepare the output based on whether instructions are provided
78-
let output: string;
79-
if (input.instructions) {
80-
output = `Follow these instructions: ${input.instructions}\nContent: ${pageContent}`;
81-
} else {
82-
output = pageContent;
83-
}
69+
// Check if the content length is less than 5 characters
70+
if (pageContent.length < 5) {
71+
throw new Error(
72+
`The extracted content is too short: ${pageContent.length} characters. It must be at least 5 characters long.`,
73+
);
74+
}
8475

85-
// Return the formatted output
86-
return { notionContent: output };
87-
} catch (error: any) {
88-
console.error('An error occurred:', (error as Error).message);
89-
throw new Error(`Error occurred: ${(error as Error).message}`);
76+
// Prepare the output based on whether instructions are provided
77+
let output: string;
78+
if (input.instructions) {
79+
output = `Follow these instructions: ${input.instructions}\nContent: ${pageContent}`;
80+
} else {
81+
output = pageContent;
9082
}
83+
84+
// Return the formatted output
85+
return { notionPageContent: output };
9186
}
9287

9388
// Helper function to retrieve all blocks from a Notion page using pagination. Recursively fetches child blocks if they exist.

src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { PluginDefinition, setupPluginServer } from 'connery';
2-
import askNotionPage from './actions/askNotionPage.js';
2+
import getNotionPageContent from './actions/getNotionPageContent.js';
33

44
const pluginDefinition: PluginDefinition = {
55
name: 'Notion',
6-
description:
7-
'This plugin enables interaction with Notion-based knowledge repositories, allowing users to query and retrieve answers from both public and private Notion pages. The plugin integrates with OpenAI to provide high-certainty answers based on the content available in Notion and suggests follow-ups in case of missing content.',
8-
actions: [askNotionPage],
6+
description: 'Notion plugin for Connery',
7+
actions: [getNotionPageContent],
98
};
109

1110
const handler = await setupPluginServer(pluginDefinition);

0 commit comments

Comments
 (0)