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
36 changes: 33 additions & 3 deletions components/zendesk/actions/update-ticket/update-ticket.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import app from "../../zendesk.app.mjs";
export default {
key: "zendesk-update-ticket",
name: "Update Ticket",
description: "Updates a ticket. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#update-ticket).",
description: "Updates a ticket with optional file attachments. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#update-ticket).",
type: "action",
version: "0.1.4",
version: "0.2.0",
props: {
app,
ticketId: {
Expand Down Expand Up @@ -56,6 +56,12 @@ export default {
"customSubdomain",
],
},
attachments: {
propDefinition: [
app,
"attachments",
],
},
},
methods: {
updateTicket({
Expand All @@ -77,6 +83,7 @@ export default {
ticketStatus,
ticketCommentPublic,
customSubdomain,
attachments,
} = this;

const ticketComment = ticketCommentBodyIsHTML
Expand All @@ -89,6 +96,24 @@ export default {

ticketComment.public = ticketCommentPublic;

// Upload attachments if provided
if (attachments && attachments.length > 0) {
try {
const uploadTokens = await this.app.uploadFiles({
attachments,
customSubdomain,
step,
});

if (uploadTokens.length > 0) {
ticketComment.uploads = uploadTokens;
}
} catch (error) {
step.export("$summary", `Failed to upload attachments: ${error.message}`);
throw error;
}
}

const response = await this.updateTicket({
step,
ticketId,
Expand All @@ -103,7 +128,12 @@ export default {
},
});

step.export("$summary", `Successfully updated ticket with ID ${response.ticket.id}`);
const attachmentCount = attachments?.length || 0;
const summary = attachmentCount > 0
? `Successfully updated ticket with ID ${response.ticket.id} with ${attachmentCount} attachment(s)`
: `Successfully updated ticket with ID ${response.ticket.id}`;

step.export("$summary", summary);

return response;
},
Expand Down
2 changes: 1 addition & 1 deletion components/zendesk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/zendesk",
"version": "0.7.1",
"version": "0.7.2",
"description": "Pipedream Zendesk Components",
"main": "zendesk.app.mjs",
"keywords": [
Expand Down
71 changes: 71 additions & 0 deletions components/zendesk/zendesk.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ export default {
description: "For Enterprise Zendesk accounts: optionally specify the subdomain to use. This will override the subdomain that was provided when connecting your Zendesk account to Pipedream. For example, if you Zendesk URL is https://examplehelp.zendesk.com, your subdomain is `examplehelp`",
optional: true,
},
attachments: {
type: "string[]",
label: "Attachments",
description: "File paths or URLs to attach to the ticket. Multiple files can be attached.",
optional: true,
},
},
methods: {
getUrl(path, customSubdomain) {
Expand Down Expand Up @@ -284,6 +290,71 @@ export default {
...args,
});
},
async uploadFile({
filePath, filename, customSubdomain, step,
} = {}) {
const fs = await import("fs");
const path = await import("path");

// If filename not provided, extract from filePath
if (!filename && filePath) {
filename = path.basename(filePath);
}

// Read file content
const fileContent = fs.readFileSync(filePath);

// Get file extension to determine Content-Type
const ext = path.extname(filename).toLowerCase();
const contentTypeMap = {
".pdf": "application/pdf",
".png": "image/png",
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".gif": "image/gif",
".txt": "text/plain",
".doc": "application/msword",
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
".xls": "application/vnd.ms-excel",
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
".zip": "application/zip",
};
const contentType = contentTypeMap[ext] || "application/octet-stream";

return this.makeRequest({
step,
method: "post",
path: `/uploads?filename=${encodeURIComponent(filename)}`,
customSubdomain,
headers: {
"Content-Type": contentType,
},
data: fileContent,
});
},
async uploadFiles({
attachments, customSubdomain, step,
} = {}) {
if (!attachments || !attachments.length) {
return [];
}

const uploadResults = [];
for (const attachment of attachments) {
try {
const result = await this.uploadFile({
filePath: attachment,
customSubdomain,
step,
});
uploadResults.push(result.upload.token);
} catch (error) {
step.export("$summary", `Failed to upload file ${attachment}: ${error.message}`);
throw error;
}
}
return uploadResults;
},
async *paginate({
fn, args, resourceKey, max,
}) {
Expand Down