Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions components/helpspot/actions/common/request-base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import {
NOTE_IS_HTML,
NOTE_TYPE_OPTIONS,
OPENED_VIA_OPTIONS,
} from "../../common/constants.mjs";
import helpspot from "../../helpspot.app.mjs";

export default {
props: {
helpspot,
tNote: {
type: "string",
label: "Note",
description: "The note of the request",
},
xCategory: {
propDefinition: [
helpspot,
"xCategory",
],
},
fNoteType: {
type: "string",
label: "Note Type",
description: "The type of the note",
options: NOTE_TYPE_OPTIONS,
optional: true,
},
fNoteIsHTML: {
type: "string",
label: "Note Is HTML?",
description: "whether the note is HTML or text",
optional: true,
options: NOTE_IS_HTML,
},
Comment on lines +29 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider changing fNoteIsHTML type to boolean

The fNoteIsHTML property indicates whether the note is HTML or text. Currently, its type is set to "string", but since it represents a boolean value, it would be more appropriate to set its type to "boolean". This enhances type correctness and improves clarity.

Apply this diff to adjust the type:

        fNoteIsHTML: {
-          type: "string",
+          type: "boolean",
           label: "Note Is HTML?",
           description: "Whether the note is HTML or text",
           optional: true,
-          options: NOTE_IS_HTML,
        },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fNoteIsHTML: {
type: "string",
label: "Note Is HTML?",
description: "whether the note is HTML or text",
optional: true,
options: NOTE_IS_HTML,
},
fNoteIsHTML: {
type: "boolean",
label: "Note Is HTML?",
description: "Whether the note is HTML or text",
optional: true,
},

sTitle: {
type: "string",
label: "Subject",
description: "The title used as email subject",
optional: true,
},
xStatus: {
propDefinition: [
helpspot,
"xStatus",
],
optional: true,
},
sUserId: {
type: "string",
label: "User Id",
description: "The Id of the customer",
optional: true,
},
sFirstName: {
type: "string",
label: "First Name",
description: "The first name of the request creator",
optional: true,
},
sLastName: {
type: "string",
label: "Last Name",
description: "The last name of the request creator",
optional: true,
},
sEmail: {
type: "string",
label: "Email",
description: "The email of the request creator",
optional: true,
Comment on lines +68 to +71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Ensure valid email format for sEmail

The sEmail property represents the email of the request creator. Consider implementing validation to ensure that the provided string conforms to a valid email format. This helps prevent potential issues with invalid or malformed email addresses.

},
sPhone: {
type: "string",
label: "Phone",
description: "The phone number of the request creator",
optional: true,
},
fUrgent: {
type: "boolean",
label: "Urgent",
description: "Whether the request is urgent or not",
optional: true,
},
fOpenedVia: {
type: "integer",
label: "Opened Via",
description: "Request opened via",
options: OPENED_VIA_OPTIONS,
optional: true,
},
emailFrom: {
propDefinition: [
helpspot,
"emailFrom",
],
optional: true,
},
emailCC: {
type: "string[]",
label: "Email CC",
description: "A list of emails to CC on the request",
optional: true,
},
emailBCC: {
type: "string[]",
label: "Email BCC",
description: "A list of emails to BCC on the request",
optional: true,
},
Comment on lines +99 to +110
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Validate email arrays emailCC and emailBCC

The emailCC and emailBCC properties are arrays of strings representing email addresses. It's important to validate each email in these arrays to ensure they are in a valid email format. This will help prevent errors when processing emails and ensure reliable communication.

emailStaff: {
propDefinition: [
helpspot,
"emailStaff",
],
optional: true,
},
},
async run({ $ }) {
await this.getValidation();

const fn = this.getFunction();
const response = await fn({
$,
data: this.getData(),
});
Comment on lines +124 to +126
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Handle potential errors from the function call

When invoking fn() and awaiting its result, it's advisable to include error handling to catch any exceptions that may occur during the async operation. This enhances the robustness of the code and ensures that unexpected errors are properly managed.

Consider wrapping the function call in a try-catch block:

      const fn = this.getFunction();
-     const response = await fn({
-       $,
-       data: this.getData(),
-     });
+     let response;
+     try {
+       response = await fn({
+         $,
+         data: this.getData(),
+       });
+     } catch (error) {
+       throw new Error(`Failed to execute function: ${error.message}`);
+     }

Committable suggestion was skipped due to low confidence.


$.export("$summary", this.getSummary(response));
return response;
},
};
45 changes: 45 additions & 0 deletions components/helpspot/actions/create-request/create-request.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { parseObject } from "../../common/utils.mjs";
import common from "../common/request-base.mjs";

