Skip to content

Commit 11993f1

Browse files
committed
[Components] help_scout #14608
Sources - New Conversation Assigned (Instant) - New Conversation Created (Instant) - New Customer (Instant) Actions - Add Note - Create Customer - Send Reply
1 parent bd10277 commit 11993f1

File tree

15 files changed

+843
-443
lines changed

15 files changed

+843
-443
lines changed

components/help_scout/actions/add-note/add-note.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,22 @@ export default {
2020
"text",
2121
],
2222
},
23+
userId: {
24+
propDefinition: [
25+
helpScout,
26+
"userId",
27+
],
28+
optional: true,
29+
},
2330
},
2431
async run({ $ }) {
2532
const response = await this.helpScout.addNoteToConversation({
33+
$,
2634
conversationId: this.conversationId,
27-
text: this.text,
35+
data: {
36+
text: this.text,
37+
user: this.userId,
38+
},
2839
});
2940
$.export("$summary", `Successfully added note to conversation ID: ${this.conversationId}`);
3041
return response;
Lines changed: 186 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,203 @@
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";
110
import helpScout from "../../help_scout.app.mjs";
211

312
export default {
413
key: "help_scout-create-customer",
514
name: "Create Customer",
615
description: "Creates a new customer record in Help Scout. [See the documentation](https://developer.helpscout.com/mailbox-api/endpoints/customers/create/)",
7-
version: "0.0.{{ts}}",
16+
version: "0.0.1",
817
type: "action",
918
props: {
1019
helpScout,
11-
customerEmail: {
12-
propDefinition: [
13-
helpScout,
14-
"customerEmail",
15-
],
16-
},
17-
customerPhone: {
18-
propDefinition: [
19-
helpScout,
20-
"customerPhone",
21-
],
22-
},
23-
chatHandles: {
24-
propDefinition: [
25-
helpScout,
26-
"chatHandles",
27-
],
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,
28105
},
29106
socialProfiles: {
30-
propDefinition: [
31-
helpScout,
32-
"socialProfiles",
33-
],
34-
},
35-
customerAddress: {
36-
propDefinition: [
37-
helpScout,
38-
"customerAddress",
39-
],
40-
},
41-
customerDetails: {
42-
propDefinition: [
43-
helpScout,
44-
"customerDetails",
45-
],
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,
46153
},
47154
},
48155
async run({ $ }) {
49-
const response = await this.helpScout.createCustomer({
50-
customerEmail: this.customerEmail,
51-
customerPhone: this.customerPhone,
52-
chatHandles: this.chatHandles,
53-
socialProfiles: this.socialProfiles,
54-
customerAddress: this.customerAddress,
55-
...this.customerDetails,
56-
});
156+
try {
157+
const address = cleanObject({
158+
city: this.addressCity,
159+
state: this.addressState,
160+
postalCode: this.addressPostalCode,
161+
country: this.addressCountry,
162+
lines: parseObject(this.addressLines),
163+
properties: parseObject(this.properties),
164+
});
165+
166+
const data = cleanObject({
167+
firstName: this.firstName,
168+
lastName: this.lastName,
169+
phone: this.phone,
170+
photoUrl: this.photoUrl,
171+
jobTitle: this.jobTitle,
172+
photoType: this.photoType,
173+
background: this.background,
174+
location: this.location,
175+
organization: this.organization,
176+
gender: this.gender,
177+
age: this.age,
178+
emails: parseObject(this.emails),
179+
phones: parseObject(this.phones),
180+
chats: parseObject(this.chats),
181+
socialProfiles: parseObject(this.socialProfiles),
182+
websites: parseObject(this.websites),
183+
});
184+
185+
if (Object.keys(address).length) data.address = address;
186+
187+
if (!Object.keys(data).length) {
188+
throw new ConfigurationError("At least one field or customer entry must be defined.");
189+
}
190+
191+
const response = await this.helpScout.createCustomer({
192+
$,
193+
data,
194+
});
195+
196+
$.export("$summary", "Successfully created the new customer.");
197+
return response;
57198

58-
$.export("$summary", `Successfully created customer with email: ${this.customerEmail}`);
59-
return response;
199+
} catch ({ response }) {
200+
throw new ConfigurationError(response.data.message);
201+
}
60202
},
61203
};

components/help_scout/actions/send-reply/send-reply.mjs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import helpScout from "../../help_scout.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "help_scout-send-reply",
@@ -15,17 +14,37 @@ export default {
1514
"conversationId",
1615
],
1716
},
17+
customerId: {
18+
propDefinition: [
19+
helpScout,
20+
"customerId",
21+
],
22+
},
1823
text: {
1924
propDefinition: [
2025
helpScout,
2126
"text",
2227
],
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,
2335
},
2436
},
2537
async run({ $ }) {
2638
const response = await this.helpScout.sendReplyToConversation({
39+
$,
2740
conversationId: this.conversationId,
28-
text: this.text,
41+
data: {
42+
customer: {
43+
id: this.customerId,
44+
},
45+
text: this.text,
46+
draft: this.draft,
47+
},
2948
});
3049

3150
$.export("$summary", `Reply sent successfully to conversation ID: ${this.conversationId}`);
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)