-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgoogleMeetToAppleCal.gs
51 lines (49 loc) · 1.64 KB
/
googleMeetToAppleCal.gs
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
/*
* This script adds Google Meet to events created via Apple Calendar (and other 3rd party calendar clients)
* It fetches events recently updated filtering via updatedMin.
* Adds Google Meet link if an event has been created by you, has no conferenceData and has at least one guest
* Creates a trigger on event update
*/
function checkForNewEvents() {
const calendarId = 'primary';
const now = new Date();
const minutesFromLastUpdate = 5;
const updatedMin = new Date(now.getTime() - minutesFromLastUpdate * 60000);
const events = Calendar.Events.list(calendarId, {
timeMin: now.toISOString(),
updatedMin: updatedMin.toISOString(),
singleEvents: true,
orderBy: 'startTime',
maxResults: 5,
});
if (events.items && events.items.length > 0) {
for (let i = 0; i < events.items.length; i++) {
let event = events.items[i];
if (event.status !== 'cancelled' && !event.start.date) {
const start = new Date(event.start.dateTime);
if (
event.creator.self &&
event.conferenceData == null &&
event.attendees
) {
event.conferenceData = {
createRequest: {
requestId: Utilities.getUuid(),
conferenceSolutionKey: { type: 'hangoutsMeet' },
},
};
try {
event = Calendar.Events.update(event, calendarId, event.id, {
conferenceDataVersion: 1,
sendUpdates: 'externalOnly', // notify non Google user
});
} catch (e) {
Logger.log('Fetch threw an exception: ' + e);
}
}
}
}
} else {
// do nothing
}
}