export default {
...common,
key: "helpspot-create-request",
name: "Create Request",
description: "Creates a new user request. [See the documentation](https://support.helpspot.com/index.php?pg=kb.page&id=164#private.request.create)",
version: "0.0.1",
type: "action",
methods: {
getValidation() {
if (!this.sFirstName && !this.sLastName && !this.sUserId && !this.sEmail && !this.sPhone) {
throw new Error("You must provide at least one of the following: First Name, Last Name, User ID, Email, or Phone.");
}
},
getFunction() {
return this.helpspot.createRequest;
},
getData() {
return {
tNote: this.tNote,
xCategory: this.xCategory,
fNoteType: this.fNoteType && parseInt(this.fNoteType),
fNoteIsHTML: this.fNoteIsHTML && parseInt(this.fNoteIsHTML),
sTitle: this.sTitle,
xStatus: this.xStatus,
sUserId: this.sUserId,
sFirstName: this.sFirstName,
sLastName: this.sLastName,
sEmail: this.sEmail,
sPhone: this.sPhone,
fUrgent: +this.fUrgent,
fOpenedVia: this.fOpenedVia,
email_from: this.emailFrom,
email_cc: parseObject(this.emailCC)?.join(),
email_bcc: parseObject(this.emailBCC)?.join(),
email_staff: parseObject(this.emailStaff)?.join(),
};
},
getSummary(response) {
return `Successfully created request with Id: ${response.xRequest}`;
},
},
};
53 changes: 53 additions & 0 deletions components/helpspot/actions/update-request/update-request.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { parseObject } from "../../common/utils.mjs";
import common from "../common/request-base.mjs";

export default {
...common,
key: "helpspot-update-request",
name: "Update Request",
description: "Updates an existing user request. [See the documentation](https://support.helpspot.com/index.php?pg=kb.page&id=164#private.request.update)",
version: "0.0.1",
type: "action",
props: {
...common.props,
xRequest: {
propDefinition: [
common.props.helpspot,
"xRequest",
],
},
},
methods: {
getValidation() {
return true;
},
getFunction() {
return this.helpspot.updateRequest;
},
getData() {
return {
xRequest: this.xRequest,
tNote: this.tNote,
xCategory: this.xCategory,
fNoteType: this.fNoteType && parseInt(this.fNoteType),
fNoteIsHTML: this.fNoteIsHTML && parseInt(this.fNoteIsHTML),
sTitle: this.sTitle,
xStatus: this.xStatus,
sUserId: this.sUserId,
sFirstName: this.sFirstName,
sLastName: this.sLastName,
sEmail: this.sEmail,
sPhone: this.sPhone,
fUrgent: +this.fUrgent,
fOpenedVia: this.fOpenedVia,
email_from: this.emailFrom,
email_cc: parseObject(this.emailCC)?.join(),
email_bcc: parseObject(this.emailBCC)?.join(),
email_staff: parseObject(this.emailStaff)?.join(),
};
},
getSummary() {
return `Successfully updated request with ID ${this.xRequest}`;
},
},
};
82 changes: 82 additions & 0 deletions components/helpspot/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
export const LIMIT = 100;

export const NOTE_TYPE_OPTIONS = [
{
label: "Private",
value: "0",
},
{
label: "Public",
value: "1",
},
{
label: "External",
value: "2",
},
];

export const NOTE_IS_HTML = [
{
label: "Text",
value: "0",
},
{
label: "HTML",
value: "1",
},
];

export const OPENED_VIA_OPTIONS = [
{
label: "Email",
value: 1,
},
{
label: "Phone",
value: 2,
},
{
label: "Walk In",
value: 3,
},
{
label: "Mail",
value: 4,
},
{
label: "Other",
value: 5,
},
{
label: "Web Service",
value: 6,
},
{
label: "Web Form",
value: 7,
},
{
label: "Forum",
value: 8,
},
{
label: "Instant Messenger",
value: 9,
},
{
label: "Fax",
value: 10,
},
{
label: "Voicemail",
value: 11,
},
{
label: "Staff Initiated",
value: 12,
},
{
label: "Tab Widget",
value: 13,
},
];
24 changes: 24 additions & 0 deletions components/helpspot/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
Loading
Loading