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 6 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
104 changes: 104 additions & 0 deletions components/freshdesk/actions/add-note-to-ticket/add-note-to-ticket.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
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) || "Unknown Ticket";

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

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

if (user_id) {
const userId = Number(user_id);
if (isNaN(userId)) {
throw new ConfigurationError("User ID must be a valid number");
}
data.user_id = userId;
}

if (notify_emails && notify_emails.length > 0) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const invalidEmails = notify_emails.filter((email) => !emailRegex.test(email));
if (invalidEmails.length > 0) {
throw new ConfigurationError(`Invalid email addresses: ${invalidEmails.join(", ")}`);
}
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;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default {

const data = removeNullEntries(fields);

const ticketName = await freshdesk.getTicketName(ticketId);
const ticketName = await freshdesk.getTicketName(ticketId) || "Unknown Ticket";

if (!Object.keys(data).length) {
throw new Error("Please provide at least one field to update.");
Expand Down
38 changes: 34 additions & 4 deletions components/freshdesk/freshdesk.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,17 @@ export default {
});
},
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) {
return null;
}
throw error;
}
},
parseIfJSONString(input) {
if (typeof input === "string") {
Expand All @@ -266,5 +273,28 @@ export default {
}
return input;
},
/**
* Add a note to a Freshdesk ticket
* @param {Object} options - The options object
* @param {number} options.ticketId - The ID of the ticket to add the note to
* @param {Object} options.data - The note data object
* @param {string} options.data.body - Content of the note in HTML format
* @param {boolean} [options.data.private=false] - Whether the note is private
* @param {boolean} [options.data.incoming] - Whether the note is incoming
* @param {number} [options.data.user_id] - ID of the user creating the note
* @param {string[]} [options.data.notify_emails] - Array of email addresses to notify
* @param {...*} args - Additional arguments passed to _makeRequest
* @returns {Promise<Object>} The API response containing the created note
*/
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.