Skip to content

Commit

Permalink
New Components - helpspot (#14153)
Browse files Browse the repository at this point in the history
* helpspot init

* [Components] helpspot #14147
Sources
 - New Request
 - New Request Updated

Actions
 - Update Request
 - Create Request

* pnpm update

* some adjusts

* Update components/helpspot/sources/new-request/new-request.mjs

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: Leo Vu <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 10, 2024
1 parent c0735bd commit da8d269
Show file tree
Hide file tree
Showing 13 changed files with 929 additions and 8 deletions.
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,
},
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,
},
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,
},
emailStaff: {
propDefinition: [
helpspot,
"emailStaff",
],
optional: true,
},
},
async run({ $ }) {
await this.getValidation();

const fn = this.getFunction();
const response = await fn({
$,
data: this.getData(),
});

$.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

0 comments on commit da8d269

Please sign in to comment.