Skip to content

Microsoft Outlook: New Attachment Received & Download Attachment #16324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "microsoft_outlook-add-label-to-email",
name: "Add Label to Email",
description: "Adds a label/category to an email in Microsoft Outlook. [See the documentation](https://learn.microsoft.com/en-us/graph/api/message-update)",
version: "0.0.5",
version: "0.0.6",
type: "action",
props: {
microsoftOutlook,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "microsoft_outlook-approve-workflow",
name: "Approve Workflow",
description: "Suspend the workflow until approved by email. [See the documentation](https://pipedream.com/docs/code/nodejs/rerun#flowsuspend)",
version: "0.0.3",
version: "0.0.4",
type: "action",
props: {
microsoftOutlook,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
export default {
type: "action",
key: "microsoft_outlook-create-contact",
version: "0.0.12",
version: "0.0.13",
name: "Create Contact",
description: "Add a contact to the root Contacts folder, [See the documentation](https://docs.microsoft.com/en-us/graph/api/user-post-contacts)",
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
export default {
type: "action",
key: "microsoft_outlook-create-draft-email",
version: "0.0.12",
version: "0.0.13",
name: "Create Draft Email",
description: "Create a draft email, [See the documentation](https://docs.microsoft.com/en-us/graph/api/user-post-messages)",
props: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import microsoftOutlook from "../../microsoft_outlook.app.mjs";
import fs from "fs";
import mime from "mime-types";

export default {
key: "microsoft_outlook-download-attachment",
name: "Download Attachment",
description: "Downloads an attachment to the /tmp directory. [See the documentation](https://learn.microsoft.com/en-us/graph/api/attachment-get?view=graph-rest-1.0&tabs=http)",
version: "0.0.1",
type: "action",
props: {
microsoftOutlook,
messageId: {
propDefinition: [
microsoftOutlook,
"messageId",
],
description: "The identifier of the message containing the attachment to download",
},
attachmentId: {
propDefinition: [
microsoftOutlook,
"attachmentId",
(c) => ({
messageId: c.messageId,
}),
],
},
filename: {
type: "string",
label: "Filename",
description: "The filename to save the attachment as in the /tmp directory",
},
},
async run({ $ }) {
const response = await this.microsoftOutlook.getAttachment({
$,
messageId: this.messageId,
attachmentId: this.attachmentId,
responseType: "arraybuffer",
});

const rawcontent = response.toString("base64");
const buffer = Buffer.from(rawcontent, "base64");
const downloadedFilepath = `/tmp/${this.filename}`;
fs.writeFileSync(downloadedFilepath, buffer);
const contentType = mime.lookup(downloadedFilepath);

return {
fileName: this.filename,
contentType,
filePath: downloadedFilepath,
};
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
export default {
type: "action",
key: "microsoft_outlook-find-contacts",
version: "0.0.12",
version: "0.0.13",
name: "Find Contacts",
description: "Finds contacts with the given search string. [See the documentation](https://docs.microsoft.com/en-us/graph/api/user-list-contacts)",
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "microsoft_outlook-find-email",
name: "Find Email",
description: "Search for an email in Microsoft Outlook. [See the documentation](https://learn.microsoft.com/en-us/graph/api/user-list-messages)",
version: "0.0.3",
version: "0.0.4",
type: "action",
props: {
microsoftOutlook,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
export default {
type: "action",
key: "microsoft_outlook-list-contacts",
version: "0.0.12",
version: "0.0.13",
name: "List Contacts",
description: "Get a contact collection from the default contacts folder, [See the documentation](https://docs.microsoft.com/en-us/graph/api/user-list-contacts)",
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "microsoft_outlook-list-folders",
name: "List Folders",
description: "Retrieves a list of all folders in Microsoft Outlook. [See the documentation](https://learn.microsoft.com/en-us/graph/api/user-list-mailfolders)",
version: "0.0.3",
version: "0.0.4",
type: "action",
props: {
microsoftOutlook,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "microsoft_outlook-list-labels",
name: "List Labels",
description: "Get all the labels/categories that have been defined for a user. [See the documentation](https://learn.microsoft.com/en-us/graph/api/outlookuser-list-mastercategories)",
version: "0.0.5",
version: "0.0.6",
type: "action",
props: {
microsoftOutlook,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "microsoft_outlook-move-email-to-folder",
name: "Move Email to Folder",
description: "Moves an email to the specified folder in Microsoft Outlook. [See the documentation](https://learn.microsoft.com/en-us/graph/api/message-move)",
version: "0.0.3",
version: "0.0.4",
type: "action",
props: {
microsoftOutlook,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "microsoft_outlook-remove-label-from-email",
name: "Remove Label from Email",
description: "Removes a label/category from an email in Microsoft Outlook. [See the documentation](https://learn.microsoft.com/en-us/graph/api/message-update)",
version: "0.0.5",
version: "0.0.6",
type: "action",
props: {
microsoftOutlook,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "microsoft_outlook-reply-to-email",
name: "Reply to Email",
description: "Reply to an email in Microsoft Outlook. [See the documentation](https://learn.microsoft.com/en-us/graph/api/message-reply)",
version: "0.0.2",
version: "0.0.3",
type: "action",
props: {
microsoftOutlook,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
export default {
type: "action",
key: "microsoft_outlook-send-email",
version: "0.0.13",
version: "0.0.14",
name: "Send Email",
description: "Send an email to one or multiple recipients, [See the docs](https://docs.microsoft.com/en-us/graph/api/user-sendmail)",
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
export default {
type: "action",
key: "microsoft_outlook-update-contact",
version: "0.0.12",
version: "0.0.13",
name: "Update Contact",
description: "Add a contact to the root Contacts folder, [See the docs](https://docs.microsoft.com/en-us/graph/api/user-post-contacts)",
props: {
Expand Down
39 changes: 39 additions & 0 deletions components/microsoft_outlook/microsoft_outlook.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,29 @@ export default {
})) || [];
},
},
attachmentId: {
type: "string",
label: "Attachment ID",
description: "The identifier of the attachment to download",
async options({
messageId, page,
}) {
const limit = DEFAULT_LIMIT;
const { value: attachments } = await this.listAttachments({
messageId,
params: {
$top: limit,
$skip: limit * page,
},
});
return attachments?.map(({
id: value, name: label,
}) => ({
value,
label,
})) || [];
},
},
maxResults: {
type: "integer",
label: "Max Results",
Expand Down Expand Up @@ -403,6 +426,22 @@ export default {
...args,
});
},
getAttachment({
messageId, attachmentId, ...args
}) {
return this._makeRequest({
path: `/me/messages/${messageId}/attachments/${attachmentId}/$value`,
...args,
});
},
listAttachments({
messageId, ...args
}) {
return this._makeRequest({
path: `/me/messages/${messageId}/attachments`,
...args,
});
},
async *paginate({
fn, args = {}, max,
}) {
Expand Down
2 changes: 1 addition & 1 deletion components/microsoft_outlook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/microsoft_outlook",
"version": "1.4.1",
"version": "1.5.0",
"description": "Pipedream Microsoft Outlook Components",
"main": "microsoft_outlook.app.mjs",
"keywords": [
Expand Down
58 changes: 58 additions & 0 deletions components/microsoft_outlook/sources/common/common-new-email.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import common from "./common.mjs";

export default {
...common,
props: {
...common.props,
folderIds: {
propDefinition: [
common.props.microsoftOutlook,
"folderIds",
],
optional: true,
},
},
hooks: {
...common.hooks,
async deploy() {
this.db.set("sentItemFolderId", await this.getFolderIdByName("Sent Items"));
this.db.set("draftsFolderId", await this.getFolderIdByName("Drafts"));

const events = await this.getSampleEvents({
pageSize: 25,
});
if (!events || events.length == 0) {
return;
}
for (const item of events) {
this.emitEvent(item);
}
},
async activate() {
await this.activate({
changeType: "created",
resource: "/me/messages",
});
},
async deactivate() {
await this.deactivate();
},
},
methods: {
...common.methods,
async getFolderIdByName(name) {
const { value: folders } = await this.microsoftOutlook.listFolders();
const folder = folders.find(({ displayName }) => displayName === name);
return folder?.id;
},
isRelevant(item) {
if (this.folderIds?.length) {
return this.folderIds.includes(item.parentFolderId);
}
// if no folderIds are specified, filter out items in Sent Items & Drafts
const sentItemFolderId = this.db.get("sentItemFolderId");
const draftsFolderId = this.db.get("draftsFolderId");
return item.parentFolderId !== sentItemFolderId && item.parentFolderId !== draftsFolderId;
},
},
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import microsoftOutlook from "../microsoft_outlook.app.mjs";
import microsoftOutlook from "../../microsoft_outlook.app.mjs";

const getRenewalInterval = (period) => {
let day = 24 * 60 * 60;
Expand Down
Loading