n8n-nodes-notion-advanced 1.1.26-beta → 1.1.27-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M4.459 4.208c.746.606 1.026.56 2.428.466l13.215-.793c.28 0 .047-.28-.046-.326L17.86 1.968c-.42-.326-.981-.7-2.055-.607L3.533 2.221c-.466.047-.56.28-.374.466l1.3.979zM5.206 6.678v14.018c0 .746.373 1.027 1.214.98l14.523-.84c.841-.046.935-.56.935-1.167V6.305c0-.607-.28-.887-.747-.84l-15.177.887c-.56.047-.748.327-.748.746v-.42zm14.337.793c.093.42 0 .84-.42.888l-.7.14v10.264c-.608.327-1.168.514-1.635.514-.748 0-.935-.234-1.495-.933l-4.577-7.186v6.952L12.21 18s0 .84-1.168.84l-3.222.186c-.093-.186 0-.653.327-.746l.84-.233V9.854L7.822 9.76c-.094-.42.14-1.026.793-1.073l3.456-.233 4.764 7.279v-6.44l-1.215-.139c-.093-.514.28-.887.747-.933l3.176-.233z" fill="currentColor"/>
3
+ </svg>
@@ -0,0 +1,13 @@
1
+ import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription, IDataObject } from 'n8n-workflow';
2
+ export declare class NotionAITool implements INodeType {
3
+ description: INodeTypeDescription;
4
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
5
+ static createPageWithContent(executeFunctions: IExecuteFunctions, itemIndex: number): Promise<IDataObject>;
6
+ static addContentToPage(executeFunctions: IExecuteFunctions, itemIndex: number): Promise<IDataObject>;
7
+ static searchPages(executeFunctions: IExecuteFunctions, itemIndex: number): Promise<IDataObject>;
8
+ static updatePageProperties(executeFunctions: IExecuteFunctions, itemIndex: number): Promise<IDataObject>;
9
+ static createDatabaseEntry(executeFunctions: IExecuteFunctions, itemIndex: number): Promise<IDataObject>;
10
+ static queryDatabase(executeFunctions: IExecuteFunctions, itemIndex: number): Promise<IDataObject>;
11
+ static parseContentToBlocks(content: string): IDataObject[];
12
+ static parsePropertiesToUpdate(propertiesString: string): IDataObject;
13
+ }
@@ -0,0 +1,566 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotionAITool = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ const NotionUtils_1 = require("./NotionUtils");
6
+ class NotionAITool {
7
+ constructor() {
8
+ this.description = {
9
+ displayName: 'Notion AI Tool',
10
+ name: 'notionAiTool',
11
+ icon: 'file:notion.svg',
12
+ group: ['ai'],
13
+ version: 1,
14
+ subtitle: '={{$parameter["operation"]}}',
15
+ description: 'AI-powered tool for creating and managing Notion content. Designed for use with AI Agent Nodes.',
16
+ defaults: {
17
+ name: 'Notion AI Tool',
18
+ },
19
+ inputs: ['main'],
20
+ outputs: ['main'],
21
+ usableAsTool: true,
22
+ codex: {
23
+ categories: ['Productivity', 'AI', 'Documentation'],
24
+ subcategories: {
25
+ 'Productivity': ['Notion', 'Knowledge Management'],
26
+ 'AI': ['AI Agent Tools', 'Natural Language Processing'],
27
+ 'Documentation': ['Page Creation', 'Content Management']
28
+ },
29
+ resources: {
30
+ primaryDocumentation: [
31
+ {
32
+ url: 'https://github.com/AZ-IT-US/n8n-notion-advanced-node#ai-tool-usage',
33
+ },
34
+ ],
35
+ },
36
+ alias: ['notion', 'productivity', 'ai-tool', 'pages', 'database'],
37
+ },
38
+ credentials: [
39
+ {
40
+ name: 'notionApi',
41
+ required: true,
42
+ },
43
+ ],
44
+ properties: [
45
+ {
46
+ displayName: 'Operation',
47
+ name: 'operation',
48
+ type: 'options',
49
+ noDataExpression: true,
50
+ options: [
51
+ {
52
+ name: 'Create Page with Content',
53
+ value: 'createPageWithContent',
54
+ description: 'Create a new Notion page with structured content including text, headings, lists, and formatting',
55
+ action: 'Create a Notion page with content',
56
+ },
57
+ {
58
+ name: 'Add Content to Page',
59
+ value: 'addContentToPage',
60
+ description: 'Append new content blocks (paragraphs, headings, lists, etc.) to an existing Notion page',
61
+ action: 'Add content to existing page',
62
+ },
63
+ {
64
+ name: 'Search and Retrieve Pages',
65
+ value: 'searchPages',
66
+ description: 'Search for Notion pages by title, content, or properties and retrieve their information',
67
+ action: 'Search and retrieve pages',
68
+ },
69
+ {
70
+ name: 'Update Page Properties',
71
+ value: 'updatePageProperties',
72
+ description: 'Update page title, properties, status, tags, or other metadata',
73
+ action: 'Update page properties',
74
+ },
75
+ {
76
+ name: 'Create Database Entry',
77
+ value: 'createDatabaseEntry',
78
+ description: 'Create a new entry in a Notion database with specified properties and values',
79
+ action: 'Create database entry',
80
+ },
81
+ {
82
+ name: 'Query Database',
83
+ value: 'queryDatabase',
84
+ description: 'Search and filter database entries based on criteria and retrieve matching records',
85
+ action: 'Query database',
86
+ },
87
+ ],
88
+ default: 'createPageWithContent',
89
+ },
90
+ // CREATE PAGE WITH CONTENT
91
+ {
92
+ displayName: 'Page Title',
93
+ name: 'pageTitle',
94
+ type: 'string',
95
+ required: true,
96
+ displayOptions: {
97
+ show: {
98
+ operation: ['createPageWithContent'],
99
+ },
100
+ },
101
+ default: '',
102
+ description: 'The title of the new page to create',
103
+ },
104
+ {
105
+ displayName: 'Parent Page/Database ID',
106
+ name: 'parentId',
107
+ type: 'string',
108
+ required: true,
109
+ displayOptions: {
110
+ show: {
111
+ operation: ['createPageWithContent', 'createDatabaseEntry'],
112
+ },
113
+ },
114
+ default: '',
115
+ description: 'ID of the parent page or database where this should be created. Can be a Notion URL or page ID.',
116
+ },
117
+ {
118
+ displayName: 'Content',
119
+ name: 'content',
120
+ type: 'string',
121
+ typeOptions: {
122
+ rows: 6,
123
+ },
124
+ displayOptions: {
125
+ show: {
126
+ operation: ['createPageWithContent', 'addContentToPage'],
127
+ },
128
+ },
129
+ default: '',
130
+ description: 'The content to add. Use natural language - AI will structure it into appropriate blocks (headings, paragraphs, lists, etc.)',
131
+ placeholder: 'Example:\n# Main Heading\nThis is a paragraph with **bold** and *italic* text.\n\n## Subheading\n- First bullet point\n- Second bullet point\n\n> This is a quote block',
132
+ },
133
+ // ADD CONTENT TO PAGE
134
+ {
135
+ displayName: 'Target Page ID',
136
+ name: 'targetPageId',
137
+ type: 'string',
138
+ required: true,
139
+ displayOptions: {
140
+ show: {
141
+ operation: ['addContentToPage', 'updatePageProperties'],
142
+ },
143
+ },
144
+ default: '',
145
+ description: 'ID or URL of the existing page to modify',
146
+ },
147
+ // SEARCH PAGES
148
+ {
149
+ displayName: 'Search Query',
150
+ name: 'searchQuery',
151
+ type: 'string',
152
+ displayOptions: {
153
+ show: {
154
+ operation: ['searchPages'],
155
+ },
156
+ },
157
+ default: '',
158
+ description: 'Search terms to find pages. Leave empty to get all pages.',
159
+ },
160
+ // UPDATE PAGE PROPERTIES
161
+ {
162
+ displayName: 'Properties to Update',
163
+ name: 'propertiesToUpdate',
164
+ type: 'string',
165
+ typeOptions: {
166
+ rows: 4,
167
+ },
168
+ displayOptions: {
169
+ show: {
170
+ operation: ['updatePageProperties'],
171
+ },
172
+ },
173
+ default: '',
174
+ description: 'Properties to update in JSON format or natural language. Example: {"status": "In Progress", "priority": "High"} or "Set status to Done and priority to Low"',
175
+ },
176
+ // DATABASE OPERATIONS
177
+ {
178
+ displayName: 'Database ID',
179
+ name: 'databaseId',
180
+ type: 'string',
181
+ required: true,
182
+ displayOptions: {
183
+ show: {
184
+ operation: ['queryDatabase'],
185
+ },
186
+ },
187
+ default: '',
188
+ description: 'ID or URL of the database to query',
189
+ },
190
+ {
191
+ displayName: 'Entry Properties',
192
+ name: 'entryProperties',
193
+ type: 'string',
194
+ typeOptions: {
195
+ rows: 4,
196
+ },
197
+ displayOptions: {
198
+ show: {
199
+ operation: ['createDatabaseEntry'],
200
+ },
201
+ },
202
+ default: '',
203
+ description: 'Properties for the new database entry in JSON format or natural language description',
204
+ },
205
+ {
206
+ displayName: 'Query Filter',
207
+ name: 'queryFilter',
208
+ type: 'string',
209
+ displayOptions: {
210
+ show: {
211
+ operation: ['queryDatabase'],
212
+ },
213
+ },
214
+ default: '',
215
+ description: 'Filter criteria in natural language (e.g., "status is Done and priority is High") or JSON format',
216
+ },
217
+ // COMMON OPTIONS
218
+ {
219
+ displayName: 'Additional Options',
220
+ name: 'additionalOptions',
221
+ type: 'collection',
222
+ placeholder: 'Add Option',
223
+ default: {},
224
+ options: [
225
+ {
226
+ displayName: 'Icon',
227
+ name: 'icon',
228
+ type: 'string',
229
+ default: '',
230
+ description: 'Emoji icon for the page (e.g., 📝, 🎯, 📊)',
231
+ },
232
+ {
233
+ displayName: 'Cover Image URL',
234
+ name: 'coverUrl',
235
+ type: 'string',
236
+ default: '',
237
+ description: 'URL of cover image for the page',
238
+ },
239
+ {
240
+ displayName: 'Max Results',
241
+ name: 'maxResults',
242
+ type: 'number',
243
+ default: 20,
244
+ description: 'Maximum number of results to return (1-100)',
245
+ },
246
+ ],
247
+ },
248
+ ],
249
+ };
250
+ }
251
+ async execute() {
252
+ const items = this.getInputData();
253
+ const responseData = [];
254
+ // Validate credentials
255
+ const isValid = await NotionUtils_1.validateCredentials.call(this);
256
+ if (!isValid) {
257
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Invalid Notion API credentials');
258
+ }
259
+ for (let i = 0; i < items.length; i++) {
260
+ try {
261
+ const operation = this.getNodeParameter('operation', i);
262
+ let result;
263
+ switch (operation) {
264
+ case 'createPageWithContent':
265
+ result = await NotionAITool.createPageWithContent(this, i);
266
+ break;
267
+ case 'addContentToPage':
268
+ result = await NotionAITool.addContentToPage(this, i);
269
+ break;
270
+ case 'searchPages':
271
+ result = await NotionAITool.searchPages(this, i);
272
+ break;
273
+ case 'updatePageProperties':
274
+ result = await NotionAITool.updatePageProperties(this, i);
275
+ break;
276
+ case 'createDatabaseEntry':
277
+ result = await NotionAITool.createDatabaseEntry(this, i);
278
+ break;
279
+ case 'queryDatabase':
280
+ result = await NotionAITool.queryDatabase(this, i);
281
+ break;
282
+ default:
283
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown operation: ${operation}`);
284
+ }
285
+ responseData.push({
286
+ operation,
287
+ success: true,
288
+ ...result,
289
+ });
290
+ }
291
+ catch (error) {
292
+ if (this.continueOnFail()) {
293
+ responseData.push({
294
+ error: error.message,
295
+ success: false,
296
+ });
297
+ }
298
+ else {
299
+ throw error;
300
+ }
301
+ }
302
+ }
303
+ return [this.helpers.returnJsonArray(responseData)];
304
+ }
305
+ static async createPageWithContent(executeFunctions, itemIndex) {
306
+ const pageTitle = executeFunctions.getNodeParameter('pageTitle', itemIndex);
307
+ const parentId = executeFunctions.getNodeParameter('parentId', itemIndex);
308
+ const content = executeFunctions.getNodeParameter('content', itemIndex, '');
309
+ const additionalOptions = executeFunctions.getNodeParameter('additionalOptions', itemIndex, {});
310
+ const resolvedParentId = await NotionUtils_1.resolvePageId.call(executeFunctions, parentId);
311
+ // Create the page first
312
+ const pageBody = {
313
+ parent: { page_id: resolvedParentId },
314
+ properties: {
315
+ title: {
316
+ title: [(0, NotionUtils_1.createRichText)(pageTitle)],
317
+ },
318
+ },
319
+ };
320
+ // Add icon and cover if provided
321
+ if (additionalOptions.icon) {
322
+ pageBody.icon = { type: 'emoji', emoji: additionalOptions.icon };
323
+ }
324
+ if (additionalOptions.coverUrl) {
325
+ pageBody.cover = { type: 'external', external: { url: additionalOptions.coverUrl } };
326
+ }
327
+ const page = await NotionUtils_1.notionApiRequest.call(executeFunctions, 'POST', '/pages', pageBody);
328
+ // If content is provided, add it to the page
329
+ if (content) {
330
+ const blocks = NotionAITool.parseContentToBlocks(content);
331
+ if (blocks.length > 0) {
332
+ await NotionUtils_1.notionApiRequest.call(executeFunctions, 'PATCH', `/blocks/${page.id}/children`, {
333
+ children: blocks,
334
+ });
335
+ }
336
+ }
337
+ return {
338
+ pageId: page.id,
339
+ title: pageTitle,
340
+ url: page.url,
341
+ message: `Created page "${pageTitle}" with content`,
342
+ };
343
+ }
344
+ static async addContentToPage(executeFunctions, itemIndex) {
345
+ const targetPageId = executeFunctions.getNodeParameter('targetPageId', itemIndex);
346
+ const content = executeFunctions.getNodeParameter('content', itemIndex);
347
+ const resolvedPageId = await NotionUtils_1.resolvePageId.call(executeFunctions, targetPageId);
348
+ const blocks = NotionAITool.parseContentToBlocks(content);
349
+ if (blocks.length === 0) {
350
+ throw new n8n_workflow_1.NodeOperationError(executeFunctions.getNode(), 'No valid content blocks found to add');
351
+ }
352
+ const result = await NotionUtils_1.notionApiRequest.call(executeFunctions, 'PATCH', `/blocks/${resolvedPageId}/children`, {
353
+ children: blocks,
354
+ });
355
+ return {
356
+ pageId: resolvedPageId,
357
+ blocksAdded: blocks.length,
358
+ message: `Added ${blocks.length} content blocks to page`,
359
+ result,
360
+ };
361
+ }
362
+ static async searchPages(executeFunctions, itemIndex) {
363
+ var _a, _b;
364
+ const searchQuery = executeFunctions.getNodeParameter('searchQuery', itemIndex, '');
365
+ const additionalOptions = executeFunctions.getNodeParameter('additionalOptions', itemIndex, {});
366
+ const maxResults = additionalOptions.maxResults || 20;
367
+ const body = {
368
+ page_size: Math.min(maxResults, 100),
369
+ };
370
+ if (searchQuery) {
371
+ body.query = searchQuery;
372
+ }
373
+ body.filter = {
374
+ property: 'object',
375
+ value: 'page',
376
+ };
377
+ const response = await NotionUtils_1.notionApiRequest.call(executeFunctions, 'POST', '/search', body);
378
+ return {
379
+ totalResults: ((_a = response.results) === null || _a === void 0 ? void 0 : _a.length) || 0,
380
+ pages: response.results || [],
381
+ message: `Found ${((_b = response.results) === null || _b === void 0 ? void 0 : _b.length) || 0} pages`,
382
+ };
383
+ }
384
+ static async updatePageProperties(executeFunctions, itemIndex) {
385
+ const targetPageId = executeFunctions.getNodeParameter('targetPageId', itemIndex);
386
+ const propertiesToUpdate = executeFunctions.getNodeParameter('propertiesToUpdate', itemIndex);
387
+ const resolvedPageId = await NotionUtils_1.resolvePageId.call(executeFunctions, targetPageId);
388
+ const properties = NotionAITool.parsePropertiesToUpdate(propertiesToUpdate);
389
+ const result = await NotionUtils_1.notionApiRequest.call(executeFunctions, 'PATCH', `/pages/${resolvedPageId}`, {
390
+ properties,
391
+ });
392
+ return {
393
+ pageId: resolvedPageId,
394
+ updatedProperties: Object.keys(properties),
395
+ message: `Updated ${Object.keys(properties).length} properties`,
396
+ result,
397
+ };
398
+ }
399
+ static async createDatabaseEntry(executeFunctions, itemIndex) {
400
+ const parentId = executeFunctions.getNodeParameter('parentId', itemIndex);
401
+ const entryProperties = executeFunctions.getNodeParameter('entryProperties', itemIndex);
402
+ const resolvedParentId = await NotionUtils_1.resolvePageId.call(executeFunctions, parentId);
403
+ const properties = NotionAITool.parsePropertiesToUpdate(entryProperties);
404
+ const result = await NotionUtils_1.notionApiRequest.call(executeFunctions, 'POST', '/pages', {
405
+ parent: { database_id: resolvedParentId },
406
+ properties,
407
+ });
408
+ return {
409
+ entryId: result.id,
410
+ databaseId: resolvedParentId,
411
+ message: 'Created new database entry',
412
+ result,
413
+ };
414
+ }
415
+ static async queryDatabase(executeFunctions, itemIndex) {
416
+ var _a, _b;
417
+ const databaseId = executeFunctions.getNodeParameter('databaseId', itemIndex);
418
+ const queryFilter = executeFunctions.getNodeParameter('queryFilter', itemIndex, '');
419
+ const additionalOptions = executeFunctions.getNodeParameter('additionalOptions', itemIndex, {});
420
+ const maxResults = additionalOptions.maxResults || 20;
421
+ const resolvedDatabaseId = await NotionUtils_1.resolvePageId.call(executeFunctions, databaseId);
422
+ const body = {
423
+ page_size: Math.min(maxResults, 100),
424
+ };
425
+ if (queryFilter) {
426
+ try {
427
+ body.filter = JSON.parse(queryFilter);
428
+ }
429
+ catch {
430
+ // If not JSON, create a simple text filter
431
+ body.filter = {
432
+ property: 'Name',
433
+ title: {
434
+ contains: queryFilter,
435
+ },
436
+ };
437
+ }
438
+ }
439
+ const response = await NotionUtils_1.notionApiRequest.call(executeFunctions, 'POST', `/databases/${resolvedDatabaseId}/query`, body);
440
+ return {
441
+ databaseId: resolvedDatabaseId,
442
+ totalResults: ((_a = response.results) === null || _a === void 0 ? void 0 : _a.length) || 0,
443
+ entries: response.results || [],
444
+ message: `Found ${((_b = response.results) === null || _b === void 0 ? void 0 : _b.length) || 0} database entries`,
445
+ };
446
+ }
447
+ static parseContentToBlocks(content) {
448
+ const blocks = [];
449
+ const lines = content.split('\n');
450
+ for (let i = 0; i < lines.length; i++) {
451
+ const line = lines[i].trim();
452
+ if (!line)
453
+ continue;
454
+ // Parse different content types
455
+ if (line.startsWith('# ')) {
456
+ blocks.push({
457
+ object: 'block',
458
+ type: 'heading_1',
459
+ heading_1: {
460
+ rich_text: [(0, NotionUtils_1.createRichText)(line.substring(2))],
461
+ },
462
+ });
463
+ }
464
+ else if (line.startsWith('## ')) {
465
+ blocks.push({
466
+ object: 'block',
467
+ type: 'heading_2',
468
+ heading_2: {
469
+ rich_text: [(0, NotionUtils_1.createRichText)(line.substring(3))],
470
+ },
471
+ });
472
+ }
473
+ else if (line.startsWith('### ')) {
474
+ blocks.push({
475
+ object: 'block',
476
+ type: 'heading_3',
477
+ heading_3: {
478
+ rich_text: [(0, NotionUtils_1.createRichText)(line.substring(4))],
479
+ },
480
+ });
481
+ }
482
+ else if (line.startsWith('- ') || line.startsWith('* ')) {
483
+ blocks.push({
484
+ object: 'block',
485
+ type: 'bulleted_list_item',
486
+ bulleted_list_item: {
487
+ rich_text: [(0, NotionUtils_1.createRichText)(line.substring(2))],
488
+ },
489
+ });
490
+ }
491
+ else if (line.match(/^\d+\. /)) {
492
+ blocks.push({
493
+ object: 'block',
494
+ type: 'numbered_list_item',
495
+ numbered_list_item: {
496
+ rich_text: [(0, NotionUtils_1.createRichText)(line.replace(/^\d+\. /, ''))],
497
+ },
498
+ });
499
+ }
500
+ else if (line.startsWith('> ')) {
501
+ blocks.push({
502
+ object: 'block',
503
+ type: 'quote',
504
+ quote: {
505
+ rich_text: [(0, NotionUtils_1.createRichText)(line.substring(2))],
506
+ },
507
+ });
508
+ }
509
+ else if (line.startsWith('```')) {
510
+ // Handle code blocks
511
+ const codeLines = [];
512
+ i++; // Skip the opening ```
513
+ while (i < lines.length && !lines[i].trim().startsWith('```')) {
514
+ codeLines.push(lines[i]);
515
+ i++;
516
+ }
517
+ blocks.push({
518
+ object: 'block',
519
+ type: 'code',
520
+ code: {
521
+ rich_text: [(0, NotionUtils_1.createRichText)(codeLines.join('\n'))],
522
+ language: 'plain text',
523
+ },
524
+ });
525
+ }
526
+ else {
527
+ // Regular paragraph
528
+ blocks.push({
529
+ object: 'block',
530
+ type: 'paragraph',
531
+ paragraph: {
532
+ rich_text: [(0, NotionUtils_1.createRichText)(line)],
533
+ },
534
+ });
535
+ }
536
+ }
537
+ return blocks;
538
+ }
539
+ static parsePropertiesToUpdate(propertiesString) {
540
+ try {
541
+ // Try to parse as JSON first
542
+ return JSON.parse(propertiesString);
543
+ }
544
+ catch {
545
+ // If not JSON, try to parse natural language
546
+ const properties = {};
547
+ // Simple natural language parsing
548
+ const patterns = [
549
+ /set\s+(\w+)\s+to\s+(.+?)(?:\s+and|$)/gi,
550
+ /(\w+)\s*:\s*(.+?)(?:\s*,|$)/gi,
551
+ /(\w+)\s*=\s*(.+?)(?:\s*,|$)/gi,
552
+ ];
553
+ for (const pattern of patterns) {
554
+ let match;
555
+ while ((match = pattern.exec(propertiesString)) !== null) {
556
+ const [, key, value] = match;
557
+ properties[key.trim()] = {
558
+ rich_text: [(0, NotionUtils_1.createRichText)(value.trim())],
559
+ };
560
+ }
561
+ }
562
+ return properties;
563
+ }
564
+ }
565
+ }
566
+ exports.NotionAITool = NotionAITool;