Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -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,
};
},
};
2 changes: 1 addition & 1 deletion components/freshdesk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/freshdesk",
"version": "0.4.0",
"version": "0.5.0",
"description": "Pipedream Freshdesk Components",
"main": "freshdesk.app.mjs",
"keywords": [
Expand Down
Loading