@pipedream/microsoft_outlook 1.6.0 → 1.7.0
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
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
import common from "../common/common-new-email.mjs";
|
|
2
|
+
import { Readable } from "stream";
|
|
2
3
|
|
|
3
4
|
export default {
|
|
4
5
|
...common,
|
|
5
6
|
key: "microsoft_outlook-new-attachment-received",
|
|
6
7
|
name: "New Attachment Received (Instant)",
|
|
7
8
|
description: "Emit new event when a new email containing one or more attachments arrives in a specified Microsoft Outlook folder.",
|
|
8
|
-
version: "0.0
|
|
9
|
+
version: "0.1.0",
|
|
9
10
|
type: "source",
|
|
10
11
|
dedupe: "unique",
|
|
12
|
+
props: {
|
|
13
|
+
...common.props,
|
|
14
|
+
includeLink: {
|
|
15
|
+
label: "Include Link",
|
|
16
|
+
type: "boolean",
|
|
17
|
+
description: "Upload attachment to your File Stash and emit temporary download link to the file. See [the docs](https://pipedream.com/docs/connect/components/files) to learn more about working with files in Pipedream.",
|
|
18
|
+
default: false,
|
|
19
|
+
optional: true,
|
|
20
|
+
},
|
|
21
|
+
dir: {
|
|
22
|
+
type: "dir",
|
|
23
|
+
accessMode: "write",
|
|
24
|
+
optional: true,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
11
27
|
methods: {
|
|
12
28
|
...common.methods,
|
|
13
29
|
async getSampleEvents({ pageSize }) {
|
|
@@ -36,8 +52,48 @@ export default {
|
|
|
36
52
|
}
|
|
37
53
|
return attachments;
|
|
38
54
|
},
|
|
39
|
-
|
|
55
|
+
async getMessageAttachments(message) {
|
|
56
|
+
const { value: attachments } = await this.microsoftOutlook.listAttachments({
|
|
57
|
+
messageId: message.id,
|
|
58
|
+
});
|
|
59
|
+
if (!attachments?.length) {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
return attachments.map((attachment) => ({
|
|
63
|
+
...attachment,
|
|
64
|
+
messageId: message.id,
|
|
65
|
+
messageSubject: message.subject,
|
|
66
|
+
messageSender: message.sender,
|
|
67
|
+
messageReceivedDateTime: message.receivedDateTime,
|
|
68
|
+
parentFolderId: message.parentFolderId,
|
|
69
|
+
contentBytes: undefined,
|
|
70
|
+
}));
|
|
71
|
+
},
|
|
72
|
+
async stashAttachment(item) {
|
|
73
|
+
const messageAttachment = await this.microsoftOutlook.getAttachment({
|
|
74
|
+
messageId: item.messageId,
|
|
75
|
+
attachmentId: item.id,
|
|
76
|
+
responseType: "arraybuffer",
|
|
77
|
+
});
|
|
78
|
+
const rawcontent = messageAttachment.toString("base64");
|
|
79
|
+
const buffer = Buffer.from(rawcontent, "base64");
|
|
80
|
+
const filepath = `${item.id}/${item.name}`;
|
|
81
|
+
// Upload the attachment to the configured directory (File Stash) so it
|
|
82
|
+
// can be accessed later.
|
|
83
|
+
const file = await this.dir.open(filepath).fromReadableStream(
|
|
84
|
+
Readable.from(buffer),
|
|
85
|
+
item.contentType,
|
|
86
|
+
buffer.length,
|
|
87
|
+
);
|
|
88
|
+
// Return file details and temporary download link:
|
|
89
|
+
// { path, get_url, s3Key, type }
|
|
90
|
+
return await file.withoutPutUrl().withGetUrl();
|
|
91
|
+
},
|
|
92
|
+
async emitEvent(item) {
|
|
40
93
|
if (this.isRelevant(item)) {
|
|
94
|
+
if (this.includeLink) {
|
|
95
|
+
item.file = await this.stashAttachment(item);
|
|
96
|
+
}
|
|
41
97
|
this.$emit(item, this.generateMeta(item));
|
|
42
98
|
}
|
|
43
99
|
},
|
|
@@ -67,7 +123,9 @@ export default {
|
|
|
67
123
|
});
|
|
68
124
|
if (message.hasAttachments) {
|
|
69
125
|
const attachments = await this.getMessageAttachments(message);
|
|
70
|
-
|
|
126
|
+
for (const item of attachments) {
|
|
127
|
+
await this.emitEvent(item);
|
|
128
|
+
}
|
|
71
129
|
}
|
|
72
130
|
} catch {
|
|
73
131
|
console.log(`Could not fetch message with ID: ${resourceId}`);
|
|
@@ -7,7 +7,7 @@ export default {
|
|
|
7
7
|
key: "microsoft_outlook-new-email",
|
|
8
8
|
name: "New Email Event (Instant)",
|
|
9
9
|
description: "Emit new event when an email is received in specified folders.",
|
|
10
|
-
version: "0.1.
|
|
10
|
+
version: "0.1.2",
|
|
11
11
|
type: "source",
|
|
12
12
|
dedupe: "unique",
|
|
13
13
|
methods: {
|