@pipedream/freshdesk 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,104 @@
1
+ import freshdesk from "../../freshdesk.app.mjs";
2
+ import { ConfigurationError } from "@pipedream/platform";
3
+
4
+ export default {
5
+ key: "freshdesk-add-note-to-ticket",
6
+ name: "Add Note to Ticket",
7
+ description: "Add a note or conversation to an existing ticket. [See the documentation](https://developers.freshdesk.com/api/#add_note_to_a_ticket).",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ props: {
11
+ freshdesk,
12
+ ticketId: {
13
+ propDefinition: [
14
+ freshdesk,
15
+ "ticketId",
16
+ ],
17
+ },
18
+ body: {
19
+ type: "string",
20
+ label: "Note Body",
21
+ description: "Content of the note in HTML format",
22
+ },
23
+ private: {
24
+ type: "boolean",
25
+ label: "Private Note",
26
+ description: "Set to true if the note is private (internal)",
27
+ default: false,
28
+ },
29
+ incoming: {
30
+ type: "boolean",
31
+ label: "Incoming",
32
+ description: "Set to true if the note should be marked as incoming (false for outgoing)",
33
+ default: false,
34
+ optional: true,
35
+ },
36
+ user_id: {
37
+ propDefinition: [
38
+ freshdesk,
39
+ "agentId",
40
+ ],
41
+ label: "User ID",
42
+ description: "ID of the user creating the note (defaults to the API user)",
43
+ optional: true,
44
+ },
45
+ notify_emails: {
46
+ type: "string[]",
47
+ label: "Notify Emails",
48
+ description: "Array of email addresses to notify about this note",
49
+ optional: true,
50
+ },
51
+ },
52
+ async run({ $ }) {
53
+ const {
54
+ freshdesk,
55
+ ticketId,
56
+ body,
57
+ private: isPrivate,
58
+ incoming,
59
+ user_id,
60
+ notify_emails,
61
+ } = this;
62
+
63
+ if (!body || !body.trim()) {
64
+ throw new ConfigurationError("Note body cannot be empty");
65
+ }
66
+
67
+ const ticketName = await freshdesk.getTicketName(ticketId) || "Unknown Ticket";
68
+
69
+ const data = {
70
+ body,
71
+ private: isPrivate,
72
+ };
73
+
74
+ if (incoming !== undefined) {
75
+ data.incoming = incoming;
76
+ }
77
+
78
+ if (user_id) {
79
+ const userId = Number(user_id);
80
+ if (isNaN(userId)) {
81
+ throw new ConfigurationError("User ID must be a valid number");
82
+ }
83
+ data.user_id = userId;
84
+ }
85
+
86
+ if (notify_emails && notify_emails.length > 0) {
87
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
88
+ const invalidEmails = notify_emails.filter((email) => !emailRegex.test(email));
89
+ if (invalidEmails.length > 0) {
90
+ throw new ConfigurationError(`Invalid email addresses: ${invalidEmails.join(", ")}`);
91
+ }
92
+ data.notify_emails = notify_emails;
93
+ }
94
+
95
+ const response = await freshdesk.addNoteToTicket({
96
+ $,
97
+ ticketId: Number(ticketId),
98
+ data,
99
+ });
100
+
101
+ $.export("$summary", `Note added to ticket "${ticketName}" (ID: ${ticketId})`);
102
+ return response;
103
+ },
104
+ };
@@ -0,0 +1,45 @@
1
+ import freshdesk from "../../freshdesk.app.mjs";
2
+ import { ConfigurationError } from "@pipedream/platform";
3
+
4
+ export default {
5
+ key: "freshdesk-add-ticket-tags",
6
+ name: "Add Ticket Tags",
7
+ description: "Add tags to a ticket (appends to existing tags). [See the documentation](https://developers.freshdesk.com/api/#update_ticket)",
8
+ type: "action",
9
+ version: "0.0.2",
10
+ props: {
11
+ freshdesk,
12
+ ticketId: {
13
+ propDefinition: [
14
+ freshdesk,
15
+ "ticketId",
16
+ ],
17
+ },
18
+ ticketTags: {
19
+ propDefinition: [
20
+ freshdesk,
21
+ "ticketTags",
22
+ ],
23
+ description: "Array of tags to add to the ticket. These will be added to any existing tags.",
24
+ },
25
+ },
26
+ async run({ $ }) {
27
+ const {
28
+ ticketId,
29
+ ticketTags,
30
+ } = this;
31
+
32
+ if (!ticketTags || ticketTags.length === 0) {
33
+ throw new ConfigurationError("At least one tag must be provided");
34
+ }
35
+
36
+ const response = await this.freshdesk.addTicketTags({
37
+ ticketId,
38
+ tags: ticketTags,
39
+ $,
40
+ });
41
+
42
+ $.export("$summary", `Successfully added ${ticketTags.length} tag(s) to ticket ${ticketId}`);
43
+ return response;
44
+ },
45
+ };
@@ -4,7 +4,7 @@ export default {
4
4
  key: "freshdesk-assign-ticket-to-agent",
5
5
  name: "Assign Ticket to Agent",
6
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",
7
+ version: "0.0.3",
8
8
  type: "action",
9
9
  props: {
10
10
  freshdesk,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "freshdesk-assign-ticket-to-group",
5
5
  name: "Assign Ticket to Group",
6
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",
7
+ version: "0.0.3",
8
8
  type: "action",
9
9
  props: {
10
10
  freshdesk,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "freshdesk-close-ticket",
5
5
  name: "Close Ticket",
6
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",
7
+ version: "0.0.3",
8
8
  type: "action",
9
9
  props: {
10
10
  freshdesk,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "freshdesk-create-company",
5
5
  name: "Create a Company",
6
6
  description: "Create a company. [See the documentation](https://developers.freshdesk.com/api/#create_company)",
7
- version: "0.0.4",
7
+ version: "0.0.6",
8
8
  type: "action",
9
9
  props: {
10
10
  freshdesk,
@@ -5,7 +5,7 @@ export default {
5
5
  key: "freshdesk-create-contact",
6
6
  name: "Create a Contact",
7
7
  description: "Create a contact. [See the documentation](https://developers.freshdesk.com/api/#create_contact)",
8
- version: "0.0.4",
8
+ version: "0.0.6",
9
9
  type: "action",
10
10
  props: {
11
11
  freshdesk,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "freshdesk-create-ticket",
5
5
  name: "Create a Ticket",
6
6
  description: "Create a ticket. [See the documentation](https://developers.freshdesk.com/api/#create_ticket)",
7
- version: "0.0.5",
7
+ version: "0.0.7",
8
8
  type: "action",
9
9
  props: {
10
10
  freshdesk,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "freshdesk-get-ticket",
5
5
  name: "Get Ticket Details",
6
6
  description: "Get details of a Ticket. [See the documentation](https://developers.freshdesk.com/api/#view_a_ticket)",
7
- version: "0.1.2",
7
+ version: "0.1.4",
8
8
  type: "action",
9
9
  props: {
10
10
  freshdesk,
@@ -5,7 +5,7 @@ export default {
5
5
  name: "List Tickets",
6
6
  description:
7
7
  "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.2",
8
+ version: "0.2.4",
9
9
  type: "action",
10
10
  props: {
11
11
  freshdesk,
@@ -0,0 +1,45 @@
1
+ import freshdesk from "../../freshdesk.app.mjs";
2
+ import { ConfigurationError } from "@pipedream/platform";
3
+
4
+ export default {
5
+ key: "freshdesk-remove-ticket-tags",
6
+ name: "Remove Ticket Tags",
7
+ description: "Remove specific tags from a ticket. [See the documentation](https://developers.freshdesk.com/api/#update_ticket)",
8
+ type: "action",
9
+ version: "0.0.2",
10
+ props: {
11
+ freshdesk,
12
+ ticketId: {
13
+ propDefinition: [
14
+ freshdesk,
15
+ "ticketId",
16
+ ],
17
+ },
18
+ ticketTags: {
19
+ propDefinition: [
20
+ freshdesk,
21
+ "ticketTags",
22
+ ],
23
+ description: "Array of tags to remove from the ticket. Only these specific tags will be removed.",
24
+ },
25
+ },
26
+ async run({ $ }) {
27
+ const {
28
+ ticketId,
29
+ ticketTags,
30
+ } = this;
31
+
32
+ if (!ticketTags || ticketTags.length === 0) {
33
+ throw new ConfigurationError("At least one tag must be provided");
34
+ }
35
+
36
+ const response = await this.freshdesk.removeTicketTags({
37
+ ticketId,
38
+ tags: ticketTags,
39
+ $,
40
+ });
41
+
42
+ $.export("$summary", `Successfully removed ${ticketTags.length} tag(s) from ticket ${ticketId}`);
43
+ return response;
44
+ },
45
+ };
@@ -4,7 +4,7 @@ export default {
4
4
  key: "freshdesk-set-ticket-priority",
5
5
  name: "Set Ticket Priority",
6
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",
7
+ version: "0.0.3",
8
8
  type: "action",
9
9
  props: {
10
10
  freshdesk,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "freshdesk-set-ticket-status",
5
5
  name: "Set Ticket Status",
6
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",
7
+ version: "0.0.3",
8
8
  type: "action",
9
9
  props: {
10
10
  freshdesk,
@@ -0,0 +1,45 @@
1
+ import freshdesk from "../../freshdesk.app.mjs";
2
+ import { ConfigurationError } from "@pipedream/platform";
3
+
4
+ export default {
5
+ key: "freshdesk-set-ticket-tags",
6
+ name: "Set Ticket Tags",
7
+ description: "Set tags on a ticket (replaces all existing tags). [See the documentation](https://developers.freshdesk.com/api/#update_ticket)",
8
+ type: "action",
9
+ version: "0.0.2",
10
+ props: {
11
+ freshdesk,
12
+ ticketId: {
13
+ propDefinition: [
14
+ freshdesk,
15
+ "ticketId",
16
+ ],
17
+ },
18
+ ticketTags: {
19
+ propDefinition: [
20
+ freshdesk,
21
+ "ticketTags",
22
+ ],
23
+ description: "Array of tags to set on the ticket. This will replace all existing tags.",
24
+ },
25
+ },
26
+ async run({ $ }) {
27
+ const {
28
+ ticketId,
29
+ ticketTags,
30
+ } = this;
31
+
32
+ if (!ticketTags || ticketTags.length === 0) {
33
+ throw new ConfigurationError("At least one tag must be provided");
34
+ }
35
+
36
+ const response = await this.freshdesk.setTicketTags({
37
+ ticketId,
38
+ tags: ticketTags,
39
+ $,
40
+ });
41
+
42
+ $.export("$summary", `Successfully set ${ticketTags.length} tag(s) on ticket ${ticketId}`);
43
+ return response;
44
+ },
45
+ };
@@ -5,7 +5,7 @@ export default {
5
5
  key: "freshdesk-update-ticket",
6
6
  name: "Update a Ticket",
7
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",
8
+ version: "0.0.3",
9
9
  type: "action",
10
10
  props: {
11
11
  freshdesk,
@@ -100,7 +100,7 @@ export default {
100
100
 
101
101
  const data = removeNullEntries(fields);
102
102
 
103
- const ticketName = await freshdesk.getTicketName(ticketId);
103
+ const ticketName = await freshdesk.getTicketName(ticketId) || "Unknown Ticket";
104
104
 
105
105
  if (!Object.keys(data).length) {
106
106
  throw new Error("Please provide at least one field to update.");
@@ -119,4 +119,3 @@ export default {
119
119
  return response;
120
120
  },
121
121
  };
122
-
package/freshdesk.app.mjs CHANGED
@@ -116,6 +116,12 @@ export default {
116
116
  }));
117
117
  },
118
118
  },
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
+ },
119
125
  },
120
126
  methods: {
121
127
  setLastDateChecked(db, value) {
@@ -251,10 +257,17 @@ export default {
251
257
  });
252
258
  },
253
259
  async getTicketName(ticketId) {
254
- const ticket = await this.getTicket({
255
- ticketId,
256
- });
257
- return ticket.subject;
260
+ try {
261
+ const ticket = await this.getTicket({
262
+ ticketId,
263
+ });
264
+ return ticket.subject;
265
+ } catch (error) {
266
+ if (error.response?.status === 404) {
267
+ return null;
268
+ }
269
+ throw error;
270
+ }
258
271
  },
259
272
  parseIfJSONString(input) {
260
273
  if (typeof input === "string") {
@@ -266,5 +279,101 @@ export default {
266
279
  }
267
280
  return input;
268
281
  },
282
+ /**
283
+ * Add a note to a Freshdesk ticket
284
+ * @param {Object} options - The options object
285
+ * @param {number} options.ticketId - The ID of the ticket to add the note to
286
+ * @param {Object} options.data - The note data object
287
+ * @param {string} options.data.body - Content of the note in HTML format
288
+ * @param {boolean} [options.data.private=false] - Whether the note is private
289
+ * @param {boolean} [options.data.incoming] - Whether the note is incoming
290
+ * @param {number} [options.data.user_id] - ID of the user creating the note
291
+ * @param {string[]} [options.data.notify_emails] - Array of email addresses to notify
292
+ * @param {...*} args - Additional arguments passed to _makeRequest
293
+ * @returns {Promise<Object>} The API response containing the created note
294
+ */
295
+ async addNoteToTicket({
296
+ ticketId, data, ...args
297
+ }) {
298
+ return this._makeRequest({
299
+ url: `/tickets/${ticketId}/notes`,
300
+ method: "post",
301
+ data,
302
+ ...args,
303
+ });
304
+ },
305
+ /**
306
+ * Set tags on a ticket (replaces all existing tags)
307
+ * @param {object} args - Arguments object
308
+ * @param {string|number} args.ticketId - The ticket ID
309
+ * @param {string[]} args.tags - Array of tags to set
310
+ * @returns {Promise<object>} API response
311
+ */
312
+ async setTicketTags({
313
+ ticketId, tags, ...args
314
+ }) {
315
+ return this._makeRequest({
316
+ url: `/tickets/${ticketId}`,
317
+ method: "PUT",
318
+ data: {
319
+ tags,
320
+ },
321
+ ...args,
322
+ });
323
+ },
324
+ /**
325
+ * Add tags to a ticket (appends to existing tags)
326
+ * @param {object} args - Arguments object
327
+ * @param {string|number} args.ticketId - The ticket ID
328
+ * @param {string[]} args.tags - Array of tags to add
329
+ * @returns {Promise<object>} API response
330
+ */
331
+ async addTicketTags({
332
+ ticketId, tags, ...args
333
+ }) {
334
+ // Get current ticket to merge tags
335
+ const ticket = await this.getTicket({
336
+ ticketId,
337
+ ...args,
338
+ });
339
+ const currentTags = ticket.tags || [];
340
+ const newTags = [
341
+ ...new Set([
342
+ ...currentTags,
343
+ ...tags,
344
+ ]),
345
+ ]; // Remove duplicates
346
+
347
+ return this.setTicketTags({
348
+ ticketId,
349
+ tags: newTags,
350
+ ...args,
351
+ });
352
+ },
353
+ /**
354
+ * Remove specific tags from a ticket
355
+ * @param {object} args - Arguments object
356
+ * @param {string|number} args.ticketId - The ticket ID
357
+ * @param {string[]} args.tags - Array of tags to remove
358
+ * @returns {Promise<object>} API response
359
+ */
360
+ async removeTicketTags({
361
+ ticketId, tags, ...args
362
+ }) {
363
+ // Get current ticket to filter tags
364
+ const ticket = await this.getTicket({
365
+ ticketId,
366
+ ...args,
367
+ });
368
+ const currentTags = ticket.tags || [];
369
+ const tagsToRemove = new Set(tags);
370
+ const remainingTags = currentTags.filter((tag) => !tagsToRemove.has(tag));
371
+
372
+ return this.setTicketTags({
373
+ ticketId,
374
+ tags: remainingTags,
375
+ ...args,
376
+ });
377
+ },
269
378
  },
270
379
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/freshdesk",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Pipedream Freshdesk Components",
5
5
  "main": "freshdesk.app.mjs",
6
6
  "keywords": [
@@ -6,7 +6,7 @@ export default {
6
6
  key: "freshdesk-new-contact",
7
7
  name: "New Contact Created",
8
8
  description: "Emit new event when a contact is created. [See the documentation](https://developers.freshdesk.com/api/#filter_contacts)",
9
- version: "0.0.5",
9
+ version: "0.0.7",
10
10
  type: "source",
11
11
  props: {
12
12
  freshdesk,
@@ -6,7 +6,7 @@ export default {
6
6
  key: "freshdesk-new-ticket",
7
7
  name: "New Ticket Created",
8
8
  description: "Emit new event when a ticket is created. [See the documentation](https://developers.freshdesk.com/api/#filter_tickets)",
9
- version: "0.0.5",
9
+ version: "0.0.7",
10
10
  type: "source",
11
11
  props: {
12
12
  freshdesk,