From 2ee9753d851cab08acd1a9c276df2bc88d497729 Mon Sep 17 00:00:00 2001 From: seynadio <79858321+seynadio@users.noreply.github.com> Date: Mon, 14 Jul 2025 13:39:07 +0200 Subject: [PATCH] Add internal notes support to Trengo integration - Add createInternalNote method to Trengo app with JSDoc documentation - Create dedicated create-internal-note action for adding notes to tickets - Enhance send-a-message action with createInternalNote option and proper validation - Update package version to 0.1.1 - Leverage existing new-internal-note webhook source for notifications --- .../create-internal-note.mjs | 37 ++++++++++++ .../actions/send-a-message/send-a-message.mjs | 58 ++++++++++++++----- components/trengo/package.json | 2 +- components/trengo/trengo.app.mjs | 12 ++++ 4 files changed, 95 insertions(+), 14 deletions(-) create mode 100644 components/trengo/actions/create-internal-note/create-internal-note.mjs diff --git a/components/trengo/actions/create-internal-note/create-internal-note.mjs b/components/trengo/actions/create-internal-note/create-internal-note.mjs new file mode 100644 index 0000000000000..c6783ac5b0b72 --- /dev/null +++ b/components/trengo/actions/create-internal-note/create-internal-note.mjs @@ -0,0 +1,37 @@ +import app from "../../trengo.app.mjs"; + +export default { + type: "action", + key: "trengo-create-internal-note", + version: "0.0.1", + name: "Create Internal Note", + description: "Create an internal note on a ticket that is only visible to team members. [See the docs](https://developers.trengo.com/reference/create-internal-note)", + props: { + app, + ticketId: { + propDefinition: [ + app, + "ticketId", + ], + }, + note: { + propDefinition: [ + app, + "note", + ], + optional: false, + description: "The internal note content that will be added to the ticket.", + }, + }, + async run({ $ }) { + const resp = await this.app.createInternalNote({ + $, + data: { + ticket_id: this.ticketId, + note: this.note, + }, + }); + $.export("$summary", `Successfully created internal note on ticket ${this.ticketId}`); + return resp; + }, +}; \ No newline at end of file diff --git a/components/trengo/actions/send-a-message/send-a-message.mjs b/components/trengo/actions/send-a-message/send-a-message.mjs index f91922ad67cbc..e6f68f44c7f31 100644 --- a/components/trengo/actions/send-a-message/send-a-message.mjs +++ b/components/trengo/actions/send-a-message/send-a-message.mjs @@ -3,7 +3,7 @@ import app from "../../trengo.app.mjs"; export default { type: "action", key: "trengo-send-a-message", - version: "0.0.2", + version: "0.0.3", name: "Send A Message", description: "This action can be used to easily send a message or an email without having to think about contacts or tickets, [See the docs](https://developers.trengo.com/reference/send-a-message-1)", props: { @@ -40,19 +40,51 @@ export default { "emailSubject", ], }, + createInternalNote: { + type: "boolean", + label: "Create Internal Note", + description: "Create an internal note instead of sending a message to the contact (requires ticket ID)", + optional: true, + default: false, + }, + ticketId: { + propDefinition: [ + app, + "ticketId", + ], + description: "Required when creating an internal note", + optional: true, + }, }, async run ({ $ }) { - const resp = await this.app.sendMessage({ - $, - data: { - channel_id: this.channelId, - contact_identifier: this.contactIdentifier, - contact_name: this.contactName, - message: this.message, - email_subject: this.emailSubject, - }, - }); - $.export("$summary", "The message has been sent"); - return resp; + if (this.createInternalNote) { + if (!this.ticketId) { + throw new Error("Ticket ID is required when creating an internal note"); + } + // Create internal note instead of sending message + const resp = await this.app.createInternalNote({ + $, + data: { + ticket_id: this.ticketId, + note: this.message, + }, + }); + $.export("$summary", `Internal note created on ticket ${this.ticketId}`); + return resp; + } else { + // Send regular message + const resp = await this.app.sendMessage({ + $, + data: { + channel_id: this.channelId, + contact_identifier: this.contactIdentifier, + contact_name: this.contactName, + message: this.message, + email_subject: this.emailSubject, + }, + }); + $.export("$summary", "The message has been sent"); + return resp; + } }, }; diff --git a/components/trengo/package.json b/components/trengo/package.json index f5c320c6d33ab..34720ef0aaa66 100644 --- a/components/trengo/package.json +++ b/components/trengo/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/trengo", - "version": "0.1.0", + "version": "0.1.1", "description": "Pipedream Trengo Components", "main": "trengo.app.mjs", "keywords": [ diff --git a/components/trengo/trengo.app.mjs b/components/trengo/trengo.app.mjs index d7f4019a1e73b..2933964e2146e 100644 --- a/components/trengo/trengo.app.mjs +++ b/components/trengo/trengo.app.mjs @@ -241,5 +241,17 @@ export default { ...args, }); }, + /** + * Create an internal note on a ticket + * @param {object} args - Request arguments + * @returns {object} Response from Trengo API + */ + async createInternalNote(args = {}) { + return this._makeRequest({ + method: "POST", + path: "/tickets/notes", + ...args, + }); + }, }, };