-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate-event.ts
87 lines (78 loc) · 2.32 KB
/
create-event.ts
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
// import cw, { morgen } from "morgen-cw-sdk";
import cw, { sandbox } from "../src";
const { morgen } = sandbox.util;
const { luxon } = sandbox.deps;
/**
* This is a basic example of a workflow that creates a new event in the
* provided calendar.
*
* NOTE: Please specify the calendar in the UI once the workflow has been
* uploaded.
*/
const wf = cw.workflow(
{
name: "SDK Example: Create an Event",
},
async function run(trigger) {
if (!trigger.accounts?.calendar?.[0]?.calendarId)
throw new Error("No calendar configured!");
const { accountId, calendarId } = trigger.accounts.calendar[0];
// Get exported classes of the luxon library
const { DateTime, Duration } = luxon;
// Create the start time using the luxon library
const startDT = DateTime.now().startOf("minute");
const start = startDT.toISO({
// Milliseconds aren't supported by the Morgen API
suppressMilliseconds: true,
// Exclude the time zone, which is provided separately
includeOffset: false,
})!;
const timeZone = startDT.zoneName || "UTC";
// Create the duration
const duration = Duration.fromObject({ minutes: 30 }).toISO()!;
// Set this property to:
// - true to show it as an all-day event
// - false to show it at a specific time of day.
const showWithoutTime = false;
// Perform the request using our client
const resp = await morgen().events.createEventV3({
requestBody: {
calendarId,
accountId,
title: "Get started with TimeTo! 🥳",
description:
"Congratulations, you just added an event to your calendar through the power of Morgen! 👏",
timeZone,
showWithoutTime,
start,
duration,
},
});
return resp;
}
);
// Upload the workflow, and trigger it when upload is complete
wf.upload().then(() => wf.trigger());
/*
wf.run({
httpParams: {},
eventUpdates: {
added: [],
modified: [],
removed: [],
},
user: {
email: "",
firstName: "",
},
accounts: {
calendar: [
{
accountId: "6441683859cf95c5a82dd83a",
calendarId:
"WyI2NDQxNjgzODU5Y2Y5NWM1YTgyZGQ4M2EiLCJkODQzNjAzOTljZDdlMTkyNmJjOWEyZTljYjliNWUzYzViMmViMDI5ZTMzZWI1M2FlNTQ3ODg1MDg5YTNhM2ZjQGdyb3VwLmNhbGVuZGFyLmdvb2dsZS5jb20iXQ",
},
],
},
});
*/