@pipedream/google_calendar 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actions/create-event/create-event.mjs +1 -1
- package/actions/delete-event/delete-event.mjs +1 -1
- package/actions/get-calendar/get-calendar.mjs +1 -1
- package/actions/get-event/get-event.mjs +1 -1
- package/actions/list-calendars/list-calendars.mjs +1 -1
- package/actions/list-events/list-events.mjs +9 -22
- package/actions/list-events-by-type/list-events-by-type.mjs +56 -0
- package/actions/query-free-busy-calendars/query-free-busy-calendars.mjs +1 -1
- package/actions/quick-add-event/quick-add-event.mjs +1 -1
- package/actions/update-event/update-event.mjs +1 -1
- package/actions/update-event-attendees/update-event-attendees.mjs +1 -1
- package/common/utils.mjs +21 -0
- package/google_calendar.app.mjs +12 -0
- package/package.json +1 -1
- package/sources/event-cancelled/event-cancelled.mjs +1 -1
- package/sources/event-ended/event-ended.mjs +1 -1
- package/sources/event-start/event-start.mjs +1 -1
- package/sources/new-calendar/new-calendar.mjs +1 -1
- package/sources/new-event/new-event.mjs +1 -1
- package/sources/new-event-search/new-event-search.mjs +1 -1
- package/sources/new-or-updated-event/new-or-updated-event.mjs +1 -1
- package/sources/new-or-updated-event-instant/new-or-updated-event-instant.mjs +1 -1
- package/sources/upcoming-event-alert/upcoming-event-alert.mjs +86 -34
- package/sources/upcoming-event-type-alert/upcoming-event-type-alert.mjs +149 -0
|
@@ -6,7 +6,7 @@ export default {
|
|
|
6
6
|
key: "google_calendar-create-event",
|
|
7
7
|
name: "Create Event",
|
|
8
8
|
description: "Create an event to the Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Events.html#insert)",
|
|
9
|
-
version: "0.2.
|
|
9
|
+
version: "0.2.1",
|
|
10
10
|
type: "action",
|
|
11
11
|
props: {
|
|
12
12
|
googleCalendar,
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "google_calendar-delete-event",
|
|
5
5
|
name: "Delete an Event",
|
|
6
6
|
description: "Delete an event to the Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Events.html#delete)",
|
|
7
|
-
version: "0.1.
|
|
7
|
+
version: "0.1.4",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
googleCalendar,
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "google_calendar-get-calendar",
|
|
5
5
|
name: "Retrieve Calendar Details",
|
|
6
6
|
description: "Retrieve calendar details of a Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Calendars.html#get)",
|
|
7
|
-
version: "0.1.
|
|
7
|
+
version: "0.1.5",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
googleCalendar,
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "google_calendar-get-event",
|
|
5
5
|
name: "Retrieve Event Details",
|
|
6
6
|
description: "Retrieve event details from Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Events.html#get)",
|
|
7
|
-
version: "0.1.
|
|
7
|
+
version: "0.1.5",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
googleCalendar,
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "google_calendar-list-calendars",
|
|
5
5
|
name: "List Calendars",
|
|
6
6
|
description: "Retrieve a list of calendars from Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Calendarlist.html#list)",
|
|
7
|
-
version: "0.1.
|
|
7
|
+
version: "0.1.5",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
googleCalendar,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import googleCalendar from "../../google_calendar.app.mjs";
|
|
2
|
+
import utils from "../../common/utils.mjs";
|
|
2
3
|
|
|
3
4
|
export default {
|
|
4
5
|
key: "google_calendar-list-events",
|
|
5
6
|
name: "List Events",
|
|
6
7
|
description: "Retrieve a list of event from the Google Calendar. [See the documentation](https://developers.google.com/calendar/api/v3/reference/events/list)",
|
|
7
|
-
version: "0.0.
|
|
8
|
+
version: "0.0.5",
|
|
8
9
|
type: "action",
|
|
9
10
|
props: {
|
|
10
11
|
googleCalendar,
|
|
@@ -111,30 +112,15 @@ export default {
|
|
|
111
112
|
"updatedMin",
|
|
112
113
|
],
|
|
113
114
|
},
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
return Object.entries(obj)
|
|
121
|
-
.reduce((reduction,
|
|
122
|
-
[
|
|
123
|
-
key,
|
|
124
|
-
value,
|
|
125
|
-
]) => {
|
|
126
|
-
if (value === undefined || value === null) {
|
|
127
|
-
return reduction;
|
|
128
|
-
}
|
|
129
|
-
return {
|
|
130
|
-
...reduction,
|
|
131
|
-
[key]: value,
|
|
132
|
-
};
|
|
133
|
-
}, {});
|
|
115
|
+
eventTypes: {
|
|
116
|
+
propDefinition: [
|
|
117
|
+
googleCalendar,
|
|
118
|
+
"eventTypes",
|
|
119
|
+
],
|
|
134
120
|
},
|
|
135
121
|
},
|
|
136
122
|
async run({ $ }) {
|
|
137
|
-
const args =
|
|
123
|
+
const args = utils.filterEmptyValues({
|
|
138
124
|
calendarId: this.calendarId,
|
|
139
125
|
iCalUID: this.iCalUID,
|
|
140
126
|
maxAttendees: this.maxAttendees,
|
|
@@ -152,6 +138,7 @@ export default {
|
|
|
152
138
|
timeMin: this.timeMin,
|
|
153
139
|
timeZone: this.timeZone,
|
|
154
140
|
updatedMin: this.updatedMin,
|
|
141
|
+
eventTypes: this.eventTypes,
|
|
155
142
|
});
|
|
156
143
|
const response = await this.googleCalendar.listEvents(args);
|
|
157
144
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import googleCalendar from "../../google_calendar.app.mjs";
|
|
2
|
+
import utils from "../../common/utils.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: "google_calendar-list-events-by-type",
|
|
6
|
+
name: "List Calendar Events by Type",
|
|
7
|
+
description: "Retrieve a list of events filtered by type (\"default\", \"focusTime\", \"outOfOffice\", \"workingLocation\") from the Google Calendar. [See the documentation](https://developers.google.com/calendar/api/v3/reference/events/list)",
|
|
8
|
+
version: "0.0.1",
|
|
9
|
+
type: "action",
|
|
10
|
+
props: {
|
|
11
|
+
googleCalendar,
|
|
12
|
+
calendarId: {
|
|
13
|
+
propDefinition: [
|
|
14
|
+
googleCalendar,
|
|
15
|
+
"calendarId",
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
eventTypes: {
|
|
19
|
+
propDefinition: [
|
|
20
|
+
googleCalendar,
|
|
21
|
+
"eventTypes",
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
maxResults: {
|
|
25
|
+
propDefinition: [
|
|
26
|
+
googleCalendar,
|
|
27
|
+
"maxResults",
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
async run({ $ }) {
|
|
32
|
+
const args = utils.filterEmptyValues({
|
|
33
|
+
calendarId: this.calendarId,
|
|
34
|
+
eventTypes: this.eventTypes,
|
|
35
|
+
});
|
|
36
|
+
const events = [];
|
|
37
|
+
let total, done = false, count = 0;
|
|
38
|
+
do {
|
|
39
|
+
const response = await this.googleCalendar.listEvents(args);
|
|
40
|
+
for (const item of response.items) {
|
|
41
|
+
events.push(item);
|
|
42
|
+
count++;
|
|
43
|
+
if (this.maxResults && count >= this.maxResults) {
|
|
44
|
+
done = true;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
total = response.items?.length;
|
|
49
|
+
args.syncToken = response.nextSyncToken;
|
|
50
|
+
} while (total && !done);
|
|
51
|
+
|
|
52
|
+
$.export("$summary", `Successfully retrieved ${events.length} event(s)`);
|
|
53
|
+
|
|
54
|
+
return events;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "google_calendar-query-free-busy-calendars",
|
|
5
5
|
name: "Retrieve Free/Busy Calendar Details",
|
|
6
6
|
description: "Retrieve free/busy calendar details from Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Freebusy.html#query)",
|
|
7
|
-
version: "0.1.
|
|
7
|
+
version: "0.1.5",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
googleCalendar,
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "google_calendar-quick-add-event",
|
|
5
5
|
name: "Add Quick Event",
|
|
6
6
|
description: "Create a quick event to the Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Events.html#quickAdd)",
|
|
7
|
-
version: "0.1.
|
|
7
|
+
version: "0.1.4",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
googleCalendar,
|
|
@@ -5,7 +5,7 @@ export default {
|
|
|
5
5
|
key: "google_calendar-update-event",
|
|
6
6
|
name: "Update Event",
|
|
7
7
|
description: "Update an event from Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Events.html#update)",
|
|
8
|
-
version: "0.0.
|
|
8
|
+
version: "0.0.6",
|
|
9
9
|
type: "action",
|
|
10
10
|
props: {
|
|
11
11
|
googleCalendar,
|
|
@@ -4,7 +4,7 @@ export default {
|
|
|
4
4
|
key: "google_calendar-update-event-attendees",
|
|
5
5
|
name: "Update attendees of an event",
|
|
6
6
|
description: "Update attendees of an existing event. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Events.html#update)",
|
|
7
|
-
version: "0.1.
|
|
7
|
+
version: "0.1.4",
|
|
8
8
|
type: "action",
|
|
9
9
|
props: {
|
|
10
10
|
googleCalendar,
|
package/common/utils.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
filterEmptyValues(obj) {
|
|
3
|
+
if (!obj) {
|
|
4
|
+
return obj;
|
|
5
|
+
}
|
|
6
|
+
return Object.entries(obj)
|
|
7
|
+
.reduce((reduction,
|
|
8
|
+
[
|
|
9
|
+
key,
|
|
10
|
+
value,
|
|
11
|
+
]) => {
|
|
12
|
+
if (value === undefined || value === null) {
|
|
13
|
+
return reduction;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
...reduction,
|
|
17
|
+
[key]: value,
|
|
18
|
+
};
|
|
19
|
+
}, {});
|
|
20
|
+
},
|
|
21
|
+
};
|
package/google_calendar.app.mjs
CHANGED
|
@@ -277,6 +277,18 @@ export default {
|
|
|
277
277
|
}));
|
|
278
278
|
},
|
|
279
279
|
},
|
|
280
|
+
eventTypes: {
|
|
281
|
+
type: "string[]",
|
|
282
|
+
label: "Event Types",
|
|
283
|
+
description: "Filter events by event type",
|
|
284
|
+
optional: true,
|
|
285
|
+
options: [
|
|
286
|
+
"default",
|
|
287
|
+
"focusTime",
|
|
288
|
+
"outOfOffice",
|
|
289
|
+
"workingLocation",
|
|
290
|
+
],
|
|
291
|
+
},
|
|
280
292
|
},
|
|
281
293
|
methods: {
|
|
282
294
|
_tokens() {
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ export default {
|
|
|
5
5
|
key: "google_calendar-event-cancelled",
|
|
6
6
|
name: "New Cancelled Event",
|
|
7
7
|
description: "Emit new event when a Google Calendar event is cancelled or deleted",
|
|
8
|
-
version: "0.1.
|
|
8
|
+
version: "0.1.7",
|
|
9
9
|
type: "source",
|
|
10
10
|
dedupe: "unique",
|
|
11
11
|
props: {
|
|
@@ -6,7 +6,7 @@ export default {
|
|
|
6
6
|
key: "google_calendar-event-start",
|
|
7
7
|
name: "New Event Start",
|
|
8
8
|
description: "Emit new event when the specified time before the Google Calendar event starts",
|
|
9
|
-
version: "0.1.
|
|
9
|
+
version: "0.1.8",
|
|
10
10
|
type: "source",
|
|
11
11
|
dedupe: "unique",
|
|
12
12
|
props: {
|
|
@@ -5,7 +5,7 @@ export default {
|
|
|
5
5
|
key: "google_calendar-new-event-search",
|
|
6
6
|
name: "New Event Matching a Search",
|
|
7
7
|
description: "Emit new event when a Google Calendar event is created that matches a search",
|
|
8
|
-
version: "0.1.
|
|
8
|
+
version: "0.1.7",
|
|
9
9
|
type: "source",
|
|
10
10
|
dedupe: "unique",
|
|
11
11
|
props: {
|
|
@@ -5,7 +5,7 @@ export default {
|
|
|
5
5
|
key: "google_calendar-new-or-updated-event",
|
|
6
6
|
name: "New Created or Updated Event",
|
|
7
7
|
description: "Emit new event when a Google Calendar events is created or updated (does not emit cancelled events)",
|
|
8
|
-
version: "0.1.
|
|
8
|
+
version: "0.1.7",
|
|
9
9
|
type: "source",
|
|
10
10
|
dedupe: "unique",
|
|
11
11
|
props: {
|
|
@@ -8,7 +8,7 @@ export default {
|
|
|
8
8
|
type: "source",
|
|
9
9
|
name: "New Created or Updated Event (Instant)",
|
|
10
10
|
description: "Emit new event when a Google Calendar events is created or updated (does not emit cancelled events)",
|
|
11
|
-
version: "0.1.
|
|
11
|
+
version: "0.1.11",
|
|
12
12
|
dedupe: "unique",
|
|
13
13
|
props: {
|
|
14
14
|
googleCalendar,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import taskScheduler from "../../../pipedream/sources/new-scheduled-tasks/new-scheduled-tasks.mjs";
|
|
2
2
|
import googleCalendar from "../../google_calendar.app.mjs";
|
|
3
|
-
import { axios } from "@pipedream/platform";
|
|
4
3
|
|
|
5
4
|
export default {
|
|
6
5
|
key: "google_calendar-upcoming-event-alert",
|
|
@@ -8,7 +7,7 @@ export default {
|
|
|
8
7
|
description: `Emit new event based on a time interval before an upcoming event in the calendar. This source uses Pipedream's Task Scheduler.
|
|
9
8
|
[See the documentation](https://pipedream.com/docs/examples/waiting-to-execute-next-step-of-workflow/#step-1-create-a-task-scheduler-event-source)
|
|
10
9
|
for more information and instructions for connecting your Pipedream account.`,
|
|
11
|
-
version: "0.0.
|
|
10
|
+
version: "0.0.6",
|
|
12
11
|
type: "source",
|
|
13
12
|
props: {
|
|
14
13
|
pipedream: taskScheduler.props.pipedream,
|
|
@@ -29,45 +28,60 @@ export default {
|
|
|
29
28
|
calendarId: c.calendarId,
|
|
30
29
|
}),
|
|
31
30
|
],
|
|
31
|
+
optional: true,
|
|
32
32
|
},
|
|
33
33
|
time: {
|
|
34
34
|
type: "integer",
|
|
35
35
|
label: "Minutes Before",
|
|
36
36
|
description: "Number of minutes to trigger before the start of the calendar event.",
|
|
37
37
|
min: 0,
|
|
38
|
+
reloadProps: true,
|
|
38
39
|
},
|
|
39
40
|
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
schedule: true,
|
|
41
|
+
async additionalProps() {
|
|
42
|
+
const props = {};
|
|
43
|
+
if (this.time > 0) {
|
|
44
|
+
props.timer = {
|
|
45
|
+
type: "$.interface.timer",
|
|
46
|
+
description: "Poll the API to schedule alerts for any newly created events",
|
|
47
|
+
default: {
|
|
48
|
+
intervalSeconds: 60 * this.time,
|
|
49
49
|
},
|
|
50
|
-
}
|
|
51
|
-
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return props;
|
|
53
|
+
},
|
|
54
|
+
hooks: {
|
|
52
55
|
async deactivate() {
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
id,
|
|
57
|
-
},
|
|
58
|
-
})) {
|
|
59
|
-
console.log("Cancelled scheduled event");
|
|
60
|
-
this._setScheduledEventId();
|
|
56
|
+
const ids = this._getScheduledEventIds();
|
|
57
|
+
if (!ids?.length) {
|
|
58
|
+
return;
|
|
61
59
|
}
|
|
60
|
+
for (const id of ids) {
|
|
61
|
+
if (await this.deleteEvent({
|
|
62
|
+
body: {
|
|
63
|
+
id,
|
|
64
|
+
},
|
|
65
|
+
})) {
|
|
66
|
+
console.log("Cancelled scheduled event");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
this._setScheduledEventIds();
|
|
62
70
|
},
|
|
63
71
|
},
|
|
64
72
|
methods: {
|
|
65
73
|
...taskScheduler.methods,
|
|
66
|
-
|
|
67
|
-
return this.db.get("
|
|
74
|
+
_getScheduledEventIds() {
|
|
75
|
+
return this.db.get("scheduledEventIds");
|
|
76
|
+
},
|
|
77
|
+
_setScheduledEventIds(ids) {
|
|
78
|
+
this.db.set("scheduledEventIds", ids);
|
|
68
79
|
},
|
|
69
|
-
|
|
70
|
-
this.db.
|
|
80
|
+
_getScheduledCalendarEventIds() {
|
|
81
|
+
return this.db.get("scheduledCalendarEventIds");
|
|
82
|
+
},
|
|
83
|
+
_setScheduledCalendarEventIds(ids) {
|
|
84
|
+
this.db.set("scheduledCalendarEventIds", ids);
|
|
71
85
|
},
|
|
72
86
|
_hasDeployed() {
|
|
73
87
|
const result = this.db.get("hasDeployed");
|
|
@@ -77,6 +91,32 @@ export default {
|
|
|
77
91
|
subtractMinutes(date, minutes) {
|
|
78
92
|
return date.getTime() - minutes * 60000;
|
|
79
93
|
},
|
|
94
|
+
async getCalendarEvents() {
|
|
95
|
+
const calendarEvents = [];
|
|
96
|
+
const params = {
|
|
97
|
+
calendarId: this.calendarId,
|
|
98
|
+
};
|
|
99
|
+
if (this.eventId) {
|
|
100
|
+
const item = await this.googleCalendar.getEvent({
|
|
101
|
+
...params,
|
|
102
|
+
eventId: this.eventId,
|
|
103
|
+
});
|
|
104
|
+
calendarEvents.push(item);
|
|
105
|
+
} else {
|
|
106
|
+
do {
|
|
107
|
+
const {
|
|
108
|
+
data: {
|
|
109
|
+
items, nextPageToken,
|
|
110
|
+
},
|
|
111
|
+
} = await this.googleCalendar.getEvents(params);
|
|
112
|
+
if (items?.length) {
|
|
113
|
+
calendarEvents.push(...items);
|
|
114
|
+
}
|
|
115
|
+
params.pageToken = nextPageToken;
|
|
116
|
+
} while (params.pageToken);
|
|
117
|
+
}
|
|
118
|
+
return calendarEvents;
|
|
119
|
+
},
|
|
80
120
|
},
|
|
81
121
|
async run(event) {
|
|
82
122
|
// self subscribe only on the first time
|
|
@@ -84,25 +124,37 @@ export default {
|
|
|
84
124
|
await this.selfSubscribe();
|
|
85
125
|
}
|
|
86
126
|
|
|
127
|
+
const scheduledEventIds = this._getScheduledEventIds() || [];
|
|
128
|
+
|
|
87
129
|
// incoming scheduled event
|
|
88
130
|
if (event.$channel === this.selfChannel()) {
|
|
131
|
+
const remainingScheduledEventIds = scheduledEventIds.filter((id) => id !== event["$id"]);
|
|
132
|
+
this._setScheduledEventIds(remainingScheduledEventIds);
|
|
89
133
|
this.emitEvent(event, `Upcoming ${event.summary} event`);
|
|
90
|
-
this._setScheduledEventId();
|
|
91
134
|
return;
|
|
92
135
|
}
|
|
93
136
|
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
calendarId: this.calendarId,
|
|
98
|
-
eventId: this.eventId,
|
|
99
|
-
});
|
|
137
|
+
// schedule new events
|
|
138
|
+
const scheduledCalendarEventIds = this._getScheduledCalendarEventIds() || {};
|
|
139
|
+
const calendarEvents = await this.getCalendarEvents();
|
|
100
140
|
|
|
101
|
-
|
|
141
|
+
for (const calendarEvent of calendarEvents) {
|
|
142
|
+
const startTime = calendarEvent.start
|
|
143
|
+
? (new Date(calendarEvent.start.dateTime || calendarEvent.start.date))
|
|
144
|
+
: null;
|
|
145
|
+
if (!startTime
|
|
146
|
+
|| startTime.getTime() < Date.now()
|
|
147
|
+
|| scheduledCalendarEventIds[calendarEvent.id])
|
|
148
|
+
{
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
102
151
|
const later = new Date(this.subtractMinutes(startTime, this.time));
|
|
103
152
|
|
|
104
153
|
const scheduledEventId = this.emitScheduleEvent(calendarEvent, later);
|
|
105
|
-
|
|
154
|
+
scheduledEventIds.push(scheduledEventId);
|
|
155
|
+
scheduledCalendarEventIds[calendarEvent.id] = true;
|
|
106
156
|
}
|
|
157
|
+
this._setScheduledEventIds(scheduledEventIds);
|
|
158
|
+
this._setScheduledCalendarEventIds(scheduledCalendarEventIds);
|
|
107
159
|
},
|
|
108
160
|
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import taskScheduler from "../../../pipedream/sources/new-scheduled-tasks/new-scheduled-tasks.mjs";
|
|
2
|
+
import googleCalendar from "../../google_calendar.app.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: "google_calendar-upcoming-event-type-alert",
|
|
6
|
+
name: "New Upcoming Event Type Alert",
|
|
7
|
+
description: `Emit new event based on a time interval before an upcoming event of the specified type ("default", "focusTime", "outOfOffice", "workingLocation") in the calendar. This source uses Pipedream's Task Scheduler.
|
|
8
|
+
[See the documentation](https://pipedream.com/docs/examples/waiting-to-execute-next-step-of-workflow/#step-1-create-a-task-scheduler-event-source)
|
|
9
|
+
for more information and instructions for connecting your Pipedream account.`,
|
|
10
|
+
version: "0.0.1",
|
|
11
|
+
type: "source",
|
|
12
|
+
props: {
|
|
13
|
+
pipedream: taskScheduler.props.pipedream,
|
|
14
|
+
googleCalendar,
|
|
15
|
+
db: "$.service.db",
|
|
16
|
+
http: "$.interface.http",
|
|
17
|
+
calendarId: {
|
|
18
|
+
propDefinition: [
|
|
19
|
+
googleCalendar,
|
|
20
|
+
"calendarId",
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
eventTypes: {
|
|
24
|
+
propDefinition: [
|
|
25
|
+
googleCalendar,
|
|
26
|
+
"eventTypes",
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
time: {
|
|
30
|
+
type: "integer",
|
|
31
|
+
label: "Minutes Before",
|
|
32
|
+
description: "Number of minutes to trigger before the start of the calendar event.",
|
|
33
|
+
min: 0,
|
|
34
|
+
reloadProps: true,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
async additionalProps() {
|
|
38
|
+
const props = {};
|
|
39
|
+
if (this.time > 0) {
|
|
40
|
+
props.timer = {
|
|
41
|
+
type: "$.interface.timer",
|
|
42
|
+
description: "Poll the API to schedule alerts for any newly created events",
|
|
43
|
+
default: {
|
|
44
|
+
intervalSeconds: 60 * this.time,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return props;
|
|
49
|
+
},
|
|
50
|
+
hooks: {
|
|
51
|
+
async deactivate() {
|
|
52
|
+
const ids = this._getScheduledEventIds();
|
|
53
|
+
if (!ids?.length) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
for (const id of ids) {
|
|
57
|
+
if (await this.deleteEvent({
|
|
58
|
+
body: {
|
|
59
|
+
id,
|
|
60
|
+
},
|
|
61
|
+
})) {
|
|
62
|
+
console.log("Cancelled scheduled event");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
this._setScheduledEventIds();
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
methods: {
|
|
69
|
+
...taskScheduler.methods,
|
|
70
|
+
_getScheduledEventIds() {
|
|
71
|
+
return this.db.get("scheduledEventIds");
|
|
72
|
+
},
|
|
73
|
+
_setScheduledEventIds(ids) {
|
|
74
|
+
this.db.set("scheduledEventIds", ids);
|
|
75
|
+
},
|
|
76
|
+
_getScheduledCalendarEventIds() {
|
|
77
|
+
return this.db.get("scheduledCalendarEventIds");
|
|
78
|
+
},
|
|
79
|
+
_setScheduledCalendarEventIds(ids) {
|
|
80
|
+
this.db.set("scheduledCalendarEventIds", ids);
|
|
81
|
+
},
|
|
82
|
+
_hasDeployed() {
|
|
83
|
+
const result = this.db.get("hasDeployed");
|
|
84
|
+
this.db.set("hasDeployed", true);
|
|
85
|
+
return result;
|
|
86
|
+
},
|
|
87
|
+
subtractMinutes(date, minutes) {
|
|
88
|
+
return date.getTime() - minutes * 60000;
|
|
89
|
+
},
|
|
90
|
+
async getCalendarEvents() {
|
|
91
|
+
const calendarEvents = [];
|
|
92
|
+
const params = {
|
|
93
|
+
calendarId: this.calendarId,
|
|
94
|
+
eventTypes: this.eventTypes,
|
|
95
|
+
};
|
|
96
|
+
do {
|
|
97
|
+
const {
|
|
98
|
+
data: {
|
|
99
|
+
items, nextPageToken,
|
|
100
|
+
},
|
|
101
|
+
} = await this.googleCalendar.getEvents(params);
|
|
102
|
+
if (items?.length) {
|
|
103
|
+
calendarEvents.push(...items);
|
|
104
|
+
}
|
|
105
|
+
params.pageToken = nextPageToken;
|
|
106
|
+
} while (params.pageToken);
|
|
107
|
+
return calendarEvents;
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
async run(event) {
|
|
111
|
+
// self subscribe only on the first time
|
|
112
|
+
if (!this._hasDeployed()) {
|
|
113
|
+
await this.selfSubscribe();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const scheduledEventIds = this._getScheduledEventIds() || [];
|
|
117
|
+
|
|
118
|
+
// incoming scheduled event
|
|
119
|
+
if (event.$channel === this.selfChannel()) {
|
|
120
|
+
const remainingScheduledEventIds = scheduledEventIds.filter((id) => id !== event["$id"]);
|
|
121
|
+
this._setScheduledEventIds(remainingScheduledEventIds);
|
|
122
|
+
this.emitEvent(event, `Upcoming ${event.summary} event`);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// schedule new events
|
|
127
|
+
const scheduledCalendarEventIds = this._getScheduledCalendarEventIds() || {};
|
|
128
|
+
const calendarEvents = await this.getCalendarEvents();
|
|
129
|
+
|
|
130
|
+
for (const calendarEvent of calendarEvents) {
|
|
131
|
+
const startTime = calendarEvent.start
|
|
132
|
+
? (new Date(calendarEvent.start.dateTime || calendarEvent.start.date))
|
|
133
|
+
: null;
|
|
134
|
+
if (!startTime
|
|
135
|
+
|| startTime.getTime() < Date.now()
|
|
136
|
+
|| scheduledCalendarEventIds[calendarEvent.id])
|
|
137
|
+
{
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const later = new Date(this.subtractMinutes(startTime, this.time));
|
|
141
|
+
|
|
142
|
+
const scheduledEventId = this.emitScheduleEvent(calendarEvent, later);
|
|
143
|
+
scheduledEventIds.push(scheduledEventId);
|
|
144
|
+
scheduledCalendarEventIds[calendarEvent.id] = true;
|
|
145
|
+
}
|
|
146
|
+
this._setScheduledEventIds(scheduledEventIds);
|
|
147
|
+
this._setScheduledCalendarEventIds(scheduledCalendarEventIds);
|
|
148
|
+
},
|
|
149
|
+
};
|