UNPKG

@pipedream/microsoft_outlook

Version:

Pipedream Microsoft Outlook Components

61 lines (57 loc) 1.67 kB
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.3", 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", }, syncDir: { type: "dir", accessMode: "write", sync: true, }, }, 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, }; }, };