|
| 1 | +import freshdesk from "../../freshdesk.app.mjs"; |
| 2 | +import { ConfigurationError } from "@pipedream/platform"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "freshdesk-add-note-to-ticket", |
| 6 | + name: "Add Note to Ticket", |
| 7 | + description: "Add a note or conversation to an existing ticket. [See the documentation](https://developers.freshdesk.com/api/#add_note_to_a_ticket).", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + props: { |
| 11 | + freshdesk, |
| 12 | + ticketId: { |
| 13 | + propDefinition: [ |
| 14 | + freshdesk, |
| 15 | + "ticketId", |
| 16 | + ], |
| 17 | + }, |
| 18 | + body: { |
| 19 | + type: "string", |
| 20 | + label: "Note Body", |
| 21 | + description: "Content of the note in HTML format", |
| 22 | + }, |
| 23 | + private: { |
| 24 | + type: "boolean", |
| 25 | + label: "Private Note", |
| 26 | + description: "Set to true if the note is private (internal)", |
| 27 | + default: false, |
| 28 | + }, |
| 29 | + incoming: { |
| 30 | + type: "boolean", |
| 31 | + label: "Incoming", |
| 32 | + description: "Set to true if the note should be marked as incoming (false for outgoing)", |
| 33 | + default: false, |
| 34 | + optional: true, |
| 35 | + }, |
| 36 | + user_id: { |
| 37 | + propDefinition: [ |
| 38 | + freshdesk, |
| 39 | + "agentId", |
| 40 | + ], |
| 41 | + label: "User ID", |
| 42 | + description: "ID of the user creating the note (defaults to the API user)", |
| 43 | + optional: true, |
| 44 | + }, |
| 45 | + notify_emails: { |
| 46 | + type: "string[]", |
| 47 | + label: "Notify Emails", |
| 48 | + description: "Array of email addresses to notify about this note", |
| 49 | + optional: true, |
| 50 | + }, |
| 51 | + }, |
| 52 | + async run({ $ }) { |
| 53 | + const { |
| 54 | + freshdesk, |
| 55 | + ticketId, |
| 56 | + body, |
| 57 | + private: isPrivate, |
| 58 | + incoming, |
| 59 | + user_id, |
| 60 | + notify_emails, |
| 61 | + } = this; |
| 62 | + |
| 63 | + if (!body || !body.trim()) { |
| 64 | + throw new ConfigurationError("Note body cannot be empty"); |
| 65 | + } |
| 66 | + |
| 67 | + const ticketName = await freshdesk.getTicketName(ticketId); |
| 68 | + |
| 69 | + const data = { |
| 70 | + body, |
| 71 | + private: isPrivate, |
| 72 | + }; |
| 73 | + |
| 74 | + if (incoming !== undefined) { |
| 75 | + data.incoming = incoming; |
| 76 | + } |
| 77 | + |
| 78 | + if (user_id) { |
| 79 | + data.user_id = Number(user_id); |
| 80 | + } |
| 81 | + |
| 82 | + if (notify_emails && notify_emails.length > 0) { |
| 83 | + data.notify_emails = notify_emails; |
| 84 | + } |
| 85 | + |
| 86 | + const response = await freshdesk.addNoteToTicket({ |
| 87 | + $, |
| 88 | + ticketId: Number(ticketId), |
| 89 | + data, |
| 90 | + }); |
| 91 | + |
| 92 | + $.export("$summary", `Note added to ticket "${ticketName}" (ID: ${ticketId})`); |
| 93 | + return response; |
| 94 | + }, |
| 95 | +}; |
0 commit comments