@pipedream/microsoft_outlook 0.0.8 → 0.0.9
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/package.json
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import common from "../common.mjs";
|
|
2
|
+
import taskScheduler from "../../../pipedream/sources/new-scheduled-tasks/new-scheduled-tasks.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
...common,
|
|
6
|
+
key: "microsoft_outlook-new-upcoming-event",
|
|
7
|
+
name: "New Upcoming Calendar Event",
|
|
8
|
+
description: "Emit new event when a Calendar event is upcoming, this source is using `reminderMinutesBeforeStart` property of the event to determine the time it should emit.",
|
|
9
|
+
version: "0.0.1",
|
|
10
|
+
type: "source",
|
|
11
|
+
props: {
|
|
12
|
+
...common.props,
|
|
13
|
+
pipedream: taskScheduler.props.pipedream,
|
|
14
|
+
},
|
|
15
|
+
hooks: {
|
|
16
|
+
...common.hooks,
|
|
17
|
+
async activate() {
|
|
18
|
+
await this.activate({
|
|
19
|
+
changeType: "updated",
|
|
20
|
+
resource: "/me/events",
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
async deactivate() {
|
|
24
|
+
await this.deactivate();
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
methods: {
|
|
28
|
+
...taskScheduler.methods,
|
|
29
|
+
...common.methods,
|
|
30
|
+
_hasDeployed() {
|
|
31
|
+
const result = this.db.get("hasDeployed");
|
|
32
|
+
this.db.set("hasDeployed", true);
|
|
33
|
+
return result;
|
|
34
|
+
},
|
|
35
|
+
subtractMinutes(date, minutes) {
|
|
36
|
+
return date.getTime() - minutes * 60000;
|
|
37
|
+
},
|
|
38
|
+
async getSampleEvents({ pageSize }) {
|
|
39
|
+
return this.microsoftOutlook.listCalendarEvents({
|
|
40
|
+
params: {
|
|
41
|
+
$top: pageSize,
|
|
42
|
+
$orderby: "lastModifiedDateTime desc",
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
emitEvent(item) {
|
|
47
|
+
this.$emit({
|
|
48
|
+
message: item,
|
|
49
|
+
}, this.generateMeta(item));
|
|
50
|
+
},
|
|
51
|
+
generateMeta(item) {
|
|
52
|
+
return {
|
|
53
|
+
id: item.id,
|
|
54
|
+
summary: `Upcoming event - ${item.subject}`,
|
|
55
|
+
ts: +Date.parse(item.createdDateTime),
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
async run(event) {
|
|
60
|
+
if (event.$channel === this.selfChannel()) {
|
|
61
|
+
const item = await this.microsoftOutlook.getCalendarEvent({
|
|
62
|
+
eventId: event.eventId,
|
|
63
|
+
});
|
|
64
|
+
// checking if the event was modified after this scheduling
|
|
65
|
+
if (item.lastModifiedDateTime === event.lastModifiedControl) {
|
|
66
|
+
this.emitEvent(item);
|
|
67
|
+
}
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
await this.run({
|
|
71
|
+
event,
|
|
72
|
+
emitFn: async ({ resourceId } = {}) => {
|
|
73
|
+
if (!this._hasDeployed()) {
|
|
74
|
+
await this.selfSubscribe();
|
|
75
|
+
}
|
|
76
|
+
const item = await this.microsoftOutlook.getCalendarEvent({
|
|
77
|
+
eventId: resourceId,
|
|
78
|
+
});
|
|
79
|
+
if (event.$channel !== this.selfChannel()) {
|
|
80
|
+
const startTime = new Date(item.start.dateTime || item.start.date);
|
|
81
|
+
const reminderMinutesBeforeStart = item.reminderMinutesBeforeStart || 15;
|
|
82
|
+
const later = new Date(this.subtractMinutes(startTime, reminderMinutesBeforeStart));
|
|
83
|
+
const newEvent = {
|
|
84
|
+
lastModifiedControl: item.lastModifiedDateTime,
|
|
85
|
+
eventId: resourceId,
|
|
86
|
+
};
|
|
87
|
+
this.emitScheduleEvent(newEvent, later);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
};
|