Skip to content

Commit 55d2e93

Browse files
luancazarinelcaresia
authored andcommitted
New Components - help_scout (#14617)
* help_scout init * [Components] help_scout #14608 Sources - New Conversation Assigned (Instant) - New Conversation Created (Instant) - New Customer (Instant) Actions - Add Note - Create Customer - Send Reply * pnpm update * some adjusts
1 parent 852e0b2 commit 55d2e93

File tree

16 files changed

+1068
-55
lines changed

16 files changed

+1068
-55
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import helpScout from "../../help_scout.app.mjs";
2+
3+
export default {
4+
key: "help_scout-add-note",
5+
name: "Add Note to Conversation",
6+
description: "Adds a note to an existing conversation in Help Scout. [See the documentation](https://developer.helpscout.com/mailbox-api/endpoints/conversations/threads/note/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
helpScout,
11+
conversationId: {
12+
propDefinition: [
13+
helpScout,
14+
"conversationId",
15+
],
16+
},
17+
text: {
18+
propDefinition: [
19+
helpScout,
20+
"text",
21+
],
22+
},
23+
userId: {
24+
propDefinition: [
25+
helpScout,
26+
"userId",
27+
],
28+
optional: true,
29+
},
30+
},
31+
async run({ $ }) {
32+
const response = await this.helpScout.addNoteToConversation({
33+
$,
34+
conversationId: this.conversationId,
35+
data: {
36+
text: this.text,
37+
user: this.userId,
38+
},
39+
});
40+
$.export("$summary", `Successfully added note to conversation ID: ${this.conversationId}`);
41+
return response;
42+
},
43+
};
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import {
3+
GENDER_OPTIONS,
4+
PHOTO_TYPE_OPTIONS,
5+
} from "../../common/constants.mjs";
6+
import {
7+
cleanObject,
8+
parseObject,
9+
} from "../../common/utils.mjs";
10+
import helpScout from "../../help_scout.app.mjs";
11+
12+
export default {
13+
key: "help_scout-create-customer",
14+
name: "Create Customer",
15+
description: "Creates a new customer record in Help Scout. [See the documentation](https://developer.helpscout.com/mailbox-api/endpoints/customers/create/)",
16+
version: "0.0.1",
17+
type: "action",
18+
props: {
19+
helpScout,
20+
firstName: {
21+
type: "string",
22+
label: "First Name",
23+
description: "First name of the customer. When defined it must be between 1 and 40 characters.",
24+
optional: true,
25+
},
26+
lastName: {
27+
type: "string",
28+
label: "Last Name",
29+
description: "Last name of the customer. When defined it must be between 1 and 40 characters.",
30+
optional: true,
31+
},
32+
phone: {
33+
type: "string",
34+
label: "Phone",
35+
description: "The phone number that will be used when creating a new customer.",
36+
optional: true,
37+
},
38+
photoUrl: {
39+
type: "string",
40+
label: "Photo URL",
41+
description: "URL of the customer's photo. Max length 200 characters.",
42+
optional: true,
43+
},
44+
jobTitle: {
45+
type: "string",
46+
label: "Job Title",
47+
description: "Job title. Max length 60 characters.",
48+
optional: true,
49+
},
50+
photoType: {
51+
type: "string",
52+
label: "Photo Type",
53+
description: "The type of photo.",
54+
options: PHOTO_TYPE_OPTIONS,
55+
optional: true,
56+
},
57+
background: {
58+
type: "string",
59+
label: "Background",
60+
description: "This is the Notes field from the user interface. Max length 200 characters.",
61+
optional: true,
62+
},
63+
location: {
64+
type: "string",
65+
label: "Location",
66+
description: "Location of the customer. Max length 60 characters.",
67+
optional: true,
68+
},
69+
organization: {
70+
type: "string",
71+
label: "Organization",
72+
description: "Organization. Max length 60 characters.",
73+
optional: true,
74+
},
75+
gender: {
76+
type: "string",
77+
label: "Gender",
78+
description: "Gender of this customer.",
79+
options: GENDER_OPTIONS,
80+
optional: true,
81+
},
82+
age: {
83+
type: "string",
84+
label: "Age",
85+
description: "Customer's age.",
86+
optional: true,
87+
},
88+
emails: {
89+
type: "string[]",
90+
label: "Emails",
91+
description: "List of email entries. **Format: {\"type\":\"home\",\"value\":\"[email protected]\"}**. see [Create Email](https://developer.helpscout.com/mailbox-api/endpoints/customers/emails/create) for the object documentation.",
92+
optional: true,
93+
},
94+
phones: {
95+
type: "string[]",
96+
label: "Phones",
97+
description: "List of phone entries. **Format: {\"type\":\"work\",\"value\":\"222-333-4444\"}**. see [Create Phone](https://developer.helpscout.com/mailbox-api/endpoints/customers/phones/create) for the object documentation.",
98+
optional: true,
99+
},
100+
chats: {
101+
type: "string[]",
102+
label: "Chats",
103+
description: "List of chat entries. **Format: {\"type\":\"aim\",\"value\":\"jsprout\"}**. see [Create Chat Handle](https://developer.helpscout.com/mailbox-api/endpoints/customers/chat_handles/create) for the object documentation.",
104+
optional: true,
105+
},
106+
socialProfiles: {
107+
type: "string[]",
108+
label: "Social Profiles",
109+
description: "List of social profile entries. **Format: {\"type\":\"googleplus\",\"value\":\"https://api.helpscout.net/+HelpscoutNet\"}**. see [Create Social Profile](https://developer.helpscout.com/mailbox-api/endpoints/customers/social_profiles/create) for the object documentation.",
110+
optional: true,
111+
},
112+
websites: {
113+
type: "string[]",
114+
label: "Websites",
115+
description: "List of websites entries. **Format: {\"value\":\"https://api.helpscout.net/\"}**. see [Create Website](https://developer.helpscout.com/mailbox-api/endpoints/customers/websites/create) for the object documentation.",
116+
optional: true,
117+
},
118+
addressCity: {
119+
type: "string",
120+
label: "Address City",
121+
description: "The city of the customer.",
122+
optional: true,
123+
},
124+
addressState: {
125+
type: "string",
126+
label: "Address State",
127+
description: "The state of the customer.",
128+
optional: true,
129+
},
130+
addressPostalCode: {
131+
type: "string",
132+
label: "Address Postal Code",
133+
description: "The postal code of the customer.",
134+
optional: true,
135+
},
136+
addressCountry: {
137+
type: "string",
138+
label: "Address Country",
139+
description: "The [ISO 3166 Alpha-2 code](https://www.iban.com/country-codes) country of the customer.",
140+
optional: true,
141+
},
142+
addressLines: {
143+
type: "string[]",
144+
label: "Address Lines",
145+
description: "A list of address lines.",
146+
optional: true,
147+
},
148+
properties: {
149+
type: "string[]",
150+
label: "Properties",
151+
description: "List of social profile entries. **Format: {\"type\":\"googleplus\",\"value\":\"https://api.helpscout.net/+HelpscoutNet\"}**. see [Create Social Profile](https://developer.helpscout.com/mailbox-api/endpoints/customers/social_profiles/create) for the object documentation.",
152+
optional: true,
153+
},
154+
},
155+
async run({ $ }) {
156+
const address = cleanObject({
157+
city: this.addressCity,
158+
state: this.addressState,
159+
postalCode: this.addressPostalCode,
160+
country: this.addressCountry,
161+
lines: parseObject(this.addressLines),
162+
properties: parseObject(this.properties),
163+
});
164+
165+
let data = {};
166+
167+
data = cleanObject({
168+
firstName: this.firstName,
169+
lastName: this.lastName,
170+
phone: this.phone,
171+
photoUrl: this.photoUrl,
172+
jobTitle: this.jobTitle,
173+
photoType: this.photoType,
174+
background: this.background,
175+
location: this.location,
176+
organization: this.organization,
177+
gender: this.gender,
178+
age: this.age,
179+
emails: parseObject(this.emails),
180+
phones: parseObject(this.phones),
181+
chats: parseObject(this.chats),
182+
socialProfiles: parseObject(this.socialProfiles),
183+
websites: parseObject(this.websites),
184+
});
185+
186+
if (Object.keys(address).length) data.address = address;
187+
188+
if (!Object.keys(data).length) {
189+
throw new ConfigurationError("At least one field or customer entry must be defined.");
190+
}
191+
192+
try {
193+
const response = await this.helpScout.createCustomer({
194+
$,
195+
data,
196+
});
197+
198+
$.export("$summary", "Successfully created the new customer.");
199+
return response;
200+
} catch ({ message }) {
201+
const error = JSON.parse(message)._embedded.errors[0];
202+
throw new ConfigurationError(`Path: ${error.path} - ${error.message}`);
203+
}
204+
},
205+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import helpScout from "../../help_scout.app.mjs";
2+
3+
export default {
4+
key: "help_scout-send-reply",
5+
name: "Send Reply",
6+
description: "Sends a reply to a conversation. Be careful as this sends an actual email to the customer. [See the documentation](https://developer.helpscout.com/mailbox-api/endpoints/conversations/threads/reply/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
helpScout,
11+
conversationId: {
12+
propDefinition: [
13+
helpScout,
14+
"conversationId",
15+
],
16+
},
17+
customerId: {
18+
propDefinition: [
19+
helpScout,
20+
"customerId",
21+
],
22+
},
23+
text: {
24+
propDefinition: [
25+
helpScout,
26+
"text",
27+
],
28+
description: "The content of the reply.",
29+
},
30+
draft: {
31+
type: "boolean",
32+
label: "Draft",
33+
description: "If set to true, a draft reply is created.",
34+
default: false,
35+
},
36+
},
37+
async run({ $ }) {
38+
const response = await this.helpScout.sendReplyToConversation({
39+
$,
40+
conversationId: this.conversationId,
41+
data: {
42+
customer: {
43+
id: this.customerId,
44+
},
45+
text: this.text,
46+
draft: this.draft,
47+
},
48+
});
49+
50+
$.export("$summary", `Reply sent successfully to conversation ID: ${this.conversationId}`);
51+
return response;
52+
},
53+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export const PHOTO_TYPE_OPTIONS = [
2+
"unknown",
3+
"gravatar",
4+
"twitter",
5+
"facebook",
6+
"googleprofile",
7+
"googleplus",
8+
"linkedin",
9+
"instagram",
10+
];
11+
12+
export const GENDER_OPTIONS = [
13+
"male",
14+
"female",
15+
"unknown",
16+
];
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};
25+
26+
export const cleanObject = (o) => {
27+
for (var k in o || {}) {
28+
if (typeof o[k] === "undefined") {
29+
delete o[k];
30+
}
31+
}
32+
return o;
33+
};

0 commit comments

Comments
 (0)