forked from anandrajaram21/alfred-notion-gtd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotion.js
47 lines (42 loc) · 963 Bytes
/
notion.js
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
import * as chrono from "chrono-node";
import { Client } from "@notionhq/client";
import dotenv from "dotenv";
dotenv.config();
const client = new Client({
auth: process.env.NOTION_TOKEN,
});
const { DATABASE_ID, TASK_NAME, DATE_NAME } = process.env;
async function createTask(
notionClient,
taskName,
databaseId,
tableTaskName,
tableDateName
) {
const taskDate = chrono.parseDate(taskName);
const response = await notionClient.pages.create({
parent: {
database_id: databaseId,
},
properties: {
[tableTaskName]: {
title: [
{
text: {
content: taskName,
},
},
],
},
...(taskDate && {
[tableDateName]: {
date: {
start: chrono.parseDate(taskName).toISOString(),
},
},
}),
},
});
return "Done";
}
await createTask(client, process.argv[2], DATABASE_ID, TASK_NAME, DATE_NAME);