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