File tree Expand file tree Collapse file tree 2 files changed +74
-1
lines changed
actions/download-attachment Expand file tree Collapse file tree 2 files changed +74
-1
lines changed Original file line number Diff line number Diff line change 1+ import freshdesk from "../../freshdesk.app.mjs" ;
2+ import { axios } from "@pipedream/platform" ;
3+ import fs from "fs" ;
4+
5+ export default {
6+ key : "freshdesk-download-attachment" ,
7+ name : "Download Attachment" ,
8+ description : "Download an attachment from a ticket. [See the documentation](https://developers.freshdesk.com/api/#view_a_ticket)" ,
9+ version : "0.0.1" ,
10+ type : "action" ,
11+ props : {
12+ freshdesk,
13+ ticketId : {
14+ propDefinition : [
15+ freshdesk ,
16+ "ticketId" ,
17+ ] ,
18+ } ,
19+ attachmentId : {
20+ type : "integer" ,
21+ label : "Attachment ID" ,
22+ description : "The ID of the attachment to download" ,
23+ async options ( ) {
24+ const attachments = await this . listTicketAttachments ( ) ;
25+ return attachments . map ( ( {
26+ id, name,
27+ } ) => ( {
28+ value : id ,
29+ label : name ,
30+ } ) ) ;
31+ } ,
32+ } ,
33+ syncDir : {
34+ type : "dir" ,
35+ accessMode : "write" ,
36+ sync : true ,
37+ } ,
38+ } ,
39+ methods : {
40+ async listTicketAttachments ( opts = { } ) {
41+ const { attachments } = await this . freshdesk . getTicket ( {
42+ ticketId : this . ticketId ,
43+ ...opts ,
44+ } ) ;
45+ return attachments ;
46+ } ,
47+ } ,
48+ async run ( { $ } ) {
49+ const attachments = await this . listTicketAttachments ( {
50+ $,
51+ } ) ;
52+ const attachment = attachments . find ( ( { id } ) => id === this . attachmentId ) ;
53+
54+ const response = await axios ( $ , {
55+ url : attachment . attachment_url ,
56+ responseType : "arraybuffer" ,
57+ } ) ;
58+
59+ const buffer = Buffer . from ( response ) ;
60+ const downloadedFilepath = `/tmp/${ attachment . name } ` ;
61+ fs . writeFileSync ( downloadedFilepath , buffer ) ;
62+
63+ const filedata = [
64+ attachment . name ,
65+ downloadedFilepath ,
66+ ] ;
67+
68+ return {
69+ filedata,
70+ attachment,
71+ } ;
72+ } ,
73+ } ;
Original file line number Diff line number Diff line change 11{
22 "name" : " @pipedream/freshdesk" ,
3- "version" : " 0.4 .0" ,
3+ "version" : " 0.5 .0" ,
44 "description" : " Pipedream Freshdesk Components" ,
55 "main" : " freshdesk.app.mjs" ,
66 "keywords" : [
You can’t perform that action at this time.
0 commit comments