Skip to content

Complete Freshservice integration to match Freshdesk functionality #17608

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import freshservice from "../../freshservice.app.mjs";

export default {
key: "freshservice-assign-ticket-to-agent",
name: "Assign Ticket to Agent",
description: "Assign a ticket to an agent in Freshservice. [See the documentation](https://api.freshservice.com/v2/#update_ticket)",
version: "0.0.1",
type: "action",
props: {
freshservice,
ticketId: {
propDefinition: [
freshservice,
"ticketId",
],
},
responder_id: {
propDefinition: [
freshservice,
"agentId",
],
},
},
async run({ $ }) {
const response = await this.freshservice.updateTicket({
ticketId: this.ticketId,
data: {
responder_id: this.responder_id,
},
$,
});

const ticketName = await this.freshservice.getTicketName(this.ticketId);
$.export("$summary", `Successfully assigned ticket "${ticketName}" to agent`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import freshservice from "../../freshservice.app.mjs";

export default {
key: "freshservice-assign-ticket-to-group",
name: "Assign Ticket to Group",
description: "Assign a ticket to a group in Freshservice. [See the documentation](https://api.freshservice.com/v2/#update_ticket)",
version: "0.0.1",
type: "action",
props: {
freshservice,
ticketId: {
propDefinition: [
freshservice,
"ticketId",
],
},
group_id: {
propDefinition: [
freshservice,
"groupId",
],
},
},
async run({ $ }) {
const response = await this.freshservice.updateTicket({
ticketId: this.ticketId,
data: {
group_id: this.group_id,
},
$,
});

const ticketName = await this.freshservice.getTicketName(this.ticketId);
$.export("$summary", `Successfully assigned ticket "${ticketName}" to group`);
return response;
},
};
31 changes: 31 additions & 0 deletions components/freshservice/actions/close-ticket/close-ticket.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import freshservice from "../../freshservice.app.mjs";

export default {
key: "freshservice-close-ticket",
name: "Close Ticket",
description: "Close a ticket in Freshservice. [See the documentation](https://api.freshservice.com/v2/#update_ticket)",
version: "0.0.1",
type: "action",
props: {
freshservice,
ticketId: {
propDefinition: [
freshservice,
"ticketId",
],
},
},
async run({ $ }) {
const response = await this.freshservice.updateTicket({
ticketId: this.ticketId,
data: {
status: 5, // Closed
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

Use constants instead of hardcoded status values.

The status value 5 for "Closed" is hardcoded. Consider importing and using the TICKET_STATUS constants from the constants file for better maintainability.

+import { TICKET_STATUS } from "../../common/constants.mjs";

Then update the status assignment:

-        status: 5, // Closed
+        status: Object.keys(TICKET_STATUS).find(key => TICKET_STATUS[key] === "Closed") || 5,

Or if the constants file exports the actual status values:

-        status: 5, // Closed
+        status: TICKET_STATUS.CLOSED,

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In components/freshservice/actions/close-ticket/close-ticket.mjs at line 22,
replace the hardcoded status value 5 with the corresponding constant from the
TICKET_STATUS constants file. Import TICKET_STATUS at the top of the file if not
already imported, then assign status using TICKET_STATUS.Closed or the
appropriate constant name to improve maintainability and clarity.

},
$,
});

const ticketName = await this.freshservice.getTicketName(this.ticketId);
$.export("$summary", `Successfully closed ticket "${ticketName}"`);
return response;
},
};
109 changes: 109 additions & 0 deletions components/freshservice/actions/create-company/create-company.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import freshservice from "../../freshservice.app.mjs";
import { removeNullEntries } from "../../common/utils.mjs";

export default {
key: "freshservice-create-company",
name: "Create Company",
description: "Create a new company in Freshservice. [See the documentation](https://api.freshservice.com/v2/#create_company)",
version: "0.0.1",
type: "action",
props: {
freshservice,
name: {
type: "string",
label: "Name",
description: "Name of the company",
},
description: {
type: "string",
label: "Description",
description: "Description of the company",
optional: true,
},
note: {
type: "string",
label: "Note",
description: "Note about the company",
optional: true,
},
domains: {
type: "string[]",
label: "Domains",
description: "Domains associated with the company",
optional: true,
},
primary_email: {
type: "string",
label: "Primary Email",
description: "Primary email of the company",
optional: true,
},
phone: {
type: "string",
label: "Phone",
description: "Phone number of the company",
optional: true,
},
address: {
type: "string",
label: "Address",
description: "Address of the company",
optional: true,
},
city: {
type: "string",
label: "City",
description: "City of the company",
optional: true,
},
state: {
type: "string",
label: "State",
description: "State of the company",
optional: true,
},
zip_code: {
type: "string",
label: "Zip Code",
description: "Zip code of the company",
optional: true,
},
country: {
type: "string",
label: "Country",
description: "Country of the company",
optional: true,
},
custom_fields: {
type: "object",
label: "Custom Fields",
description: "Custom fields as a JSON object",
optional: true,
},
},
async run({ $ }) {
const {
custom_fields,
domains,
...otherProps
} = this;

const data = removeNullEntries(otherProps);

if (custom_fields) {
data.custom_fields = this.freshservice.parseIfJSONString(custom_fields);
}

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

const response = await this.freshservice.createCompany({
data,
$,
});

$.export("$summary", `Successfully created company: ${response.company?.name}`);
return response;
},
};
110 changes: 110 additions & 0 deletions components/freshservice/actions/create-contact/create-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { ConfigurationError } from "@pipedream/platform";
import freshservice from "../../freshservice.app.mjs";
import { removeNullEntries } from "../../common/utils.mjs";

export default {
key: "freshservice-create-contact",
name: "Create Contact",
description: "Create a new contact in Freshservice. [See the documentation](https://api.freshservice.com/v2/#create_requester)",
version: "0.0.1",
type: "action",
props: {
freshservice,
first_name: {
type: "string",
label: "First Name",
description: "First name of the contact",
},
last_name: {
type: "string",
label: "Last Name",
description: "Last name of the contact",
optional: true,
},
email: {
type: "string",
label: "Email",
description: "Primary email address of the contact",
optional: true,
},
secondary_emails: {
type: "string[]",
label: "Secondary Emails",
description: "Additional email addresses of the contact",
optional: true,
},
phone: {
type: "string",
label: "Phone",
description: "Phone number of the contact",
optional: true,
},
mobile: {
type: "string",
label: "Mobile",
description: "Mobile number of the contact",
optional: true,
},
job_title: {
type: "string",
label: "Job Title",
description: "Job title of the contact",
optional: true,
},
department_id: {
type: "string",
label: "Department ID",
description: "Department ID of the contact",
optional: true,
},
company_id: {
propDefinition: [
freshservice,
"companyId",
],
optional: true,
},
address: {
type: "string",
label: "Address",
description: "Address of the contact",
optional: true,
},
time_zone: {
type: "string",
label: "Time Zone",
description: "Time zone of the contact",
optional: true,
},
language: {
type: "string",
label: "Language",
description: "Language of the contact",
optional: true,
},
},
async run({ $ }) {
const {
secondary_emails,
...otherProps
} = this;

if (!this.email && !this.phone) {
throw new ConfigurationError("Either email or phone must be provided");
}

const data = removeNullEntries(otherProps);

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

const response = await this.freshservice.createContact({
data,
$,
});

$.export("$summary", `Successfully created contact: ${response.requester?.first_name} ${response.requester?.last_name || ""}`);
return response;
},
};
Loading