Skip to content

Trengo internal notes #17600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
41 changes: 35 additions & 6 deletions components/freshdesk/actions/update-ticket/update-ticket.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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",
version: "0.0.2",
type: "action",
props: {
freshdesk,
Expand Down Expand Up @@ -71,6 +71,19 @@ export default {
description: "Used when creating a contact with phone but no email.",
optional: true,
},
internalNote: {
type: "boolean",
label: "Internal note (private)",
description: "If enabled, the comment will be added as an internal note (not visible to requester).",
optional: true,
default: false,
},
noteBody: {
type: "string",
label: "Note Body",
description: "The content of the internal note to add.",
optional: true,
},
type: {
type: "string",
label: "Type",
Expand All @@ -95,28 +108,44 @@ export default {
const {
freshdesk,
ticketId,
internalNote,
noteBody,
...fields
} = this;

const data = removeNullEntries(fields);

const ticketName = await freshdesk.getTicketName(ticketId);

if (internalNote && noteBody) {
const response = await freshdesk._makeRequest({
$,
method: "POST",
url: `/tickets/${ticketId}/notes`,
data: {
body: noteBody,
private: true,
},
});

$.export("$summary", `Internal note added to ticket "${ticketName}" (ID: ${ticketId})`);
return response;
}

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;
},
};

}
Original file line number Diff line number Diff line change
@@ -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;
},
};
52 changes: 39 additions & 13 deletions components/trengo/actions/send-a-message/send-a-message.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -40,19 +40,45 @@ export default {
"emailSubject",
],
},
createInternalNote: {
type: "boolean",
label: "Create Internal Note",
description: "Create an internal note instead of sending a message to the contact",
optional: true,
default: false,
},
},
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) {
// Create internal note instead of sending message
const resp = await this.app.createInternalNote({
$,
data: {
note: this.message,
// Internal notes might need additional context
metadata: {
channel_id: this.channelId,
contact_identifier: this.contactIdentifier,
contact_name: this.contactName,
},
},
});
$.export("$summary", "Internal note has been created");
return resp;
} else {
Comment on lines +52 to +68
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical: Missing ticket_id for internal note creation.

Internal notes must be associated with a ticket, but no ticket_id is being passed to the createInternalNote method. This will likely cause API errors since the /tickets/notes endpoint requires knowing which ticket to attach the note to.

Additionally, the metadata structure being passed is inconsistent with the dedicated create-internal-note action which only passes ticket_id and note.

Consider one of these solutions:

  1. Add a ticketId prop to this action when createInternalNote is true
  2. Remove the internal note functionality from this action since it's better handled by the dedicated create-internal-note action
  3. Clarify the API requirements for the /tickets/notes endpoint
 data: {
+  ticket_id: this.ticketId, // Add this prop to the action
   note: this.message,
-  // Internal notes might need additional context
-  metadata: {
-    channel_id: this.channelId,
-    contact_identifier: this.contactIdentifier,
-    contact_name: this.contactName,
-  },
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (this.createInternalNote) {
// Create internal note instead of sending message
const resp = await this.app.createInternalNote({
$,
data: {
note: this.message,
// Internal notes might need additional context
metadata: {
channel_id: this.channelId,
contact_identifier: this.contactIdentifier,
contact_name: this.contactName,
},
},
});
$.export("$summary", "Internal note has been created");
return resp;
} else {
if (this.createInternalNote) {
// Create internal note instead of sending message
const resp = await this.app.createInternalNote({
$,
data: {
ticket_id: this.ticketId, // Add this prop to the action
note: this.message,
},
});
$.export("$summary", "Internal note has been created");
return resp;
} else {
🤖 Prompt for AI Agents
In components/trengo/actions/send-a-message/send-a-message.mjs around lines 52
to 68, the internal note creation is missing the required ticket_id parameter,
which is necessary for associating the note with a ticket and avoiding API
errors. To fix this, add a ticketId property to the action and include it in the
data passed to createInternalNote, ensuring the payload matches the expected
structure of the dedicated create-internal-note action by passing only ticket_id
and note. Alternatively, consider removing the internal note functionality from
this action if it is better handled separately.

// 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;
}
},
};
2 changes: 1 addition & 1 deletion components/trengo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/trengo",
"version": "0.1.0",
"version": "0.1.1",
"description": "Pipedream Trengo Components",
"main": "trengo.app.mjs",
"keywords": [
Expand Down
7 changes: 7 additions & 0 deletions components/trengo/trengo.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,12 @@ export default {
...args,
});
},
async createInternalNote(args = {}) {
return this._makeRequest({
method: "POST",
path: "/tickets/notes",
...args,
});
},
},
};