Skip to content

Commit 3162811

Browse files
committed
Add update ticket action and set actions
1 parent 65e79d1 commit 3162811

File tree

6 files changed

+317
-0
lines changed

6 files changed

+317
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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",
7+
version: "0.0.3",
8+
type: "action",
9+
props: {
10+
freshdesk,
11+
ticketId: {
12+
propDefinition: [
13+
freshdesk,
14+
"ticketId",
15+
],
16+
},
17+
responder_id: {
18+
type: "integer",
19+
label: "Agent ID",
20+
description: "ID of the agent to assign this ticket to",
21+
},
22+
},
23+
async run({ $ }) {
24+
const response = await this.freshdesk._makeRequest({
25+
$,
26+
method: "PUT",
27+
url: `/tickets/${this.ticketId}`,
28+
data: {
29+
responder_id: this.responder_id,
30+
},
31+
});
32+
$.export("$summary", `Ticket ${this.ticketId} assigned to agent ${this.responder_id}`);
33+
return response;
34+
},
35+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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",
7+
version: "0.0.3",
8+
type: "action",
9+
props: {
10+
freshdesk,
11+
ticketId: {
12+
propDefinition: [
13+
freshdesk,
14+
"ticketId",
15+
],
16+
},
17+
group_id: {
18+
type: "integer",
19+
label: "Group ID",
20+
description: "ID of the group to assign this ticket to",
21+
},
22+
},
23+
async run({ $ }) {
24+
const response = await this.freshdesk._makeRequest({
25+
$,
26+
method: "PUT",
27+
url: `/tickets/${this.ticketId}`,
28+
data: {
29+
group_id: this.group_id,
30+
},
31+
});
32+
$.export("$summary", `Ticket ${this.ticketId} assigned to group ${this.group_id}`);
33+
return response;
34+
},
35+
};
Lines changed: 33 additions & 0 deletions
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.3",
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+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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",
7+
version: "0.0.3",
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+
const response = await this.freshdesk._makeRequest({
26+
$,
27+
method: "PUT",
28+
url: `/tickets/${this.ticketId}`,
29+
data: {
30+
priority: this.ticketPriority,
31+
},
32+
});
33+
$.export("$summary", `Ticket ${this.ticketId} priority updated to ${this.ticketPriority}`);
34+
return response;
35+
},
36+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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",
7+
version: "0.0.3",
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+
const response = await this.freshdesk._makeRequest({
26+
$,
27+
method: "PUT",
28+
url: `/tickets/${this.ticketId}`,
29+
data: {
30+
status: this.ticketStatus,
31+
},
32+
});
33+
$.export("$summary", `Ticket ${this.ticketId} status updated to ${this.ticketStatus}`);
34+
return response;
35+
},
36+
};
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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, tags, etc. [See docs](https://developers.freshdesk.com/api/#update_a_ticket)",
8+
version: "0.0.11",
9+
type: "action",
10+
props: {
11+
freshdesk,
12+
ticketId: {
13+
propDefinition: [
14+
freshdesk,
15+
"ticketId",
16+
],
17+
},
18+
ticketStatus: {
19+
propDefinition: [
20+
freshdesk,
21+
"ticketStatus",
22+
],
23+
optional: true,
24+
},
25+
ticketPriority: {
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+
type: "integer",
46+
label: "Group ID",
47+
description: "ID of the group to assign this ticket to",
48+
optional: true,
49+
},
50+
responder_id: {
51+
type: "integer",
52+
label: "Agent ID",
53+
description: "ID of the agent to assign this ticket to",
54+
optional: true,
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+
ticketStatus,
99+
ticketPriority,
100+
subject,
101+
description,
102+
type,
103+
group_id,
104+
responder_id,
105+
email,
106+
phone,
107+
name,
108+
tags,
109+
custom_fields,
110+
} = this;
111+
112+
const data = removeNullEntries({
113+
status: ticketStatus,
114+
priority: ticketPriority,
115+
subject,
116+
description,
117+
type,
118+
group_id,
119+
responder_id,
120+
email,
121+
phone,
122+
name,
123+
tags,
124+
custom_fields,
125+
});
126+
127+
if (!Object.keys(data).length) {
128+
throw new Error("Please provide at least one field to update.");
129+
}
130+
131+
const response = await freshdesk._makeRequest({
132+
$,
133+
method: "PUT",
134+
url: `/tickets/${ticketId}`,
135+
data,
136+
});
137+
138+
$.export("$summary", `Ticket ${ticketId} updated successfully`);
139+
return response;
140+
},
141+
};
142+

0 commit comments

Comments
 (0)