From 7cb15c973ae1f9a6b71fb097b02ebb9209d41a5e Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Tue, 30 Sep 2025 12:29:12 -0400 Subject: [PATCH 1/2] download-attachment --- .../download-attachment.mjs | 74 +++++++++++++++++++ components/freshdesk/package.json | 2 +- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 components/freshdesk/actions/download-attachment/download-attachment.mjs diff --git a/components/freshdesk/actions/download-attachment/download-attachment.mjs b/components/freshdesk/actions/download-attachment/download-attachment.mjs new file mode 100644 index 0000000000000..71ff17b5934de --- /dev/null +++ b/components/freshdesk/actions/download-attachment/download-attachment.mjs @@ -0,0 +1,74 @@ +import freshdesk from "../../freshdesk.app.mjs"; +import { axios } from "@pipedream/platform"; +import fs from "fs"; + +export default { + key: "freshdesk-download-attachment", + name: "Download Attachment", + description: "Download an attachment from a ticket. [See the documentation](https://developers.freshdesk.com/api/#view_a_ticket)", + version: "0.0.1", + type: "action", + props: { + freshdesk, + ticketId: { + propDefinition: [ + freshdesk, + "ticketId", + ], + }, + attachmentId: { + type: "integer", + label: "Attachment ID", + description: "The ID of the attachment to download", + async options() { + const attachments = await this.listTicketAttachments(); + return attachments.map(({ + id, name, + }) => ({ + value: id, + label: name, + })); + }, + }, + syncDir: { + type: "dir", + accessMode: "write", + sync: true, + }, + }, + methods: { + async listTicketAttachments(opts = {}) { + const { attachments } = await this.freshdesk.getTicket({ + ticketId: this.ticketId, + ...opts, + }); + return attachments; + }, + }, + async run({ $ }) { + const attachments = await this.listTicketAttachments({ + $, + }); + const attachment = attachments.find(({ id }) => id === this.attachmentId); + + const resppnse = await axios($, { + url: attachment.attachment_url, + responseType: "arraybuffer", + }); + + const rawcontent = resppnse.toString("base64"); + const buffer = Buffer.from(rawcontent, "base64"); + const downloadedFilepath = `/tmp/${attachment.name}`; + fs.writeFileSync(downloadedFilepath, buffer); + + const filedata = [ + attachment.name, + downloadedFilepath, + ]; + + return { + filedata, + attachment, + }; + }, +}; diff --git a/components/freshdesk/package.json b/components/freshdesk/package.json index a37abb1407f9a..6189aa3119732 100644 --- a/components/freshdesk/package.json +++ b/components/freshdesk/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/freshdesk", - "version": "0.4.0", + "version": "0.5.0", "description": "Pipedream Freshdesk Components", "main": "freshdesk.app.mjs", "keywords": [ From 5718d79b6b85e05bb832e33f3de6d4ab8855c77c Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Tue, 30 Sep 2025 12:41:15 -0400 Subject: [PATCH 2/2] updates --- .../actions/download-attachment/download-attachment.mjs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/components/freshdesk/actions/download-attachment/download-attachment.mjs b/components/freshdesk/actions/download-attachment/download-attachment.mjs index 71ff17b5934de..e6b78803b51b5 100644 --- a/components/freshdesk/actions/download-attachment/download-attachment.mjs +++ b/components/freshdesk/actions/download-attachment/download-attachment.mjs @@ -51,13 +51,12 @@ export default { }); const attachment = attachments.find(({ id }) => id === this.attachmentId); - const resppnse = await axios($, { + const response = await axios($, { url: attachment.attachment_url, responseType: "arraybuffer", }); - const rawcontent = resppnse.toString("base64"); - const buffer = Buffer.from(rawcontent, "base64"); + const buffer = Buffer.from(response); const downloadedFilepath = `/tmp/${attachment.name}`; fs.writeFileSync(downloadedFilepath, buffer);