diff --git a/components/freshdesk/actions/assign-ticket-to-agent/assign-ticket-to-agent.mjs b/components/freshdesk/actions/assign-ticket-to-agent/assign-ticket-to-agent.mjs new file mode 100644 index 0000000000000..68e6f0d5bacd1 --- /dev/null +++ b/components/freshdesk/actions/assign-ticket-to-agent/assign-ticket-to-agent.mjs @@ -0,0 +1,41 @@ +import freshdesk from "../../freshdesk.app.mjs"; + +export default { + key: "freshdesk-assign-ticket-to-agent", + name: "Assign Ticket to Agent", + description: "Assign a Freshdesk ticket to a specific agent. [See the documentation](https://developers.freshdesk.com/api/#update_ticket).", + version: "0.0.1", + type: "action", + props: { + freshdesk, + ticketId: { + propDefinition: [ + freshdesk, + "ticketId", + ], + }, + responder_id: { + propDefinition: [ + freshdesk, + "agentId", + ], + }, + }, + async run({ $ }) { + + const ticketName = await this.freshdesk.getTicketName(this.ticketId); + + const response = await this.freshdesk._makeRequest({ + $, + method: "PUT", + url: `/tickets/${this.ticketId}`, + data: { + responder_id: this.responder_id, + }, + }); + $.export("$summary", + `Ticket "${ticketName}" (ID: ${this.ticketId}) assigned to agent ${this.responder_id}`); + + return response; + }, +}; diff --git a/components/freshdesk/actions/assign-ticket-to-group/assign-ticket-to-group.mjs b/components/freshdesk/actions/assign-ticket-to-group/assign-ticket-to-group.mjs new file mode 100644 index 0000000000000..296a24d2f417a --- /dev/null +++ b/components/freshdesk/actions/assign-ticket-to-group/assign-ticket-to-group.mjs @@ -0,0 +1,42 @@ +import freshdesk from "../../freshdesk.app.mjs"; + +export default { + key: "freshdesk-assign-ticket-to-group", + name: "Assign Ticket to Group", + description: "Assign a Freshdesk ticket to a specific group [See the documentation](https://developers.freshdesk.com/api/#update_ticket).", + version: "0.0.1", + type: "action", + props: { + freshdesk, + ticketId: { + propDefinition: [ + freshdesk, + "ticketId", + ], + }, + group_id: { + propDefinition: [ + freshdesk, + "groupId", + ], + }, + }, + async run({ $ }) { + + const ticketName = await this.freshdesk.getTicketName(this.ticketId); + + const response = await this.freshdesk._makeRequest({ + $, + method: "PUT", + url: `/tickets/${this.ticketId}`, + data: { + group_id: this.group_id, + }, + }); + + $.export("$summary", + `Ticket "${ticketName}" (ID: ${this.ticketId}) assigned to group ${this.group_id}`); + + return response; + }, +}; diff --git a/components/freshdesk/actions/close-ticket/close-ticket.mjs b/components/freshdesk/actions/close-ticket/close-ticket.mjs new file mode 100644 index 0000000000000..963260da7b973 --- /dev/null +++ b/components/freshdesk/actions/close-ticket/close-ticket.mjs @@ -0,0 +1,33 @@ +import freshdesk from "../../freshdesk.app.mjs"; + +export default { + key: "freshdesk-close-ticket", + name: "Close Ticket", + description: "Set a Freshdesk ticket's status to 'Closed'. [See docs](https://developers.freshdesk.com/api/#update_a_ticket)", + version: "0.0.1", + type: "action", + props: { + freshdesk, + ticketId: { + propDefinition: [ + freshdesk, + "ticketId", + ], + }, + }, + async run({ $ }) { + const CLOSED_STATUS = 5; // Freshdesk status code for 'Closed' + + const response = await this.freshdesk._makeRequest({ + $, + method: "PUT", + url: `/tickets/${this.ticketId}`, + data: { + status: CLOSED_STATUS, + }, + }); + + $.export("$summary", `Ticket ${this.ticketId} closed successfully`); + return response; + }, +}; diff --git a/components/freshdesk/actions/create-company/create-company.mjs b/components/freshdesk/actions/create-company/create-company.mjs index 2960aec4dc5f1..2763436cc55bb 100644 --- a/components/freshdesk/actions/create-company/create-company.mjs +++ b/components/freshdesk/actions/create-company/create-company.mjs @@ -4,7 +4,7 @@ export default { key: "freshdesk-create-company", name: "Create a Company", description: "Create a company. [See the documentation](https://developers.freshdesk.com/api/#create_company)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { freshdesk, diff --git a/components/freshdesk/actions/create-contact/create-contact.mjs b/components/freshdesk/actions/create-contact/create-contact.mjs index e7a375fc2a6ef..049d0160e740c 100644 --- a/components/freshdesk/actions/create-contact/create-contact.mjs +++ b/components/freshdesk/actions/create-contact/create-contact.mjs @@ -5,7 +5,7 @@ export default { key: "freshdesk-create-contact", name: "Create a Contact", description: "Create a contact. [See the documentation](https://developers.freshdesk.com/api/#create_contact)", - version: "0.0.3", + version: "0.0.4", type: "action", props: { freshdesk, diff --git a/components/freshdesk/actions/create-ticket/create-ticket.mjs b/components/freshdesk/actions/create-ticket/create-ticket.mjs index c505334e4e455..6b562efe43682 100644 --- a/components/freshdesk/actions/create-ticket/create-ticket.mjs +++ b/components/freshdesk/actions/create-ticket/create-ticket.mjs @@ -4,7 +4,7 @@ export default { key: "freshdesk-create-ticket", name: "Create a Ticket", description: "Create a ticket. [See the documentation](https://developers.freshdesk.com/api/#create_ticket)", - version: "0.0.4", + version: "0.0.5", type: "action", props: { freshdesk, diff --git a/components/freshdesk/actions/get-ticket/get-ticket.mjs b/components/freshdesk/actions/get-ticket/get-ticket.mjs index 18837769a396f..6769ba87c5975 100644 --- a/components/freshdesk/actions/get-ticket/get-ticket.mjs +++ b/components/freshdesk/actions/get-ticket/get-ticket.mjs @@ -4,7 +4,7 @@ export default { key: "freshdesk-get-ticket", name: "Get Ticket Details", description: "Get details of a Ticket. [See the documentation](https://developers.freshdesk.com/api/#view_a_ticket)", - version: "0.1.1", + version: "0.1.2", type: "action", props: { freshdesk, diff --git a/components/freshdesk/actions/list-all-tickets/list-all-tickets.mjs b/components/freshdesk/actions/list-all-tickets/list-all-tickets.mjs index 8c9060b92517d..13a0896a1316d 100644 --- a/components/freshdesk/actions/list-all-tickets/list-all-tickets.mjs +++ b/components/freshdesk/actions/list-all-tickets/list-all-tickets.mjs @@ -5,7 +5,7 @@ export default { name: "List Tickets", description: "Fetch up to 100 tickets according to the selected filters. [See the documentation](https://developers.freshdesk.com/api/#list_all_tickets)", - version: "0.2.1", + version: "0.2.2", type: "action", props: { freshdesk, diff --git a/components/freshdesk/actions/set-ticket-priority/set-ticket-priority.mjs b/components/freshdesk/actions/set-ticket-priority/set-ticket-priority.mjs new file mode 100644 index 0000000000000..6790ef691a8b9 --- /dev/null +++ b/components/freshdesk/actions/set-ticket-priority/set-ticket-priority.mjs @@ -0,0 +1,51 @@ +import freshdesk from "../../freshdesk.app.mjs"; + +export default { + key: "freshdesk-set-ticket-priority", + name: "Set Ticket Priority", + description: "Update the priority of a ticket in Freshdesk [See the documentation](https://developers.freshdesk.com/api/#update_ticket).", + version: "0.0.1", + type: "action", + props: { + freshdesk, + ticketId: { + propDefinition: [ + freshdesk, + "ticketId", + ], + }, + ticketPriority: { + propDefinition: [ + freshdesk, + "ticketPriority", + ], + }, + }, + async run({ $ }) { + + const ticketName = await this.freshdesk.getTicketName(this.ticketId); + + const response = await this.freshdesk._makeRequest({ + $, + method: "PUT", + url: `/tickets/${this.ticketId}`, + data: { + priority: this.ticketPriority, + }, + }); + + const priorityLabels = { + 1: "Low", + 2: "Medium", + 3: "High", + 4: "Urgent", + }; + + const priorityLabel = priorityLabels[this.ticketPriority] || this.ticketPriority; + + $.export("$summary", + `Ticket ${ticketName} (ID: ${this.ticketId}) priority updated to "${priorityLabel}".`); + + return response; + }, +}; diff --git a/components/freshdesk/actions/set-ticket-status/set-ticket-status.mjs b/components/freshdesk/actions/set-ticket-status/set-ticket-status.mjs new file mode 100644 index 0000000000000..0a94f28e9c0cb --- /dev/null +++ b/components/freshdesk/actions/set-ticket-status/set-ticket-status.mjs @@ -0,0 +1,53 @@ +import freshdesk from "../../freshdesk.app.mjs"; + +export default { + key: "freshdesk-set-ticket-status", + name: "Set Ticket Status", + description: "Update the status of a ticket in Freshdesk [See the documentation](https://developers.freshdesk.com/api/#update_ticket).", + version: "0.0.1", + type: "action", + props: { + freshdesk, + ticketId: { + propDefinition: [ + freshdesk, + "ticketId", + ], + }, + ticketStatus: { + propDefinition: [ + freshdesk, + "ticketStatus", + ], + }, + }, + async run({ $ }) { + + const ticketName = await this.freshdesk.getTicketName(this.ticketId); + + const response = await this.freshdesk._makeRequest({ + $, + method: "PUT", + url: `/tickets/${this.ticketId}`, + data: { + status: this.ticketStatus, + }, + }); + + const statusLabels = { + 2: "Open", + 3: "Pending", + 4: "Resolved", + 5: "Closed", + }; + + const statusLabel = statusLabels[this.ticketStatus] || this.ticketStatus; + + $.export( + "$summary", + `Ticket "${ticketName}" (ID: ${this.ticketId}) status updated to "${statusLabel}".`, + ); + + return response; + }, +}; diff --git a/components/freshdesk/actions/update-ticket/update-ticket.mjs b/components/freshdesk/actions/update-ticket/update-ticket.mjs new file mode 100644 index 0000000000000..f1dd5c8c1e7df --- /dev/null +++ b/components/freshdesk/actions/update-ticket/update-ticket.mjs @@ -0,0 +1,122 @@ +import freshdesk from "../../freshdesk.app.mjs"; +import { removeNullEntries } from "../../common/utils.mjs"; + +export default { + key: "freshdesk-update-ticket", + name: "Update a Ticket", + description: "Update status, priority, subject, description, agent, group, etc. [See the documentation](https://developers.freshdesk.com/api/#update_ticket).", + version: "0.0.1", + type: "action", + props: { + freshdesk, + ticketId: { + propDefinition: [ + freshdesk, + "ticketId", + ], + }, + status: { + propDefinition: [ + freshdesk, + "ticketStatus", + ], + optional: true, + }, + priority: { + propDefinition: [ + freshdesk, + "ticketPriority", + ], + optional: true, + }, + subject: { + type: "string", + label: "Subject", + description: "Ticket subject", + optional: true, + }, + description: { + type: "string", + label: "Description", + description: "Detailed ticket description (HTML allowed)", + optional: true, + }, + group_id: { + propDefinition: [ + freshdesk, + "groupId", + ], + }, + responder_id: { + propDefinition: [ + freshdesk, + "agentId", + ], + }, + email: { + type: "string", + label: "Requester Email (replaces requester)", + description: "Updates the requester. If no contact with this email exists, a new one will be created and assigned to the ticket.", + optional: true, + }, + phone: { + type: "string", + label: "Requester Phone (replaces requester)", + description: "If no contact with this phone number exists, a new one will be created. If used without email, 'name' is required.", + optional: true, + }, + name: { + type: "string", + label: "Requester Name (required with phone if no email)", + description: "Used when creating a contact with phone but no email.", + optional: true, + }, + type: { + type: "string", + label: "Type", + description: "Type of ticket (must match one of the allowed values)", + optional: true, + options: [ + "Question", + "Incident", + "Problem", + "Feature Request", + "Refund", + ], + }, + custom_fields: { + type: "object", + label: "Custom Fields", + description: "Custom fields as key-value pairs (make sure types match your config)", + optional: true, + }, + }, + async run({ $ }) { + const { + freshdesk, + ticketId, + ...fields + } = this; + + const data = removeNullEntries(fields); + + const ticketName = await freshdesk.getTicketName(ticketId); + + if (!Object.keys(data).length) { + throw new Error("Please provide at least one field to update."); + } + + if (data.custom_fields) freshdesk.parseIfJSONString(data.custom_fields); + + const response = await freshdesk._makeRequest({ + $, + method: "PUT", + url: `/tickets/${ticketId}`, + data, + }); + + $.export("$summary", `Ticket "${ticketName}" (ID: ${this.ticketId}) updated successfully`); + return response; + }, +}; + diff --git a/components/freshdesk/freshdesk.app.mjs b/components/freshdesk/freshdesk.app.mjs index d60c43eff58af..fe405b1c37151 100644 --- a/components/freshdesk/freshdesk.app.mjs +++ b/components/freshdesk/freshdesk.app.mjs @@ -19,6 +19,7 @@ export default { })); }, }, + ticketId: { type: "integer", label: "Ticket ID", @@ -37,6 +38,48 @@ export default { })); }, }, + agentId: { + type: "integer", + label: "Agent", + description: "Select an agent to assign the ticket to", + async options({ page = 0 }) { + const response = await this._makeRequest({ + method: "GET", + url: "/agents", + params: { + page: page + 1, + }, + }); + + return response.map((agent) => ({ + label: agent.contact?.name + ? `${agent.contact.name} (${agent.contact.email || "No email"})` + : `Agent ${agent.id}`, + value: agent.id, + })); + }, + }, + groupId: { + type: "integer", + label: "Group", + description: "Select a group to assign the ticket to.", + async options({ page = 0 }) { + const groups = await this._makeRequest({ + method: "GET", + url: "/groups", + params: { + page: page + 1, + per_page: 100, + }, + }); + + return groups.map((group) => ({ + label: group.name || `Group ${group.id}`, + value: group.id, + })); + }, + }, + ticketStatus: { type: "integer", label: "Status", @@ -207,5 +250,21 @@ export default { ...args, }); }, + async getTicketName(ticketId) { + const ticket = await this.getTicket({ + ticketId, + }); + return ticket.subject; + }, + parseIfJSONString(input) { + if (typeof input === "string") { + try { + return JSON.parse(input); + } catch (error) { + return input; + } + } + return input; + }, }, }; diff --git a/components/freshdesk/package.json b/components/freshdesk/package.json index 1128b1f775f3e..5b58e05dcd799 100644 --- a/components/freshdesk/package.json +++ b/components/freshdesk/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/freshdesk", - "version": "0.1.1", + "version": "0.2.0", "description": "Pipedream Freshdesk Components", "main": "freshdesk.app.mjs", "keywords": [ diff --git a/components/freshdesk/sources/new-contact/new-contact.mjs b/components/freshdesk/sources/new-contact/new-contact.mjs index bfd2f40aab89d..aa3e485eb8baa 100644 --- a/components/freshdesk/sources/new-contact/new-contact.mjs +++ b/components/freshdesk/sources/new-contact/new-contact.mjs @@ -6,7 +6,7 @@ export default { key: "freshdesk-new-contact", name: "New Contact Created", description: "Emit new event when a contact is created. [See the documentation](https://developers.freshdesk.com/api/#filter_contacts)", - version: "0.0.4", + version: "0.0.5", type: "source", props: { freshdesk, diff --git a/components/freshdesk/sources/new-ticket/new-ticket.mjs b/components/freshdesk/sources/new-ticket/new-ticket.mjs index 1f910b1786cc4..8af71af64fff3 100644 --- a/components/freshdesk/sources/new-ticket/new-ticket.mjs +++ b/components/freshdesk/sources/new-ticket/new-ticket.mjs @@ -6,7 +6,7 @@ export default { key: "freshdesk-new-ticket", name: "New Ticket Created", description: "Emit new event when a ticket is created. [See the documentation](https://developers.freshdesk.com/api/#filter_tickets)", - version: "0.0.4", + version: "0.0.5", type: "source", props: { freshdesk, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1a8d77d88c2c2..eee1fc6916b83 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2864,8 +2864,7 @@ importers: specifier: ^4.17.21 version: 4.17.21 - components/consulta_unica: - specifiers: {} + components/consulta_unica: {} components/contact_enhance: dependencies: