/// <summary> /// Creates an event structure containing a CanonicalContact, suitable for passing to an EventGrid topic /// </summary> public NewContactEvent(string eventId, CanonicalContact hubSpotContact) { this.id = eventId; this.eventType = "NewContact"; subject = "Starling.Crm.ContactCreated"; this.eventTime = DateTime.UtcNow; data = new NewContactPayload(hubSpotContact); }
public UpdatedContactEvent(string id, CanonicalContact hubspotContact) { this.id = id; this.subject = "Starling.Crm.ContactUpdated"; this.eventTime = DateTime.UtcNow; this.data = hubspotContact; if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } this.eventType = "ContactProperties"; }
public NewContactPayload(CanonicalContact hubspotContact) { this.contactId = hubspotContact.contactId; this.firstName = hubspotContact.firstName; this.lastName = hubspotContact.lastName; this.preferredName = hubspotContact.preferredName; this.phone = hubspotContact.phone; this.email = hubspotContact.email; this.streetAddress = hubspotContact.streetAddress; this.city = hubspotContact.city; this.state = hubspotContact.state; this.postcode = hubspotContact.postcode; this.customerAddress = hubspotContact.customerAddress; this.leadStatus = hubspotContact.leadStatus; this.installationRecordExists = hubspotContact.installationRecordExists; this.restUri = hubspotContact.restUri; }
public HubSpotContactResult(CanonicalContact contact) : base(HttpStatusCode.OK) { this.Payload = contact; }
/// <summary> /// Converts a raw Hubspot API response into a generic Contact structure with the properties that we care about /// </summary> /// <param name="wholeContactText">The raw response body from the API call</param> /// <param name="fetchPreviousValues"></param> /// <returns></returns> private static CanonicalContact ConvertHubspotJsonToCanonicalContact( string wholeContactText, bool fetchPreviousValues, ILogger log) { dynamic contact = ConvertStringToJson(wholeContactText); string vid = contact.vid; string firstName = contact.properties.firstname?.value; string lastName = contact.properties.lastname?.value; string preferredName = contact.properties.preferred_name?.value; string phone = contact.properties.phone?.value; string email = contact.properties.email?.value; string streetAddress = contact.properties.address?.value; string city = contact.properties.city?.value; string state = contact.properties.state?.value; string postcode = contact.properties.zip?.value; string customerAddress = AssembleCustomerAddress(contact.properties); string leadStatus = contact.properties.hs_lead_status?.value; string installationrecordString = contact.properties.installationrecordexists?.value ?? "false"; // raw values are null, "false", "true" and "" bool installationrecordExists = (installationrecordString == "true"); // Default the previous values to the current values var oldFirstName = firstName; var oldLastName = lastName; var oldPreferredName = preferredName; var oldPhone = phone; var oldEmail = email; var oldStreetAddress = streetAddress; var oldCity = city; var oldState = state; var oldPostcode = postcode; var oldCustomerAddress = customerAddress; var oldLeadStatus = leadStatus; var restUri = contact["profile-url"].ToString(); if (fetchPreviousValues) { oldFirstName = GetPreviousValue(contact.properties.firstname); oldLastName = GetPreviousValue(contact.properties.lastname); oldPreferredName = GetPreviousValue(contact.properties.preferred_name); oldPhone = GetPreviousValue(contact.properties.phone); oldEmail = GetPreviousValue(contact.properties.email); oldStreetAddress = GetPreviousValue(contact.properties.address); oldCity = GetPreviousValue(contact.properties.city); oldState = GetPreviousValue(contact.properties.state); oldPostcode = GetPreviousValue(contact.properties.zip); oldCustomerAddress = AssembleCustomerAddress(contact.properties, true); oldLeadStatus = GetPreviousValue(contact.properties.hs_lead_status); } log.LogInformation($"CanonicalContact({contact.vid},{firstName},{lastName},{preferredName},{phone},{email},{customerAddress},{leadStatus})"); var canonicalContact = new CanonicalContact( vid, firstName, lastName, preferredName, phone, email, streetAddress, city, state, postcode, customerAddress, leadStatus, installationrecordExists) { oldFirstName = oldFirstName, oldLastName = oldLastName, oldPreferredName = oldPreferredName, oldPhone = oldPhone, oldEmail = oldEmail, oldStreetAddress = oldStreetAddress, oldCity = oldCity, oldState = oldState, oldPostcode = oldPostcode, oldcustomerAddress = oldCustomerAddress, oldLeadStatus = oldLeadStatus, restUri = restUri }; return(canonicalContact); }