Merge pull request #1177 from automatisch/notion-create-database-item
feat(notion): add create database item action
This commit is contained in:
@@ -0,0 +1,100 @@
|
|||||||
|
import { IJSONArray, IJSONObject } from '@automatisch/types';
|
||||||
|
import defineAction from '../../../../helpers/define-action';
|
||||||
|
|
||||||
|
type TBody = {
|
||||||
|
parent: IJSONObject;
|
||||||
|
properties: IJSONObject;
|
||||||
|
children: IJSONArray;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default defineAction({
|
||||||
|
name: 'Create Database Item',
|
||||||
|
key: 'createDatabaseItem',
|
||||||
|
description: 'Creates an item in a database.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Database',
|
||||||
|
key: 'databaseId',
|
||||||
|
type: 'dropdown' as const,
|
||||||
|
required: true,
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listDatabases',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Name',
|
||||||
|
key: 'name',
|
||||||
|
type: 'string' as const,
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
'This field has a 2000 character limit. Any characters beyond 2000 will not be included.',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Content',
|
||||||
|
key: 'content',
|
||||||
|
type: 'string' as const,
|
||||||
|
required: false,
|
||||||
|
description:
|
||||||
|
'The text to add to the page body. The max length for this field is 2000 characters. Any characters beyond 2000 will not be included.',
|
||||||
|
variables: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const name = $.step.parameters.name as string;
|
||||||
|
const truncatedName = name.slice(0, 2000);
|
||||||
|
const content = $.step.parameters.content as string;
|
||||||
|
const truncatedContent = content.slice(0, 2000);
|
||||||
|
|
||||||
|
const body: TBody = {
|
||||||
|
parent: {
|
||||||
|
database_id: $.step.parameters.databaseId,
|
||||||
|
},
|
||||||
|
properties: {},
|
||||||
|
children: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
if (name) {
|
||||||
|
body.properties.Name = {
|
||||||
|
title: [
|
||||||
|
{
|
||||||
|
text: {
|
||||||
|
content: truncatedName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (content) {
|
||||||
|
body.children = [
|
||||||
|
{
|
||||||
|
object: 'block',
|
||||||
|
paragraph: {
|
||||||
|
rich_text: [
|
||||||
|
{
|
||||||
|
text: {
|
||||||
|
content: truncatedContent,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data } = await $.http.post('/v1/pages', body);
|
||||||
|
|
||||||
|
$.setActionItem({
|
||||||
|
raw: data,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
3
packages/backend/src/apps/notion/actions/index.ts
Normal file
3
packages/backend/src/apps/notion/actions/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import createDatabaseItem from './create-database-item';
|
||||||
|
|
||||||
|
export default [createDatabaseItem];
|
@@ -3,6 +3,7 @@ import addAuthHeader from './common/add-auth-header';
|
|||||||
import addNotionVersionHeader from './common/add-notion-version-header';
|
import addNotionVersionHeader from './common/add-notion-version-header';
|
||||||
import auth from './auth';
|
import auth from './auth';
|
||||||
import triggers from './triggers';
|
import triggers from './triggers';
|
||||||
|
import actions from './actions';
|
||||||
import dynamicData from './dynamic-data';
|
import dynamicData from './dynamic-data';
|
||||||
|
|
||||||
export default defineApp({
|
export default defineApp({
|
||||||
@@ -14,11 +15,9 @@ export default defineApp({
|
|||||||
authDocUrl: 'https://automatisch.io/docs/apps/notion/connection',
|
authDocUrl: 'https://automatisch.io/docs/apps/notion/connection',
|
||||||
primaryColor: '000000',
|
primaryColor: '000000',
|
||||||
supportsConnections: true,
|
supportsConnections: true,
|
||||||
beforeRequest: [
|
beforeRequest: [addAuthHeader, addNotionVersionHeader],
|
||||||
addAuthHeader,
|
|
||||||
addNotionVersionHeader,
|
|
||||||
],
|
|
||||||
auth,
|
auth,
|
||||||
triggers,
|
triggers,
|
||||||
|
actions,
|
||||||
dynamicData,
|
dynamicData,
|
||||||
});
|
});
|
||||||
|
@@ -157,6 +157,7 @@ export default defineConfig({
|
|||||||
collapsed: true,
|
collapsed: true,
|
||||||
items: [
|
items: [
|
||||||
{ text: 'Triggers', link: '/apps/notion/triggers' },
|
{ text: 'Triggers', link: '/apps/notion/triggers' },
|
||||||
|
{ text: 'Actions', link: '/apps/notion/actions' },
|
||||||
{ text: 'Connection', link: '/apps/notion/connection' },
|
{ text: 'Connection', link: '/apps/notion/connection' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
12
packages/docs/pages/apps/notion/actions.md
Normal file
12
packages/docs/pages/apps/notion/actions.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
favicon: /favicons/notion.svg
|
||||||
|
items:
|
||||||
|
- name: Create database item
|
||||||
|
desc: Creates an item in a database.
|
||||||
|
---
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import CustomListing from '../../components/CustomListing.vue'
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<CustomListing />
|
Reference in New Issue
Block a user