@pipedream/freshdesk 0.3.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
+ };
@@ -6,7 +6,7 @@ export default {
6
6
  name: "Add Ticket Tags",
7
7
  description: "Add tags to a ticket (appends to existing tags). [See the documentation](https://developers.freshdesk.com/api/#update_ticket)",
8
8
  type: "action",
9
- version: "0.0.1",
9
+ version: "0.0.2",
10
10
  props: {
11
11
  freshdesk,
12
12
  ticketId: {
@@ -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.2",
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.2",
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.2",
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.5",
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.5",
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.6",
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.3",
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.3",
8
+ version: "0.2.4",
9
9
  type: "action",
10
10
  props: {
11
11
  freshdesk,
@@ -6,7 +6,7 @@ export default {
6
6
  name: "Remove Ticket Tags",
7
7
  description: "Remove specific tags from a ticket. [See the documentation](https://developers.freshdesk.com/api/#update_ticket)",
8
8
  type: "action",
9
- version: "0.0.1",
9
+ version: "0.0.2",
10
10
  props: {
11
11
  freshdesk,
12
12
  ticketId: {
@@ -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.2",
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.2",
7
+ version: "0.0.3",
8
8
  type: "action",
9
9
  props: {
10
10
  freshdesk,
@@ -6,7 +6,7 @@ export default {
6
6
  name: "Set Ticket Tags",
7
7
  description: "Set tags on a ticket (replaces all existing tags). [See the documentation](https://developers.freshdesk.com/api/#update_ticket)",
8
8
  type: "action",
9
- version: "0.0.1",
9
+ version: "0.0.2",
10
10
  props: {
11
11
  freshdesk,
12
12
  ticketId: {
@@ -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.2",
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
@@ -257,10 +257,17 @@ export default {
257
257
  });
258
258
  },
259
259
  async getTicketName(ticketId) {
260
- const ticket = await this.getTicket({
261
- ticketId,
262
- });
263
- 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
+ }
264
271
  },
265
272
  parseIfJSONString(input) {
266
273
  if (typeof input === "string") {
@@ -272,6 +279,29 @@ export default {
272
279
  }
273
280
  return input;
274
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
+ },
275
305
  /**
276
306
  * Set tags on a ticket (replaces all existing tags)
277
307
  * @param {object} args - Arguments object
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/freshdesk",
3
- "version": "0.3.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.6",
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.6",
9
+ version: "0.0.7",
10
10
  type: "source",
11
11
  props: {
12
12
  freshdesk,