@pipedream/microsoft_outlook 1.0.3 → 1.0.4
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/README.md +8 -6
- package/package.json +2 -1
- package/sources/new-email/new-email.mjs +105 -22
package/README.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# Overview
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
services that work with Outlook. Here are some examples:
|
|
3
|
+
The Microsoft Outlook API on Pipedream allows you to automate email-related tasks, manage calendars, and handle contacts effortlessly. With the API, you can trigger workflows on new emails, send emails programmatically, and synchronize calendars across platforms, among other functions. Pipedream's serverless platform facilitates the connection between Outlook and a myriad of other apps for efficient automation workflows.
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
-
|
|
9
|
-
|
|
5
|
+
# Example Use Cases
|
|
6
|
+
|
|
7
|
+
- **Email Event to Slack Notification**: When receiving an email from a specific sender or with certain keywords, you can automatically post a message to a Slack channel. This keeps teams informed of important communications without manual monitoring of inboxes.
|
|
8
|
+
|
|
9
|
+
- **Calendar Sync with Google Calendar**: Upon the creation of a new event in Outlook Calendar, sync this event to Google Calendar. This is ideal for individuals who use multiple calendar services and want to ensure consistency across platforms without manual duplication of events.
|
|
10
|
+
|
|
11
|
+
- **Automated Email Responses**: Set up a workflow that sends an automated response to emails that meet specific criteria, such as out-of-office replies or acknowledging receipt of customer inquiries. This helps maintain communication with contacts even when you're not actively managing your inbox.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pipedream/microsoft_outlook",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Pipedream Microsoft Outlook Components",
|
|
5
5
|
"main": "microsoft_outlook.app.mjs",
|
|
6
6
|
"keywords": [
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"axios": "^0.21.1",
|
|
16
16
|
"js-base64": "^3.7.2",
|
|
17
|
+
"md5": "^2.3.0",
|
|
17
18
|
"mime-types": "^2.1.35"
|
|
18
19
|
},
|
|
19
20
|
"publishConfig": {
|
|
@@ -1,19 +1,53 @@
|
|
|
1
1
|
import common from "../common.mjs";
|
|
2
|
+
import md5 from "md5";
|
|
2
3
|
import sampleEmit from "./test-event.mjs";
|
|
3
4
|
|
|
4
5
|
export default {
|
|
5
6
|
...common,
|
|
6
7
|
key: "microsoft_outlook-new-email",
|
|
7
8
|
name: "New Email Event (Instant)",
|
|
8
|
-
description: "Emit new event when an email received",
|
|
9
|
-
version: "0.0.
|
|
9
|
+
description: "Emit new event when an email is received in specified folders.",
|
|
10
|
+
version: "0.0.10",
|
|
10
11
|
type: "source",
|
|
12
|
+
dedupe: "unique",
|
|
13
|
+
props: {
|
|
14
|
+
...common.props,
|
|
15
|
+
folderIds: {
|
|
16
|
+
type: "string[]",
|
|
17
|
+
label: "Folder IDs to Monitor",
|
|
18
|
+
description: "Specify the folder IDs or names in Outlook that you want to monitor for new emails. Leave empty to monitor all folders (excluding \"Sent Items\" and \"Drafts\").",
|
|
19
|
+
optional: true,
|
|
20
|
+
async options() {
|
|
21
|
+
const { value: folders } = await this.listFolders();
|
|
22
|
+
return folders?.map(({
|
|
23
|
+
id: value, displayName: label,
|
|
24
|
+
}) => ({
|
|
25
|
+
value,
|
|
26
|
+
label,
|
|
27
|
+
})) || [];
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
11
31
|
hooks: {
|
|
12
32
|
...common.hooks,
|
|
33
|
+
async deploy() {
|
|
34
|
+
this.db.set("sentItemFolderId", await this.getFolderIdByName("Sent Items"));
|
|
35
|
+
this.db.set("draftsFolderId", await this.getFolderIdByName("Drafts"));
|
|
36
|
+
|
|
37
|
+
const events = await this.getSampleEvents({
|
|
38
|
+
pageSize: 25,
|
|
39
|
+
});
|
|
40
|
+
if (!events || events.length == 0) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
for (const item of events) {
|
|
44
|
+
this.emitEvent(item);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
13
47
|
async activate() {
|
|
14
48
|
await this.activate({
|
|
15
49
|
changeType: "created",
|
|
16
|
-
resource: "/me/
|
|
50
|
+
resource: "/me/messages",
|
|
17
51
|
});
|
|
18
52
|
},
|
|
19
53
|
async deactivate() {
|
|
@@ -22,37 +56,86 @@ export default {
|
|
|
22
56
|
},
|
|
23
57
|
methods: {
|
|
24
58
|
...common.methods,
|
|
25
|
-
|
|
26
|
-
return this.microsoftOutlook.
|
|
27
|
-
|
|
28
|
-
$top: pageSize,
|
|
29
|
-
$orderby: "createdDateTime desc",
|
|
30
|
-
},
|
|
59
|
+
listFolders() {
|
|
60
|
+
return this.microsoftOutlook._makeRequest({
|
|
61
|
+
path: "/me/mailFolders",
|
|
31
62
|
});
|
|
32
63
|
},
|
|
64
|
+
async getFolderIdByName(name) {
|
|
65
|
+
const { value: folders } = await this.listFolders();
|
|
66
|
+
const { id } = folders.find(({ displayName }) => displayName === name);
|
|
67
|
+
return id;
|
|
68
|
+
},
|
|
69
|
+
async getSampleEvents({ pageSize }) {
|
|
70
|
+
const folders = this.folderIds?.length
|
|
71
|
+
? this.folderIds.map((id) => `/me/mailFolders/${id}/messages`)
|
|
72
|
+
: [
|
|
73
|
+
"/me/messages",
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
const results = [];
|
|
77
|
+
for (const folder of folders) {
|
|
78
|
+
const { value: messages } = await this.microsoftOutlook.listMessages({
|
|
79
|
+
resource: folder,
|
|
80
|
+
params: {
|
|
81
|
+
$top: pageSize,
|
|
82
|
+
$orderby: "createdDateTime desc",
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
results.push(...messages);
|
|
86
|
+
}
|
|
87
|
+
return results;
|
|
88
|
+
},
|
|
89
|
+
isRelevant(item) {
|
|
90
|
+
if (this.folderIds?.length) {
|
|
91
|
+
return this.folderIds.includes(item.parentFolderId);
|
|
92
|
+
}
|
|
93
|
+
// if no folderIds are specified, filter out items in Sent Items & Drafts
|
|
94
|
+
const sentItemFolderId = this.db.get("sentItemFolderId");
|
|
95
|
+
const draftsFolderId = this.db.get("draftsFolderId");
|
|
96
|
+
return item.parentFolderId !== sentItemFolderId && item.parentFolderId !== draftsFolderId;
|
|
97
|
+
},
|
|
33
98
|
emitEvent(item) {
|
|
34
|
-
this
|
|
35
|
-
|
|
36
|
-
|
|
99
|
+
if (this.isRelevant(item)) {
|
|
100
|
+
this.$emit(
|
|
101
|
+
{
|
|
102
|
+
email: item,
|
|
103
|
+
},
|
|
104
|
+
this.generateMeta(item),
|
|
105
|
+
);
|
|
106
|
+
}
|
|
37
107
|
},
|
|
38
108
|
generateMeta(item) {
|
|
39
109
|
return {
|
|
40
|
-
id: item.id,
|
|
110
|
+
id: md5(item.id), // id > 64 characters, so dedupe on hash of id
|
|
41
111
|
summary: `New email (ID:${item.id})`,
|
|
42
112
|
ts: Date.parse(item.createdDateTime),
|
|
43
113
|
};
|
|
44
114
|
},
|
|
45
115
|
},
|
|
46
116
|
async run(event) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
117
|
+
const folders = this.folderIds?.length
|
|
118
|
+
? this.folderIds.map((id) => `/me/mailFolders/${id}/messages`)
|
|
119
|
+
: [
|
|
120
|
+
"/me/messages",
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
for (const folder of folders) {
|
|
124
|
+
await this.run({
|
|
125
|
+
event,
|
|
126
|
+
emitFn: async ({ resourceId } = {}) => {
|
|
127
|
+
try {
|
|
128
|
+
const item = await this.microsoftOutlook.getMessage({
|
|
129
|
+
resource: folder,
|
|
130
|
+
messageId: resourceId,
|
|
131
|
+
});
|
|
132
|
+
this.emitEvent(item);
|
|
133
|
+
} catch {
|
|
134
|
+
console.log(`Could not fetch message with ID: ${resourceId}`);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
}
|
|
56
139
|
},
|
|
57
140
|
sampleEmit,
|
|
58
141
|
};
|