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