Skip to content

Commit 41e54a5

Browse files
committed
[Components] attractwell - WIP
1 parent c47457c commit 41e54a5

File tree

12 files changed

+853
-8
lines changed

12 files changed

+853
-8
lines changed
Lines changed: 356 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,356 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import app from "../../attractwell.app.mjs";
3+
4+
export default {
5+
key: "attractwell-create-update-contact",
6+
name: "Create or Update Contact",
7+
description: "Creates or updates a contact with the provided identification and contact details.",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
email: {
13+
type: "string",
14+
label: "Email",
15+
description: "The email address of the contact.",
16+
optional: true,
17+
},
18+
mobilePhone: {
19+
type: "string",
20+
label: "Mobile Phone",
21+
description: "The mobile phone number of the contact.",
22+
optional: true,
23+
},
24+
firstName: {
25+
type: "string",
26+
label: "First Name",
27+
description: "The first name of the contact.",
28+
optional: true,
29+
},
30+
lastName: {
31+
type: "string",
32+
label: "Last Name",
33+
description: "The last name of the contact.",
34+
optional: true,
35+
},
36+
contactType: {
37+
type: "string",
38+
label: "Contact Type",
39+
description: "The type of the contact.",
40+
optional: true,
41+
},
42+
rating: {
43+
type: "string",
44+
label: "Rating",
45+
description: "The rating of the contact. From `0` (coldest) to `5` (hottest). You'll get periodic reminders of which contacts to reach out to more often if you choose a higher rating, or not at all if you pick `0`.",
46+
default: "0",
47+
options: [
48+
{
49+
value: "0",
50+
label: "No reminders",
51+
},
52+
{
53+
value: "1",
54+
label: "Annual reminders",
55+
},
56+
{
57+
value: "2",
58+
label: "Quarterly reminders",
59+
},
60+
{
61+
value: "3",
62+
label: "Monthly reminders",
63+
},
64+
{
65+
value: "4",
66+
label: "Weekly reminders",
67+
},
68+
{
69+
value: "5",
70+
label: "Reminders every 3 days",
71+
},
72+
],
73+
},
74+
workPhone: {
75+
type: "string",
76+
label: "Work Phone",
77+
description: "The work phone number of the contact.",
78+
optional: true,
79+
},
80+
homePhone: {
81+
type: "string",
82+
label: "Home Phone",
83+
description: "The home phone number of the contact.",
84+
optional: true,
85+
},
86+
address1: {
87+
type: "string",
88+
label: "Street Address",
89+
description: "The street address of the contact.",
90+
optional: true,
91+
},
92+
city: {
93+
type: "string",
94+
label: "City",
95+
description: "The city of the contact.",
96+
optional: true,
97+
},
98+
state: {
99+
type: "string",
100+
label: "State",
101+
description: "The state of the contact.",
102+
optional: true,
103+
},
104+
postalCode: {
105+
type: "string",
106+
label: "Postal Code",
107+
description: "The postal code of the contact.",
108+
optional: true,
109+
},
110+
country: {
111+
type: "string",
112+
label: "Country",
113+
description: "The country of the contact.",
114+
optional: true,
115+
},
116+
companyName: {
117+
type: "string",
118+
label: "Company Name",
119+
description: "The company name of the contact.",
120+
optional: true,
121+
},
122+
title: {
123+
type: "string",
124+
label: "Title",
125+
description: "The title of the contact.",
126+
optional: true,
127+
},
128+
campaignContactEmail: {
129+
type: "boolean",
130+
label: "Send Campaigns By Email",
131+
description: "The campaign contact email setting.",
132+
default: true,
133+
},
134+
campaignContactText: {
135+
type: "boolean",
136+
label: "Send Campaigns By Text",
137+
description: "The campaign contact text setting.",
138+
default: false,
139+
},
140+
receiveMarketingEmail: {
141+
type: "boolean",
142+
label: "Opted Into Email",
143+
description: "The receive marketing email setting.",
144+
default: true,
145+
},
146+
receiveMarketingText: {
147+
type: "boolean",
148+
label: "Opted Into Text",
149+
description: "The receive marketing text setting.",
150+
default: true,
151+
},
152+
tagsToAdd: {
153+
type: "string[]",
154+
label: "Tags to Add",
155+
description: "Tags to add to the contact.",
156+
propDefinition: [
157+
app,
158+
"tag",
159+
],
160+
},
161+
tagsToRemove: {
162+
type: "string[]",
163+
label: "Tags to Remove",
164+
description: "Tags to remove from the contact.",
165+
propDefinition: [
166+
app,
167+
"tag",
168+
],
169+
},
170+
campaignsToAdd: {
171+
type: "string[]",
172+
label: "Campaigns to Add",
173+
description: "If a contact isn't already receiving a campaign, start sending these campaigns to them.",
174+
propDefinition: [
175+
app,
176+
"campaignId",
177+
],
178+
},
179+
campaignsToAddOrRestart: {
180+
type: "string[]",
181+
label: "Campaigns to Add or Restart",
182+
description: "If a contact is already receiving a campaign, restart these campaigns. If a contact is not receiving a campaign, start sending these campaigns to them.",
183+
propDefinition: [
184+
app,
185+
"campaignId",
186+
],
187+
},
188+
campaignsToRemove: {
189+
type: "string[]",
190+
label: "Campaigns to Remove",
191+
description: "Campaigns to remove from the contact.",
192+
propDefinition: [
193+
app,
194+
"campaignId",
195+
],
196+
},
197+
offlineCampaignsToAdd: {
198+
type: "string[]",
199+
label: "Offline Campaigns To Add",
200+
description: "Offline campaigns to add to the contact.",
201+
propDefinition: [
202+
app,
203+
"campaignId",
204+
],
205+
},
206+
offlineCampaignsToRemove: {
207+
type: "string[]",
208+
label: "Offline Campaigns To Remove",
209+
description: "Offline campaigns to remove from the contact.",
210+
propDefinition: [
211+
app,
212+
"campaignId",
213+
],
214+
},
215+
addToVaults: {
216+
type: "string[]",
217+
label: "Add To Vaults",
218+
description: "Give Access To Vault (Contact Still Must Pay For Paid Vaults).",
219+
propDefinition: [
220+
app,
221+
"vaultId",
222+
],
223+
},
224+
addToVaultsForFree: {
225+
type: "string[]",
226+
label: "Add To Vaults For Free",
227+
description: "Give Access To Vault For Free (Contact Gets Free Access To Paid Vaults).",
228+
propDefinition: [
229+
app,
230+
"vaultId",
231+
],
232+
},
233+
removeFromVaults: {
234+
type: "string[]",
235+
label: "Remove from Vaults",
236+
description: "Vaults to remove the contact from.",
237+
propDefinition: [
238+
app,
239+
"vaultId",
240+
],
241+
},
242+
automationsToRun: {
243+
type: "string[]",
244+
label: "Automations To Run",
245+
description: "Automations to run for the contact.",
246+
propDefinition: [
247+
app,
248+
"automationId",
249+
],
250+
},
251+
mayAccessMemberArea: {
252+
type: "boolean",
253+
label: "May Access Member Area",
254+
description: "Whether the user may access or is banned from the member area. If this is set to `true`, they only are able to access the member area if they are also assigned to one or more vaults.",
255+
default: true,
256+
},
257+
},
258+
methods: {
259+
fromBooleanToInt(value) {
260+
return value === true
261+
? 1
262+
: 0;
263+
},
264+
createOrUpdateContact(args = {}) {
265+
return this.app.post({
266+
path: "/contacts",
267+
...args,
268+
});
269+
},
270+
},
271+
async run({ $ }) {
272+
const {
273+
fromBooleanToInt,
274+
createOrUpdateContact,
275+
email,
276+
mobilePhone,
277+
firstName,
278+
lastName,
279+
contactType,
280+
rating,
281+
workPhone,
282+
homePhone,
283+
address1,
284+
city,
285+
state,
286+
postalCode,
287+
country,
288+
companyName,
289+
title,
290+
campaignContactEmail,
291+
campaignContactText,
292+
receiveMarketingEmail,
293+
receiveMarketingText,
294+
tagsToAdd,
295+
tagsToRemove,
296+
campaignsToAdd,
297+
campaignsToRemove,
298+
offlineCampaignsToAdd,
299+
offlineCampaignsToRemove,
300+
addToVaults,
301+
addToVaultsForFree,
302+
removeFromVaults,
303+
automationsToRun,
304+
campaignsToAddOrRestart,
305+
mayAccessMemberArea,
306+
} = this;
307+
308+
if (!email && !mobilePhone) {
309+
throw new ConfigurationError("Either **Email** or **Mobile Phone** is required.");
310+
}
311+
312+
const response = await createOrUpdateContact({
313+
$,
314+
// headers: {
315+
// "X-TAGS-TO-ADD": tagsToAdd,
316+
// "X-AUTOMATIONS-TO-RUN": automationsToRun,
317+
// },
318+
data: {
319+
contact_source: "API",
320+
email,
321+
mobile_phone: mobilePhone,
322+
first_name: firstName,
323+
last_name: lastName,
324+
contact_type: contactType,
325+
rating: parseInt(rating, 10),
326+
work_phone: workPhone,
327+
home_phone: homePhone,
328+
address1,
329+
city,
330+
state,
331+
postal_code: postalCode,
332+
country,
333+
company_name: companyName,
334+
title,
335+
campaign_contact_email: fromBooleanToInt(campaignContactEmail),
336+
campaign_contact_text: fromBooleanToInt(campaignContactText),
337+
receive_marketing_email: fromBooleanToInt(receiveMarketingEmail),
338+
receive_marketing_text: fromBooleanToInt(receiveMarketingText),
339+
tags_to_add: tagsToAdd,
340+
tags_to_remove: tagsToRemove,
341+
campaigns_to_add: campaignsToAdd,
342+
campaigns_to_remove: campaignsToRemove,
343+
offline_campaigns_to_add: offlineCampaignsToAdd,
344+
offline_campaigns_to_remove: offlineCampaignsToRemove,
345+
add_to_vaults: addToVaults,
346+
add_to_vaults_for_free: addToVaultsForFree,
347+
remove_from_vaults: removeFromVaults,
348+
automations_to_run: automationsToRun,
349+
campaigns_to_add_or_restart: campaignsToAddOrRestart,
350+
may_access_member_area: fromBooleanToInt(mayAccessMemberArea),
351+
},
352+
});
353+
$.export("$summary", "Successfully created or updated contact.");
354+
return response;
355+
},
356+
};

0 commit comments

Comments
 (0)