Skip to content

Commit cab8c94

Browse files
[ACTIONS] Freshdesk. Add update-ticket and SET actions (#16450)
* Add update ticket action and set actions * Ammend * Ammend * Fix after QA * versions * pnpm-lock.yaml --------- Co-authored-by: michelle0927 <[email protected]>
1 parent 582ff70 commit cab8c94

File tree

15 files changed

+409
-8
lines changed

15 files changed

+409
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import freshdesk from "../../freshdesk.app.mjs";
2+
3+
export default {
4+
key: "freshdesk-assign-ticket-to-agent",
5+
name: "Assign Ticket to Agent",
6+
description: "Assign a Freshdesk ticket to a specific agent. [See the documentation](https://developers.freshdesk.com/api/#update_ticket).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
freshdesk,
11+
ticketId: {
12+
propDefinition: [
13+
freshdesk,
14+
"ticketId",
15+
],
16+
},
17+
responder_id: {
18+
propDefinition: [
19+
freshdesk,
20+
"agentId",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
26+
const ticketName = await this.freshdesk.getTicketName(this.ticketId);
27+
28+
const response = await this.freshdesk._makeRequest({
29+
$,
30+
method: "PUT",
31+
url: `/tickets/${this.ticketId}`,
32+
data: {
33+
responder_id: this.responder_id,
34+
},
35+
});
36+
$.export("$summary",
37+
`Ticket "${ticketName}" (ID: ${this.ticketId}) assigned to agent ${this.responder_id}`);
38+
39+
return response;
40+
},
41+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import freshdesk from "../../freshdesk.app.mjs";
2+
3+
export default {
4+
key: "freshdesk-assign-ticket-to-group",
5+
name: "Assign Ticket to Group",
6+
description: "Assign a Freshdesk ticket to a specific group [See the documentation](https://developers.freshdesk.com/api/#update_ticket).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
freshdesk,
11+
ticketId: {
12+
propDefinition: [
13+
freshdesk,
14+
"ticketId",
15+
],
16+
},
17+
group_id: {
18+
propDefinition: [
19+
freshdesk,
20+
"groupId",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
26+
const ticketName = await this.freshdesk.getTicketName(this.ticketId);
27+
28+
const response = await this.freshdesk._makeRequest({
29+
$,
30+
method: "PUT",
31+
url: `/tickets/${this.ticketId}`,
32+
data: {
33+
group_id: this.group_id,
34+
},
35+
});
36+
37+
$.export("$summary",
38+
`Ticket "${ticketName}" (ID: ${this.ticketId}) assigned to group ${this.group_id}`);
39+
40+
return response;
41+
},
42+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import freshdesk from "../../freshdesk.app.mjs";
2+
3+
export default {
4+
key: "freshdesk-close-ticket",
5+
name: "Close Ticket",
6+
description: "Set a Freshdesk ticket's status to 'Closed'. [See docs](https://developers.freshdesk.com/api/#update_a_ticket)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
freshdesk,
11+
ticketId: {
12+
propDefinition: [
13+
freshdesk,
14+
"ticketId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const CLOSED_STATUS = 5; // Freshdesk status code for 'Closed'
20+
21+
const response = await this.freshdesk._makeRequest({
22+
$,
23+
method: "PUT",
24+
url: `/tickets/${this.ticketId}`,
25+
data: {
26+
status: CLOSED_STATUS,
27+
},
28+
});
29+
30+
$.export("$summary", `Ticket ${this.ticketId} closed successfully`);
31+
return response;
32+
},
33+
};

components/freshdesk/actions/create-company/create-company.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "freshdesk-create-company",
55
name: "Create a Company",
66
description: "Create a company. [See the documentation](https://developers.freshdesk.com/api/#create_company)",
7-
version: "0.0.3",
7+
version: "0.0.4",
88
type: "action",
99
props: {
1010
freshdesk,

components/freshdesk/actions/create-contact/create-contact.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "freshdesk-create-contact",
66
name: "Create a Contact",
77
description: "Create a contact. [See the documentation](https://developers.freshdesk.com/api/#create_contact)",
8-
version: "0.0.3",
8+
version: "0.0.4",
99
type: "action",
1010
props: {
1111
freshdesk,

components/freshdesk/actions/create-ticket/create-ticket.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "freshdesk-create-ticket",
55
name: "Create a Ticket",
66
description: "Create a ticket. [See the documentation](https://developers.freshdesk.com/api/#create_ticket)",
7-
version: "0.0.4",
7+
version: "0.0.5",
88
type: "action",
99
props: {
1010
freshdesk,

components/freshdesk/actions/get-ticket/get-ticket.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "freshdesk-get-ticket",
55
name: "Get Ticket Details",
66
description: "Get details of a Ticket. [See the documentation](https://developers.freshdesk.com/api/#view_a_ticket)",
7-
version: "0.1.1",
7+
version: "0.1.2",
88
type: "action",
99
props: {
1010
freshdesk,

components/freshdesk/actions/list-all-tickets/list-all-tickets.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
name: "List Tickets",
66
description:
77
"Fetch up to 100 tickets according to the selected filters. [See the documentation](https://developers.freshdesk.com/api/#list_all_tickets)",
8-
version: "0.2.1",
8+
version: "0.2.2",
99
type: "action",
1010
props: {
1111
freshdesk,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import freshdesk from "../../freshdesk.app.mjs";
2+
3+
export default {
4+
key: "freshdesk-set-ticket-priority",
5+
name: "Set Ticket Priority",
6+
description: "Update the priority of a ticket in Freshdesk [See the documentation](https://developers.freshdesk.com/api/#update_ticket).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
freshdesk,
11+
ticketId: {
12+
propDefinition: [
13+
freshdesk,
14+
"ticketId",
15+
],
16+
},
17+
ticketPriority: {
18+
propDefinition: [
19+
freshdesk,
20+
"ticketPriority",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
26+
const ticketName = await this.freshdesk.getTicketName(this.ticketId);
27+
28+
const response = await this.freshdesk._makeRequest({
29+
$,
30+
method: "PUT",
31+
url: `/tickets/${this.ticketId}`,
32+
data: {
33+
priority: this.ticketPriority,
34+
},
35+
});
36+
37+
const priorityLabels = {
38+
1: "Low",
39+
2: "Medium",
40+
3: "High",
41+
4: "Urgent",
42+
};
43+
44+
const priorityLabel = priorityLabels[this.ticketPriority] || this.ticketPriority;
45+
46+
$.export("$summary",
47+
`Ticket ${ticketName} (ID: ${this.ticketId}) priority updated to "${priorityLabel}".`);
48+
49+
return response;
50+
},
51+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import freshdesk from "../../freshdesk.app.mjs";
2+
3+
export default {
4+
key: "freshdesk-set-ticket-status",
5+
name: "Set Ticket Status",
6+
description: "Update the status of a ticket in Freshdesk [See the documentation](https://developers.freshdesk.com/api/#update_ticket).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
freshdesk,
11+
ticketId: {
12+
propDefinition: [
13+
freshdesk,
14+
"ticketId",
15+
],
16+
},
17+
ticketStatus: {
18+
propDefinition: [
19+
freshdesk,
20+
"ticketStatus",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
26+
const ticketName = await this.freshdesk.getTicketName(this.ticketId);
27+
28+
const response = await this.freshdesk._makeRequest({
29+
$,
30+
method: "PUT",
31+
url: `/tickets/${this.ticketId}`,
32+
data: {
33+
status: this.ticketStatus,
34+
},
35+
});
36+
37+
const statusLabels = {
38+
2: "Open",
39+
3: "Pending",
40+
4: "Resolved",
41+
5: "Closed",
42+
};
43+
44+
const statusLabel = statusLabels[this.ticketStatus] || this.ticketStatus;
45+
46+
$.export(
47+
"$summary",
48+
`Ticket "${ticketName}" (ID: ${this.ticketId}) status updated to "${statusLabel}".`,
49+
);
50+
51+
return response;
52+
},
53+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import freshdesk from "../../freshdesk.app.mjs";
2+
import { removeNullEntries } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "freshdesk-update-ticket",
6+
name: "Update a Ticket",
7+
description: "Update status, priority, subject, description, agent, group, etc. [See the documentation](https://developers.freshdesk.com/api/#update_ticket).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
freshdesk,
12+
ticketId: {
13+
propDefinition: [
14+
freshdesk,
15+
"ticketId",
16+
],
17+
},
18+
status: {
19+
propDefinition: [
20+
freshdesk,
21+
"ticketStatus",
22+
],
23+
optional: true,
24+
},
25+
priority: {
26+
propDefinition: [
27+
freshdesk,
28+
"ticketPriority",
29+
],
30+
optional: true,
31+
},
32+
subject: {
33+
type: "string",
34+
label: "Subject",
35+
description: "Ticket subject",
36+
optional: true,
37+
},
38+
description: {
39+
type: "string",
40+
label: "Description",
41+
description: "Detailed ticket description (HTML allowed)",
42+
optional: true,
43+
},
44+
group_id: {
45+
propDefinition: [
46+
freshdesk,
47+
"groupId",
48+
],
49+
},
50+
responder_id: {
51+
propDefinition: [
52+
freshdesk,
53+
"agentId",
54+
],
55+
},
56+
email: {
57+
type: "string",
58+
label: "Requester Email (replaces requester)",
59+
description: "Updates the requester. If no contact with this email exists, a new one will be created and assigned to the ticket.",
60+
optional: true,
61+
},
62+
phone: {
63+
type: "string",
64+
label: "Requester Phone (replaces requester)",
65+
description: "If no contact with this phone number exists, a new one will be created. If used without email, 'name' is required.",
66+
optional: true,
67+
},
68+
name: {
69+
type: "string",
70+
label: "Requester Name (required with phone if no email)",
71+
description: "Used when creating a contact with phone but no email.",
72+
optional: true,
73+
},
74+
type: {
75+
type: "string",
76+
label: "Type",
77+
description: "Type of ticket (must match one of the allowed values)",
78+
optional: true,
79+
options: [
80+
"Question",
81+
"Incident",
82+
"Problem",
83+
"Feature Request",
84+
"Refund",
85+
],
86+
},
87+
custom_fields: {
88+
type: "object",
89+
label: "Custom Fields",
90+
description: "Custom fields as key-value pairs (make sure types match your config)",
91+
optional: true,
92+
},
93+
},
94+
async run({ $ }) {
95+
const {
96+
freshdesk,
97+
ticketId,
98+
...fields
99+
} = this;
100+
101+
const data = removeNullEntries(fields);
102+
103+
const ticketName = await freshdesk.getTicketName(ticketId);
104+
105+
if (!Object.keys(data).length) {
106+
throw new Error("Please provide at least one field to update.");
107+
}
108+
109+
if (data.custom_fields) freshdesk.parseIfJSONString(data.custom_fields);
110+
111+
const response = await freshdesk._makeRequest({
112+
$,
113+
method: "PUT",
114+
url: `/tickets/${ticketId}`,
115+
data,
116+
});
117+
118+
$.export("$summary", `Ticket "${ticketName}" (ID: ${this.ticketId}) updated successfully`);
119+
return response;
120+
},
121+
};
122+

0 commit comments

Comments
 (0)