|  | 
|  | 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.5", | 
|  | 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.", | 
|  | 46 | +      optional: true, | 
|  | 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: "integer", | 
|  | 130 | +      label: "Send Campaigns By Email", | 
|  | 131 | +      description: "The campaign contact email setting.", | 
|  | 132 | +      optional: true, | 
|  | 133 | +      options: [ | 
|  | 134 | +        { | 
|  | 135 | +          value: 1, | 
|  | 136 | +          label: "Yes", | 
|  | 137 | +        }, | 
|  | 138 | +        { | 
|  | 139 | +          value: 0, | 
|  | 140 | +          label: "No", | 
|  | 141 | +        }, | 
|  | 142 | +      ], | 
|  | 143 | +    }, | 
|  | 144 | +    campaignContactText: { | 
|  | 145 | +      type: "integer", | 
|  | 146 | +      label: "Send Campaigns By Text", | 
|  | 147 | +      description: "The campaign contact text setting.", | 
|  | 148 | +      optional: true, | 
|  | 149 | +      options: [ | 
|  | 150 | +        { | 
|  | 151 | +          value: 1, | 
|  | 152 | +          label: "Yes", | 
|  | 153 | +        }, | 
|  | 154 | +        { | 
|  | 155 | +          value: 0, | 
|  | 156 | +          label: "No", | 
|  | 157 | +        }, | 
|  | 158 | +      ], | 
|  | 159 | +    }, | 
|  | 160 | +    receiveMarketingEmail: { | 
|  | 161 | +      type: "integer", | 
|  | 162 | +      label: "Opted Into Email", | 
|  | 163 | +      description: "The receive marketing email setting.", | 
|  | 164 | +      optional: true, | 
|  | 165 | +      options: [ | 
|  | 166 | +        { | 
|  | 167 | +          value: 1, | 
|  | 168 | +          label: "Yes", | 
|  | 169 | +        }, | 
|  | 170 | +        { | 
|  | 171 | +          value: 0, | 
|  | 172 | +          label: "No", | 
|  | 173 | +        }, | 
|  | 174 | +      ], | 
|  | 175 | +    }, | 
|  | 176 | +    receiveMarketingText: { | 
|  | 177 | +      type: "integer", | 
|  | 178 | +      label: "Opted Into Text", | 
|  | 179 | +      description: "The receive marketing text setting.", | 
|  | 180 | +      optional: true, | 
|  | 181 | +      options: [ | 
|  | 182 | +        { | 
|  | 183 | +          value: 1, | 
|  | 184 | +          label: "Yes", | 
|  | 185 | +        }, | 
|  | 186 | +        { | 
|  | 187 | +          value: 0, | 
|  | 188 | +          label: "No", | 
|  | 189 | +        }, | 
|  | 190 | +      ], | 
|  | 191 | +    }, | 
|  | 192 | +    tagsToAdd: { | 
|  | 193 | +      type: "string[]", | 
|  | 194 | +      label: "Tags to Add", | 
|  | 195 | +      description: "Tags to add to the contact.", | 
|  | 196 | +      propDefinition: [ | 
|  | 197 | +        app, | 
|  | 198 | +        "tag", | 
|  | 199 | +      ], | 
|  | 200 | +    }, | 
|  | 201 | +    tagsToRemove: { | 
|  | 202 | +      type: "string[]", | 
|  | 203 | +      label: "Tags to Remove", | 
|  | 204 | +      description: "Tags to remove from the contact.", | 
|  | 205 | +      propDefinition: [ | 
|  | 206 | +        app, | 
|  | 207 | +        "tag", | 
|  | 208 | +      ], | 
|  | 209 | +    }, | 
|  | 210 | +    campaignsToAdd: { | 
|  | 211 | +      type: "string[]", | 
|  | 212 | +      label: "Campaigns to Add", | 
|  | 213 | +      description: "If a contact isn't already receiving a campaign, start sending these campaigns to them.", | 
|  | 214 | +      propDefinition: [ | 
|  | 215 | +        app, | 
|  | 216 | +        "campaignId", | 
|  | 217 | +      ], | 
|  | 218 | +    }, | 
|  | 219 | +    campaignsToAddOrRestart: { | 
|  | 220 | +      type: "string[]", | 
|  | 221 | +      label: "Campaigns to Add or Restart", | 
|  | 222 | +      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.", | 
|  | 223 | +      propDefinition: [ | 
|  | 224 | +        app, | 
|  | 225 | +        "campaignId", | 
|  | 226 | +      ], | 
|  | 227 | +    }, | 
|  | 228 | +    campaignsToRemove: { | 
|  | 229 | +      type: "string[]", | 
|  | 230 | +      label: "Campaigns to Remove", | 
|  | 231 | +      description: "Campaigns to remove from the contact.", | 
|  | 232 | +      propDefinition: [ | 
|  | 233 | +        app, | 
|  | 234 | +        "campaignId", | 
|  | 235 | +      ], | 
|  | 236 | +    }, | 
|  | 237 | +    offlineCampaignsToAdd: { | 
|  | 238 | +      type: "string[]", | 
|  | 239 | +      label: "Offline Campaigns To Add", | 
|  | 240 | +      description: "Offline campaigns to add to the contact.", | 
|  | 241 | +      propDefinition: [ | 
|  | 242 | +        app, | 
|  | 243 | +        "campaignId", | 
|  | 244 | +      ], | 
|  | 245 | +    }, | 
|  | 246 | +    offlineCampaignsToRemove: { | 
|  | 247 | +      type: "string[]", | 
|  | 248 | +      label: "Offline Campaigns To Remove", | 
|  | 249 | +      description: "Offline campaigns to remove from the contact.", | 
|  | 250 | +      propDefinition: [ | 
|  | 251 | +        app, | 
|  | 252 | +        "campaignId", | 
|  | 253 | +      ], | 
|  | 254 | +    }, | 
|  | 255 | +    addToVaults: { | 
|  | 256 | +      type: "string[]", | 
|  | 257 | +      label: "Add To Vaults", | 
|  | 258 | +      description: "Give Access To Vault (Contact Still Must Pay For Paid Vaults).", | 
|  | 259 | +      propDefinition: [ | 
|  | 260 | +        app, | 
|  | 261 | +        "vaultId", | 
|  | 262 | +      ], | 
|  | 263 | +    }, | 
|  | 264 | +    addToVaultsForFree: { | 
|  | 265 | +      type: "string[]", | 
|  | 266 | +      label: "Add To Vaults For Free", | 
|  | 267 | +      description: "Give Access To Vault For Free (Contact Gets Free Access To Paid Vaults).", | 
|  | 268 | +      propDefinition: [ | 
|  | 269 | +        app, | 
|  | 270 | +        "vaultId", | 
|  | 271 | +      ], | 
|  | 272 | +    }, | 
|  | 273 | +    removeFromVaults: { | 
|  | 274 | +      type: "string[]", | 
|  | 275 | +      label: "Remove from Vaults", | 
|  | 276 | +      description: "Vaults to remove the contact from.", | 
|  | 277 | +      propDefinition: [ | 
|  | 278 | +        app, | 
|  | 279 | +        "vaultId", | 
|  | 280 | +      ], | 
|  | 281 | +    }, | 
|  | 282 | +    automationsToRun: { | 
|  | 283 | +      type: "string[]", | 
|  | 284 | +      label: "Automations To Run", | 
|  | 285 | +      description: "Automations to run for the contact.", | 
|  | 286 | +      propDefinition: [ | 
|  | 287 | +        app, | 
|  | 288 | +        "automationId", | 
|  | 289 | +      ], | 
|  | 290 | +    }, | 
|  | 291 | +  }, | 
|  | 292 | +  methods: { | 
|  | 293 | +    createOrUpdateContact(args = {}) { | 
|  | 294 | +      return this.app.post({ | 
|  | 295 | +        path: "/contacts", | 
|  | 296 | +        ...args, | 
|  | 297 | +      }); | 
|  | 298 | +    }, | 
|  | 299 | +  }, | 
|  | 300 | +  async run({ $ }) { | 
|  | 301 | +    const { | 
|  | 302 | +      createOrUpdateContact, | 
|  | 303 | +      email, | 
|  | 304 | +      mobilePhone, | 
|  | 305 | +      firstName, | 
|  | 306 | +      lastName, | 
|  | 307 | +      contactType, | 
|  | 308 | +      rating, | 
|  | 309 | +      workPhone, | 
|  | 310 | +      homePhone, | 
|  | 311 | +      address1, | 
|  | 312 | +      city, | 
|  | 313 | +      state, | 
|  | 314 | +      postalCode, | 
|  | 315 | +      country, | 
|  | 316 | +      companyName, | 
|  | 317 | +      title, | 
|  | 318 | +      campaignContactEmail, | 
|  | 319 | +      campaignContactText, | 
|  | 320 | +      receiveMarketingEmail, | 
|  | 321 | +      receiveMarketingText, | 
|  | 322 | +      tagsToAdd, | 
|  | 323 | +      tagsToRemove, | 
|  | 324 | +      campaignsToAdd, | 
|  | 325 | +      campaignsToRemove, | 
|  | 326 | +      offlineCampaignsToAdd, | 
|  | 327 | +      offlineCampaignsToRemove, | 
|  | 328 | +      addToVaults, | 
|  | 329 | +      addToVaultsForFree, | 
|  | 330 | +      removeFromVaults, | 
|  | 331 | +      automationsToRun, | 
|  | 332 | +      campaignsToAddOrRestart, | 
|  | 333 | +    } = this; | 
|  | 334 | + | 
|  | 335 | +    if (!email && !mobilePhone) { | 
|  | 336 | +      throw new ConfigurationError("Either **Email** or **Mobile Phone** is required."); | 
|  | 337 | +    } | 
|  | 338 | + | 
|  | 339 | +    const response = await createOrUpdateContact({ | 
|  | 340 | +      $, | 
|  | 341 | +      headers: { | 
|  | 342 | +        "X-TAGS-TO-ADD": tagsToAdd, | 
|  | 343 | +        "X-AUTOMATIONS-TO-RUN": automationsToRun, | 
|  | 344 | +      }, | 
|  | 345 | +      data: { | 
|  | 346 | +        email, | 
|  | 347 | +        mobile_phone: mobilePhone, | 
|  | 348 | +        first_name: firstName, | 
|  | 349 | +        last_name: lastName, | 
|  | 350 | +        contact_type: contactType, | 
|  | 351 | +        rating, | 
|  | 352 | +        work_phone: workPhone, | 
|  | 353 | +        home_phone: homePhone, | 
|  | 354 | +        address1, | 
|  | 355 | +        city, | 
|  | 356 | +        state, | 
|  | 357 | +        postal_code: postalCode, | 
|  | 358 | +        country, | 
|  | 359 | +        company_name: companyName, | 
|  | 360 | +        title, | 
|  | 361 | +        campaign_contact_email: campaignContactEmail, | 
|  | 362 | +        campaign_contact_text: campaignContactText, | 
|  | 363 | +        receive_marketing_email: receiveMarketingEmail, | 
|  | 364 | +        receive_marketing_text: receiveMarketingText, | 
|  | 365 | +        tags_to_add: tagsToAdd, | 
|  | 366 | +        tags_to_remove: tagsToRemove, | 
|  | 367 | +        campaigns_to_add: campaignsToAdd, | 
|  | 368 | +        campaigns_to_remove: campaignsToRemove, | 
|  | 369 | +        offline_campaigns_to_add: offlineCampaignsToAdd, | 
|  | 370 | +        offline_campaigns_to_remove: offlineCampaignsToRemove, | 
|  | 371 | +        add_to_vaults: addToVaults, | 
|  | 372 | +        add_to_vaults_for_free: addToVaultsForFree, | 
|  | 373 | +        remove_from_vaults: removeFromVaults, | 
|  | 374 | +        automations_to_run: automationsToRun, | 
|  | 375 | +        campaigns_to_add_or_restart: campaignsToAddOrRestart, | 
|  | 376 | +      }, | 
|  | 377 | +    }); | 
|  | 378 | +    $.export("$summary", "Successfully created or updated contact."); | 
|  | 379 | +    return response; | 
|  | 380 | +  }, | 
|  | 381 | +}; | 
0 commit comments