Skip to content

Commit e292f3f

Browse files
seynadioclaude
andcommitted
Add comprehensive tag management for Freshdesk tickets
- Added ticketTags prop definition to freshdesk.app.mjs - Added 3 tag management methods: setTicketTags, addTicketTags, removeTicketTags - Created 3 dedicated tag actions: set-ticket-tags, add-ticket-tags, remove-ticket-tags - Enhanced update-ticket action with tag support - Provides feature parity with Zendesk tag management 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent acc9e22 commit e292f3f

File tree

5 files changed

+213
-0
lines changed

5 files changed

+213
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import freshdesk from "../../freshdesk.app.mjs";
2+
3+
export default {
4+
key: "freshdesk-add-ticket-tags",
5+
name: "Add Ticket Tags",
6+
description: "Add tags to a ticket (appends to existing tags). [See the documentation](https://developers.freshdesk.com/api/#update_ticket)",
7+
type: "action",
8+
version: "0.0.1",
9+
props: {
10+
freshdesk,
11+
ticketId: {
12+
propDefinition: [
13+
freshdesk,
14+
"ticketId",
15+
],
16+
},
17+
ticketTags: {
18+
propDefinition: [
19+
freshdesk,
20+
"ticketTags",
21+
],
22+
description: "Array of tags to add to the ticket. These will be added to any existing tags.",
23+
},
24+
},
25+
async run({ $ }) {
26+
const {
27+
ticketId,
28+
ticketTags,
29+
} = this;
30+
31+
if (!ticketTags || ticketTags.length === 0) {
32+
throw new Error("At least one tag must be provided");
33+
}
34+
35+
const response = await this.freshdesk.addTicketTags({
36+
ticketId,
37+
tags: ticketTags,
38+
$,
39+
});
40+
41+
$.export("$summary", `Successfully added ${ticketTags.length} tag(s) to ticket ${ticketId}`);
42+
return response;
43+
},
44+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import freshdesk from "../../freshdesk.app.mjs";
2+
3+
export default {
4+
key: "freshdesk-remove-ticket-tags",
5+
name: "Remove Ticket Tags",
6+
description: "Remove specific tags from a ticket. [See the documentation](https://developers.freshdesk.com/api/#update_ticket)",
7+
type: "action",
8+
version: "0.0.1",
9+
props: {
10+
freshdesk,
11+
ticketId: {
12+
propDefinition: [
13+
freshdesk,
14+
"ticketId",
15+
],
16+
},
17+
ticketTags: {
18+
propDefinition: [
19+
freshdesk,
20+
"ticketTags",
21+
],
22+
description: "Array of tags to remove from the ticket. Only these specific tags will be removed.",
23+
},
24+
},
25+
async run({ $ }) {
26+
const {
27+
ticketId,
28+
ticketTags,
29+
} = this;
30+
31+
if (!ticketTags || ticketTags.length === 0) {
32+
throw new Error("At least one tag must be provided");
33+
}
34+
35+
const response = await this.freshdesk.removeTicketTags({
36+
ticketId,
37+
tags: ticketTags,
38+
$,
39+
});
40+
41+
$.export("$summary", `Successfully removed ${ticketTags.length} tag(s) from ticket ${ticketId}`);
42+
return response;
43+
},
44+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import freshdesk from "../../freshdesk.app.mjs";
2+
3+
export default {
4+
key: "freshdesk-set-ticket-tags",
5+
name: "Set Ticket Tags",
6+
description: "Set tags on a ticket (replaces all existing tags). [See the documentation](https://developers.freshdesk.com/api/#update_ticket)",
7+
type: "action",
8+
version: "0.0.1",
9+
props: {
10+
freshdesk,
11+
ticketId: {
12+
propDefinition: [
13+
freshdesk,
14+
"ticketId",
15+
],
16+
},
17+
ticketTags: {
18+
propDefinition: [
19+
freshdesk,
20+
"ticketTags",
21+
],
22+
description: "Array of tags to set on the ticket. This will replace all existing tags.",
23+
},
24+
},
25+
async run({ $ }) {
26+
const {
27+
ticketId,
28+
ticketTags,
29+
} = this;
30+
31+
if (!ticketTags || ticketTags.length === 0) {
32+
throw new Error("At least one tag must be provided");
33+
}
34+
35+
const response = await this.freshdesk.setTicketTags({
36+
ticketId,
37+
tags: ticketTags,
38+
$,
39+
});
40+
41+
$.export("$summary", `Successfully set ${ticketTags.length} tag(s) on ticket ${ticketId}`);
42+
return response;
43+
},
44+
};

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ export default {
9090
description: "Custom fields as key-value pairs (make sure types match your config)",
9191
optional: true,
9292
},
93+
tags: {
94+
propDefinition: [
95+
freshdesk,
96+
"ticketTags",
97+
],
98+
description: "Array of tags to set on the ticket. This will replace all existing tags.",
99+
},
93100
},
94101
async run({ $ }) {
95102
const {

components/freshdesk/freshdesk.app.mjs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ export default {
116116
}));
117117
},
118118
},
119+
ticketTags: {
120+
type: "string[]",
121+
label: "Tags",
122+
description: "Array of tags to apply to the ticket. Each tag must be 32 characters or less.",
123+
optional: true,
124+
},
119125
},
120126
methods: {
121127
setLastDateChecked(db, value) {
@@ -266,5 +272,73 @@ export default {
266272
}
267273
return input;
268274
},
275+
/**
276+
* Set tags on a ticket (replaces all existing tags)
277+
* @param {object} args - Arguments object
278+
* @param {string|number} args.ticketId - The ticket ID
279+
* @param {string[]} args.tags - Array of tags to set
280+
* @returns {Promise<object>} API response
281+
*/
282+
async setTicketTags({
283+
ticketId, tags, ...args
284+
}) {
285+
return this._makeRequest({
286+
url: `/tickets/${ticketId}`,
287+
method: "PUT",
288+
data: {
289+
tags,
290+
},
291+
...args,
292+
});
293+
},
294+
/**
295+
* Add tags to a ticket (appends to existing tags)
296+
* @param {object} args - Arguments object
297+
* @param {string|number} args.ticketId - The ticket ID
298+
* @param {string[]} args.tags - Array of tags to add
299+
* @returns {Promise<object>} API response
300+
*/
301+
async addTicketTags({
302+
ticketId, tags, ...args
303+
}) {
304+
// Get current ticket to merge tags
305+
const ticket = await this.getTicket({
306+
ticketId,
307+
...args,
308+
});
309+
const currentTags = ticket.tags || [];
310+
const newTags = [...new Set([...currentTags, ...tags])]; // Remove duplicates
311+
312+
return this.setTicketTags({
313+
ticketId,
314+
tags: newTags,
315+
...args,
316+
});
317+
},
318+
/**
319+
* Remove specific tags from a ticket
320+
* @param {object} args - Arguments object
321+
* @param {string|number} args.ticketId - The ticket ID
322+
* @param {string[]} args.tags - Array of tags to remove
323+
* @returns {Promise<object>} API response
324+
*/
325+
async removeTicketTags({
326+
ticketId, tags, ...args
327+
}) {
328+
// Get current ticket to filter tags
329+
const ticket = await this.getTicket({
330+
ticketId,
331+
...args,
332+
});
333+
const currentTags = ticket.tags || [];
334+
const tagsToRemove = new Set(tags);
335+
const remainingTags = currentTags.filter(tag => !tagsToRemove.has(tag));
336+
337+
return this.setTicketTags({
338+
ticketId,
339+
tags: remainingTags,
340+
...args,
341+
});
342+
},
269343
},
270344
};

0 commit comments

Comments
 (0)