Skip to content

Freshdesk - add support for notes #17598

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

Merged
merged 10 commits into from
Jul 21, 2025
Merged
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
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Address the either/or behavior limitation and validation gap.

The current implementation has two design issues:

  1. Either/or limitation: Users can either add an internal note OR update ticket fields, but not both in the same action call. This may not meet user expectations.

  2. Validation gap: If internalNote is true but noteBody is empty/falsy, the function proceeds to regular update logic, potentially throwing a confusing "Please provide at least one field to update" error.

Consider these improvements:

Option 1: Allow both operations in sequence

 if (internalNote && noteBody) {
-  const response = await freshdesk._makeRequest({
+  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 (internalNote && !noteBody) {
+   throw new Error("Note Body is required when Internal note is enabled.");
 }

Option 2: Add validation for the either/or scenario

+ if (internalNote && !noteBody) {
+   throw new Error("Note Body is required when Internal note is enabled.");
+ }
+ 
 if (internalNote && noteBody) {
   // existing logic
 }
📝 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 (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 (internalNote && noteBody) {
await freshdesk._makeRequest({
$,
method: "POST",
url: `/tickets/${ticketId}/notes`,
data: {
body: noteBody,
private: true,
},
});
}
if (internalNote && !noteBody) {
throw new Error("Note Body is required when Internal note is enabled.");
}
🤖 Prompt for AI Agents
In components/freshdesk/actions/update-ticket/update-ticket.mjs around lines 120
to 133, the code currently only allows adding an internal note or updating
ticket fields, not both, and lacks validation when internalNote is true but
noteBody is empty. To fix this, modify the logic to support performing both
actions sequentially if both internalNote and ticket updates are provided, or
alternatively, add validation to check if internalNote is true but noteBody is
missing and return a clear error before proceeding. This ensures users can
update tickets and add notes in one call or receive proper feedback if required
inputs are missing.


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

}