1 | |
2 |
|
3 | type Gcal = { |
4 | token: string; |
5 | }; |
6 | export async function main( |
7 | gcal_auth: Gcal, |
8 | calendarId: string, |
9 | start_date?: string, |
10 | end_date?: string, |
11 | description?: string, |
12 | summary: string, |
13 | location?: string, |
14 | attendees?: Array<object>, |
15 | maxAttendees?: number = 2, |
16 | ) { |
17 | const sendNotifications = true; |
18 | const sendUpdates = "all"; |
19 | const supportsAttachments = true; |
20 |
|
21 | const CREATE_EVENT_URL = `https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events/?maxAttendees=${maxAttendees}&sendNotifications=${sendNotifications}&sendUpdates=${sendUpdates}&supportsAttachments${supportsAttachments}`; |
22 |
|
23 | const token = gcal_auth["token"]; |
24 |
|
25 | const body = { |
26 | summary: summary, |
27 | description: description, |
28 | location: location, |
29 | end: { |
30 | date: end_date, |
31 | }, |
32 | start: { |
33 | date: start_date, |
34 | }, |
35 | attendees: attendees, |
36 | }; |
37 |
|
38 | const response = await fetch(CREATE_EVENT_URL, { |
39 | method: "POST", |
40 | body: JSON.stringify(body), |
41 | headers: { |
42 | Authorization: "Bearer " + token, |
43 | "Content-Type": "application/json", |
44 | }, |
45 | }); |
46 |
|
47 | const result = await response.json(); |
48 |
|
49 | return result; |
50 | } |
51 |
|