-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.json
547 lines (547 loc) · 40.1 KB
/
plugin.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
{
"uuid": "7705fa3f-897d-4605-bd73-605d2a46b15a",
"id": "perform_notion_database_query",
"emoji": "🧩",
"title": "Notion Database Query",
"overviewMarkdown": "# **Notion Database Query**\nThis plugin allows users to query pages from a Notion database.\n\n### 🎯 **It Supports**\n- Filtering data by different property types based on the provided database information.\n- Sorting results in ascending or descending order.\n- Pagination with a specified page size.\n\n### 📝 **User Setting Notes:**\n#### 🔧 **Set Up the Plugin Server:**\n- A plugin server must be set up to use this feature. Follow the detailed guide to set up a plugin server on Render: [How to Deploy the Plugin Server on Render](https://docs.typingmind.com/plugins/plugins-server/how-to-deploy-plugins-server-on-render)\n\n#### 🔑 **Set Up Your Notion API Key:**\n- Go to the [Notion Integration Page](https://www.notion.so/profile/integrations) and create a new integration.\n- Copy the key from the Integration Detail Page.\n- Paste the key into the plugin's user settings:\n **Notion API Key:** `ntn_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX`\n\nFor detailed instructions, visit the [Notion Integration API Documentation](https://developers.notion.com/docs/create-a-notion-integration)\n\n#### 🔗 **Share Your Database with the Integration:**\n- Open your database in Notion.\n- Click the **“Share”** button in the top right.\n- Select **“Invite”**, search for your integration name, and click **“Invite”** to grant access.\n\nFor detailed instructions, visit the [Notion API Connections Documentation](https://www.notion.com/help/add-and-manage-connections-with-the-api)\n\n### 📌 **Important Notes:**\n\n#### 👉 **Database Context Requirement:**\nTo use the plugin, you need to tell the AI your database ID along with the database structure at the beginning.\n\n##### 1. Obtain Your Database ID\n- To get the database ID, open your Notion database as a full page in your browser.\n- Copy the full URL from the address bar. The URL will look something like this: `https://www.notion.so/<DATABASE_ID>?v=<VIEW_ID>`\n- Example URL `https://www.notion.so/12345bcxyz?v=11111aaaaaa`. The **Database ID** is: `12345bcxyz`.\n\n##### 2. Obtain Your Database Structure\n- Manually list out each property, including Name, Type, and Options (Select, Multi-select, Status).\n- Use the [Notion Database Structure Viewer plugin](https://github.com/TypingMind/plugin-notion-database-structure-viewer).\n\n#### ⚠️ **Limitations:**\n- The plugin does **not support** the following property types for querying: Relation, Rollup, Verification, Formula, Unique ID.\n\n#### 👉 **Rate Limits:**\n- There are rate limits for Notion API requests. Learn more at [Notion API Rate Limits](https://developers.notion.com/reference/request-limits#rate-limits).\n- There are size limits on certain parameters, as well as the depth of children in requests. Learn more at [Notion API Size Limits](https://developers.notion.com/reference/request-limits#size-limits)\n\n### 💡 **Example Usage** \n- As an HR professional, I want to filter employees based on specific conditions. First, I need to provide the AI with the context of my database, including the database URL along with the database structure description.\n\nGiven the description of my Employee Directory Database as follows: \n> Notion Database URL: `https://www.notion.so/12345bcxyz?v=11111aaaaaa`\n>\n> Database Structure:\n> 1. Name (Title)\n> 2. Years of Experience (Number)\n> 3. Skills (Multi-select) - Options: Project Management, Programming, Data Analysis, Communication, Leadership, Design, Marketing, Sales, MLOps, FullStack\n> 4. Probation Passed (Checkbox)\n> 5. Location (Select) - Options: HQ - New York, Office - London, Office - Singapore, Remote - Domestic, Remote - International, Hybrid, Office - New York\n> 6. Role (Select) - Options: Engineer, Manager, Designer, Analyst, Developer, Director, Coordinator, Specialist\n> 7. LinkedIn Profile (URL)\n> 8. Performance Review Status (Status) - Options: Not started, In progress, Done\n> 9. Email (Email)\n> 10. Start Date (Date)\n> 11. Department (Select) - Options: Engineering, Marketing, Sales, HR, Finance, Operations, Customer Support, Design\n> 12. Attachments (Files)\n> 13. Phone (Phone Number)\n> 14. Notes (Rich Text)\n\nThen, I can ask the AI to retrieve employees based on my needs. Here are some examples:\n\nExample 1:\n> Filter employees who have not passed probation.\n\nExample 2:\n> Filter employees in the Engineering Department, sort them by Name (A-Z), and retrieve the first 5 individuals.\n\nExample 3:\n> Filter employees in the Engineering Department with roles of Engineer or Analyst, hired after 2025-01-01, and sort them by Name (A-Z).",
"openaiSpec": {
"name": "perform_notion_database_query",
"description": "Perform a Notion database query using the Notion API, including filters, sorting, and pagination. Provide the Notion Database ID and Database Structure to use this function.",
"parameters": {
"type": "object",
"properties": {
"databaseId": {
"type": "string",
"description": "The ID of the Notion database for create and read operations."
},
"databaseStructure": {
"type": "array",
"description": "A list of properties in the Notion database structure, used to generate filter or sort criteria.",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The name of the property."
},
"type": {
"type": "string",
"description": "The type of the property.",
"enum": [
"title",
"number",
"multi_select",
"select",
"checkbox",
"url",
"status",
"email",
"date",
"files",
"phone_number",
"rich_text"
]
},
"options": {
"type": "array",
"description": "List of options for select, multi-select, and status properties.",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Name of the option."
}
}
}
}
}
}
},
"filter": {
"type": "object",
"description": "Filters to refine the database query, supporting nested conditions and operations specific to property types.",
"properties": {
"and": {
"type": "array",
"description": "List of conditions where all must be true.",
"items": {
"type": "object",
"properties": {
"property": {
"type": "string",
"description": "The name or ID of the property to filter."
},
"type": {
"type": "string",
"enum": [
"checkbox",
"number",
"title",
"text",
"select",
"multi_select",
"date",
"relation",
"formula",
"rollup",
"status"
],
"description": "The type of the property being filtered."
},
"checkbox": {
"type": "object",
"description": "Filter operations for checkbox properties.",
"properties": {
"equals": {
"type": "boolean",
"description": "Checks if the checkbox is checked or not."
}
}
},
"number": {
"type": "object",
"description": "Filter operations for number properties.",
"properties": {
"equals": {
"type": "number",
"description": "Checks if the number equals the given value."
},
"greater_than": {
"type": "number",
"description": "Checks if the number is greater than the given value."
},
"less_than": {
"type": "number",
"description": "Checks if the number is less than the given value."
},
"greater_than_or_equal_to": {
"type": "number",
"description": "Checks if the number is greater than or equal to the given value."
},
"less_than_or_equal_to": {
"type": "number",
"description": "Checks if the number is less than or equal to the given value."
}
}
},
"text": {
"type": "object",
"description": "Filter operations for text properties.",
"properties": {
"contains": {
"type": "string",
"description": "Checks if the text contains the given substring."
},
"does_not_contain": {
"type": "string",
"description": "Checks if the text does not contain the given substring."
},
"equals": {
"type": "string",
"description": "Checks if the text equals the given value."
},
"starts_with": {
"type": "string",
"description": "Checks if the text starts with the given value."
},
"ends_with": {
"type": "string",
"description": "Checks if the text ends with the given value."
}
}
},
"rich_text": {
"type": "object",
"description": "Filter operations for rich_text properties.",
"properties": {
"contains": {
"type": "string",
"description": "Checks if the text contains the given substring."
},
"does_not_contain": {
"type": "string",
"description": "Checks if the text does not contain the given substring."
},
"equals": {
"type": "string",
"description": "Checks if the text equals the given value."
},
"starts_with": {
"type": "string",
"description": "Checks if the text starts with the given value."
},
"ends_with": {
"type": "string",
"description": "Checks if the text ends with the given value."
}
}
},
"title": {
"type": "object",
"description": "Filter operations for title properties.",
"properties": {
"contains": {
"type": "string",
"description": "Checks if the title contains the given substring."
},
"does_not_contain": {
"type": "string",
"description": "Checks if the title does not contain the given substring."
},
"equals": {
"type": "string",
"description": "Checks if the title equals the given value."
},
"starts_with": {
"type": "string",
"description": "Checks if the title starts with the given value."
},
"ends_with": {
"type": "string",
"description": "Checks if the title ends with the given value."
}
}
},
"select": {
"type": "object",
"description": "Filter operations for select properties.",
"properties": {
"equals": {
"type": "string",
"description": "Checks if the selected option equals the given value."
},
"does_not_equal": {
"type": "string",
"description": "Checks if the selected option does not equal the given value."
}
}
},
"multi_select": {
"type": "object",
"description": "Filter operations for multi-select properties.",
"properties": {
"contains": {
"type": "string",
"description": "Checks if the multi-select property contains the given value."
},
"does_not_contain": {
"type": "string",
"description": "Checks if the multi-select property does not contain the given value."
}
}
},
"date": {
"type": "object",
"description": "Filter operations for date properties.",
"properties": {
"equals": {
"type": "string",
"description": "Checks if the date equals the given value (ISO 8601 format)."
},
"before": {
"type": "string",
"description": "Checks if the date is before the given value (ISO 8601 format)."
},
"after": {
"type": "string",
"description": "Checks if the date is after the given value (ISO 8601 format)."
},
"on_or_before": {
"type": "string",
"description": "Checks if the date is on or before the given value (ISO 8601 format)."
},
"on_or_after": {
"type": "string",
"description": "Checks if the date is on or after the given value (ISO 8601 format)."
}
}
}
}
}
},
"or": {
"type": "array",
"description": "List of conditions where all must be true.",
"items": {
"type": "object",
"properties": {
"property": {
"type": "string",
"description": "The name or ID of the property to filter."
},
"type": {
"type": "string",
"enum": [
"checkbox",
"number",
"text",
"select",
"multi_select",
"date",
"status",
"files"
],
"description": "The type of the property being filtered."
},
"checkbox": {
"type": "object",
"description": "Filter operations for checkbox properties.",
"properties": {
"equals": {
"type": "boolean",
"description": "Checks if the checkbox is checked or not."
}
}
},
"number": {
"type": "object",
"description": "Filter operations for number properties.",
"properties": {
"equals": {
"type": "number",
"description": "Checks if the number equals the given value."
},
"greater_than": {
"type": "number",
"description": "Checks if the number is greater than the given value."
},
"less_than": {
"type": "number",
"description": "Checks if the number is less than the given value."
},
"greater_than_or_equal_to": {
"type": "number",
"description": "Checks if the number is greater than or equal to the given value."
},
"less_than_or_equal_to": {
"type": "number",
"description": "Checks if the number is less than or equal to the given value."
}
}
},
"text": {
"type": "object",
"description": "Filter operations for text properties.",
"properties": {
"contains": {
"type": "string",
"description": "Checks if the text contains the given substring."
},
"does_not_contain": {
"type": "string",
"description": "Checks if the text does not contain the given substring."
},
"equals": {
"type": "string",
"description": "Checks if the text equals the given value."
},
"starts_with": {
"type": "string",
"description": "Checks if the text starts with the given value."
},
"ends_with": {
"type": "string",
"description": "Checks if the text ends with the given value."
}
}
},
"rich_text": {
"type": "object",
"description": "Filter operations for rich_text properties.",
"properties": {
"contains": {
"type": "string",
"description": "Checks if the text contains the given substring."
},
"does_not_contain": {
"type": "string",
"description": "Checks if the text does not contain the given substring."
},
"equals": {
"type": "string",
"description": "Checks if the text equals the given value."
},
"starts_with": {
"type": "string",
"description": "Checks if the text starts with the given value."
},
"ends_with": {
"type": "string",
"description": "Checks if the text ends with the given value."
}
}
},
"title": {
"type": "object",
"description": "Filter operations for title properties.",
"properties": {
"contains": {
"type": "string",
"description": "Checks if the title contains the given substring."
},
"does_not_contain": {
"type": "string",
"description": "Checks if the title does not contain the given substring."
},
"equals": {
"type": "string",
"description": "Checks if the title equals the given value."
},
"starts_with": {
"type": "string",
"description": "Checks if the title starts with the given value."
},
"ends_with": {
"type": "string",
"description": "Checks if the title ends with the given value."
}
}
},
"select": {
"type": "object",
"description": "Filter operations for select properties.",
"properties": {
"equals": {
"type": "string",
"description": "Checks if the selected option equals the given value."
},
"does_not_equal": {
"type": "string",
"description": "Checks if the selected option does not equal the given value."
}
}
},
"multi_select": {
"type": "object",
"description": "Filter operations for multi-select properties.",
"properties": {
"contains": {
"type": "string",
"description": "Checks if the multi-select property contains the given value."
},
"does_not_contain": {
"type": "string",
"description": "Checks if the multi-select property does not contain the given value."
}
}
},
"date": {
"type": "object",
"description": "Filter operations for date properties.",
"properties": {
"equals": {
"type": "string",
"description": "Checks if the date equals the given value (ISO 8601 format)."
},
"before": {
"type": "string",
"description": "Checks if the date is before the given value (ISO 8601 format)."
},
"after": {
"type": "string",
"description": "Checks if the date is after the given value (ISO 8601 format)."
},
"on_or_before": {
"type": "string",
"description": "Checks if the date is on or before the given value (ISO 8601 format)."
},
"on_or_after": {
"type": "string",
"description": "Checks if the date is on or after the given value (ISO 8601 format)."
}
}
},
"status": {
"type": "object",
"description": "Filter operations for status properties.",
"properties": {
"equals": {
"type": "string",
"description": "Checks if the status equals the given value."
}
}
},
"files": {
"type": "object",
"description": "Filter operations for files properties.",
"properties": {
"contains": {
"type": "string",
"description": "Checks if the file property contains the given value."
}
}
}
}
}
}
}
},
"sorts": {
"type": "array",
"description": "Defines the sorting order of query results.",
"items": {
"type": "object",
"properties": {
"property": {
"type": "string",
"description": "The name or ID of the property to sort by."
},
"direction": {
"type": "string",
"enum": [
"ascending",
"descending"
],
"description": "The direction to sort the results ('ascending' or 'descending')."
}
}
}
},
"pageSize": {
"type": "integer",
"description": "The number of results per page for the read operation. Default value is 100."
},
"startCursor": {
"type": "string",
"description": "The start cursor for pagination in the read operation."
}
},
"required": [
"databaseId",
"databaseStructure"
]
}
},
"userSettings": [
{
"name": "pluginServer",
"label": "Plugin Server",
"required": true,
"description": "The URL of the plugin server. For more details, refer to the documentation: https://docs.typingmind.com/plugins/plugins-server",
"placeholder": "https://...."
},
{
"name": "notionApiKey",
"label": "Notion API Key",
"description": "Enter your Notion Secret Key. You can create an integration from Notion at https://www.notion.so/profile/integrations",
"required": true
}
],
"code": "/**\n * Perform a query operation on a Notion database.\n * @param {Object} params - The parameters for the operation.\n * @param {string} [params.databaseId] - The ID of the Notion database for create and read operations.\n * @param {Array} [params.databaseStructure] - A list of properties in the Notion database structure, used to generate filter or sort criteria..\n * @param {Object} [params.filter] - Optional filter for querying pages in the read operation.\n * @param {Array} [params.sorts] - Optional sorting criteria for page results in the read operation.\n * @param {number} [params.pageSize] - The number of results per page for the read operation.\n * @param {string} [params.startCursor] - The start cursor for pagination in the read operation.\n * @returns {Promise<Object>} - The response data from the Notion API.\n */\nasync function perform_notion_database_query(params, userSettings) {\n const { databaseId, databaseStructure = [] } = params;\n const { pluginServer, notionApiKey } = userSettings;\n\n if (!pluginServer) {\n throw new Error(\n \"Missing the Plugin Server URL. Please set it in the plugin settings.\"\n );\n }\n\n if (!notionApiKey) {\n throw new Error(\n \"Missing the Notion API Key. Please set it in the plugin settings.\"\n );\n }\n\n if (!databaseId) {\n throw new Error(\n \"Missing the Database Id. Please provide specific Database ID or Database URL\"\n );\n }\n\n if (!databaseStructure.length) {\n throw new Error(\n \"Missing the Database Structure Properties. Please provide valid structure of your provided database.\"\n );\n }\n\n try {\n const result = await queryPages({\n pluginServerUrl: pluginServer,\n notionApiKey: notionApiKey,\n databaseId: databaseId,\n databaseStructure: databaseStructure,\n filter: params.filter ?? {},\n sorts: params.sorts ?? [],\n pageSize: params.pageSize ?? 100,\n startCursor: params.startCursor,\n });\n return result;\n } catch (error) {\n return { error: error.message };\n }\n}\n\nasync function queryPages({\n notionApiKey,\n pluginServerUrl,\n databaseId,\n databaseStructure,\n filter,\n sorts,\n pageSize = 100,\n startCursor = null,\n}) {\n const requestBody = {\n notionApiKey: notionApiKey,\n databaseId: databaseId,\n pageSize: pageSize,\n databaseStructure: databaseStructure,\n };\n if (filter) requestBody.filter = filter;\n if (sorts) requestBody.sorts = sorts;\n if (startCursor) requestBody.startCursor = startCursor;\n\n try {\n const response = await fetch(\n `${pluginServerUrl}/notion-database/query-pages`,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(requestBody),\n }\n );\n\n if (!response.ok) {\n throw new Error(`Error query pages: ${response.statusText}`);\n }\n\n const data = await response.json();\n console.log(JSON.stringify(data));\n return data;\n } catch (error) {\n throw new Error(`Failed to query pages: ${error.message}`);\n }\n}",
"iconURL": "https://registry.npmmirror.com/@lobehub/icons-static-png/latest/files/light/notion.png",
"authenticationType": "AUTH_TYPE_NONE",
"implementationType": "javascript",
"httpAction": {
"id": "0ef6f5e9-92c2-4c97-84b3-1f20944a0b7f",
"name": "",
"url": "{pluginServer}/notion-database/query-pages",
"method": "POST",
"hasHeaders": true,
"requestHeaders": "{\n \"Content-Type\": \"application/json\"\n}",
"hasBody": true,
"requestBody": "{\n \"notionApiKey\": \"{notionApiKey}\",\n \"databaseId\": \"{databaseId}\",\n \"pageSize\": {pageSize},\n \"startCursor\": \"{startCursor}\",\n \"filter\": {filter},\n \"sorts\": {sorts}\n}"
},
"oauthConfig": null,
"outputType": "respond_to_ai"
}