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
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import freshdesk from "../../freshdesk.app.mjs";
import { ConfigurationError } from "@pipedream/platform";

export default {
key: "freshdesk-add-note-to-ticket",
name: "Add Note to Ticket",
description: "Add a note or conversation to an existing ticket. [See the documentation](https://developers.freshdesk.com/api/#add_note_to_a_ticket).",
version: "0.0.1",
type: "action",
props: {
freshdesk,
ticketId: {
propDefinition: [
freshdesk,
"ticketId",
],
},
body: {
type: "string",
label: "Note Body",
description: "Content of the note in HTML format",
},
private: {
type: "boolean",
label: "Private Note",
description: "Set to true if the note is private (internal)",
default: false,
},
incoming: {
type: "boolean",
label: "Incoming",
description: "Set to true if the note should be marked as incoming (false for outgoing)",
default: false,
optional: true,
},
user_id: {
propDefinition: [
freshdesk,
"agentId",
],
label: "User ID",
description: "ID of the user creating the note (defaults to the API user)",
optional: true,
},
notify_emails: {
type: "string[]",
label: "Notify Emails",
description: "Array of email addresses to notify about this note",
optional: true,
},
},
async run({ $ }) {
const {
freshdesk,
ticketId,
body,
private: isPrivate,
incoming,
user_id,
notify_emails,
} = this;

if (!body || !body.trim()) {
throw new ConfigurationError("Note body cannot be empty");
}

const ticketName = await freshdesk.getTicketName(ticketId);
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify error handling for getTicketName method.

Ensure that if the ticket doesn't exist, the error is handled gracefully.

Run the following script to check if getTicketName has proper error handling:


🏁 Script executed:

#!/bin/bash
# Check if getTicketName method has error handling for non-existent tickets
ast-grep --pattern $'async getTicketName($TICKET_ID) {
  $$$
}'

Length of output: 64


To locate the getTicketName implementation and inspect its error handling, let’s search for its definition across the codebase:


🏁 Script executed:

#!/bin/bash
# Find all occurrences of getTicketName to locate its implementation
rg -n "getTicketName" --color=never

Length of output: 989


Let’s inspect the implementation around line 253 to see how errors are handled:


🏁 Script executed:

#!/bin/bash
# Show getTicketName implementation with context
rg -n "async getTicketName" -A15 -B5 components/freshdesk/freshdesk.app.mjs

Length of output: 612


To verify how missing tickets are handled, let’s inspect the getTicket implementation:


🏁 Script executed:

#!/bin/bash
# Show getTicket implementation with context to check error handling
rg -n "async getTicket" -A15 -B5 components/freshdesk/freshdesk.app.mjs

Length of output: 1134


Let’s inspect the _makeRequest implementation to see how it handles HTTP errors (e.g., 404 for non-existent tickets):


🏁 Script executed:

#!/bin/bash
# Locate _makeRequest implementation with surrounding context
rg -n "async _makeRequest" -A20 -B5 components/freshdesk/freshdesk.app.mjs

Length of output: 805


Add explicit error handling for missing tickets in getTicketName

The getTicketName helper currently propagates any errors (including 404s) up to the caller. We need to catch “ticket not found” errors and handle them gracefully—either by returning null (or a default) or by surfacing a clear, user-friendly error.

Affected locations:

  • components/freshdesk/freshdesk.app.mjs at getTicketName (around line 253)
  • components/freshdesk/actions/add-note-to-ticket/add-note-to-ticket.mjs at the call site (line 67)

Proposed changes:

  1. Wrap getTicketName implementation in a try/catch and handle HTTP 404:
--- a/components/freshdesk/freshdesk.app.mjs
+++ b/components/freshdesk/freshdesk.app.mjs
@@ -251,7 +251,15 @@
     async getTicketName(ticketId) {
-      const ticket = await this.getTicket({ ticketId });
-      return ticket.subject;
+      try {
+        const ticket = await this.getTicket({ ticketId });
+        return ticket.subject;
+      } catch (error) {
+        if (error.response?.status === 404) {
+          // Ticket not found; return null or a default placeholder
+          return null;
+        }
+        // Re-throw other errors
+        throw error;
+      }
     },
  1. Handle the null (or fallback) at the action layer so the flow doesn’t break unexpectedly:
--- a/components/freshdesk/actions/add-note-to-ticket/add-note-to-ticket.mjs
+++ b/components/freshdesk/actions/add-note-to-ticket/add-note-to-ticket.mjs
@@ -64,7 +64,13 @@
     const ticketId = await freshdesk.searchTickets({ /* … */ });
-    const ticketName = await freshdesk.getTicketName(ticketId);
+    let ticketName;
+    try {
+      ticketName = await freshdesk.getTicketName(ticketId);
+      if (!ticketName) {
+        // Optional: handle missing ticket (e.g., log warning or set default)
+        ticketName = "Unknown Ticket";
+      }
+    } catch (error) {
+      throw new Error(`Failed to fetch ticket name: ${error.message}`);
+    }

     // … proceed with adding the note

This ensures that 404s don’t crash your action and that any other errors bubble up clearly.

📝 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
const ticketName = await freshdesk.getTicketName(ticketId);
async getTicketName(ticketId) {
try {
const ticket = await this.getTicket({ ticketId });
return ticket.subject;
} catch (error) {
if (error.response?.status === 404) {
// Ticket not found; return null or a default placeholder
return null;
}
// Re-throw other errors
throw error;
}
},
Suggested change
const ticketName = await freshdesk.getTicketName(ticketId);
const ticketId = await freshdesk.searchTickets({ /* … */ });
let ticketName;
try {
ticketName = await freshdesk.getTicketName(ticketId);
if (!ticketName) {
// Optional: handle missing ticket (e.g., log warning or set default)
ticketName = "Unknown Ticket";
}
} catch (error) {
throw new Error(`Failed to fetch ticket name: ${error.message}`);
}
// … proceed with adding the note
🤖 Prompt for AI Agents
In components/freshdesk/actions/add-note-to-ticket/add-note-to-ticket.mjs at
line 67, the call to getTicketName does not handle the case where the ticket is
missing (HTTP 404). Update the getTicketName function in
components/freshdesk/freshdesk.app.mjs around line 253 to wrap its logic in a
try/catch block that catches 404 errors and returns null or a default value
instead of throwing. Then, at the call site in add-note-to-ticket.mjs line 67,
check if the returned ticketName is null or fallback and handle that case
gracefully to prevent the action from breaking unexpectedly.


const data = {
body,
private: isPrivate,
};

if (incoming !== undefined) {
data.incoming = incoming;
}

if (user_id) {
data.user_id = Number(user_id);
}

if (notify_emails && notify_emails.length > 0) {
data.notify_emails = notify_emails;
}

const response = await freshdesk.addNoteToTicket({
$,
ticketId: Number(ticketId),
data,
});

$.export("$summary", `Note added to ticket "${ticketName}" (ID: ${ticketId})`);
return response;
},
};
3 changes: 1 addition & 2 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.3",
type: "action",
props: {
freshdesk,
Expand Down Expand Up @@ -119,4 +119,3 @@ export default {
return response;
},
};

10 changes: 10 additions & 0 deletions components/freshdesk/freshdesk.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,15 @@ export default {
}
return input;
},
async addNoteToTicket({
ticketId, data, ...args
}) {
return this._makeRequest({
url: `/tickets/${ticketId}/notes`,
method: "post",
data,
...args,
});
},
},
};
11 changes: 1 addition & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.