Skip to content

Commit

Permalink
Website: update contact form CRM records (#20645)
Browse files Browse the repository at this point in the history
Closes: fleetdm/confidential#7394

Changes:
- Updated update-or-create-contact-and-account to set descriptions on
contacts
- Updated deliver-talk-to-us-form-submissions to not create leads for
users sent to the "Lets get you set up!" event
- Updated deliver-contact-form-message to only create contact records.
  • Loading branch information
eashaw authored Jul 22, 2024
1 parent c762ac4 commit adf1405
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
4 changes: 2 additions & 2 deletions website/api/controllers/deliver-contact-form-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ module.exports = {
`Name: ${firstName + ' ' + lastName}, Email: ${emailAddress}, Message: ${message ? message : 'No message.'}`
});

sails.helpers.salesforce.updateOrCreateContactAndAccountAndCreateLead.with({
sails.helpers.salesforce.updateOrCreateContactAndAccount.with({
emailAddress: emailAddress,
firstName: firstName,
lastName: lastName,
leadSource: 'Website - Contact forms',
leadDescription: `Sent a contact form message: ${message}`,
description: `Sent a contact form message: ${message}`,
}).exec((err)=>{// Use .exec() to run the salesforce helpers in the background.
if(err) {
sails.log.warn(`Background task failed: When a user submitted a contact form message, a lead/contact could not be updated in the CRM for this email address: ${emailAddress}.`, err);
Expand Down
45 changes: 30 additions & 15 deletions website/api/controllers/deliver-talk-to-us-form-submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,36 @@ module.exports = {
throw 'invalidEmailDomain';
}


sails.helpers.salesforce.updateOrCreateContactAndAccountAndCreateLead.with({
emailAddress: emailAddress,
firstName: firstName,
lastName: lastName,
organization: organization,
numberOfHosts: numberOfHosts,
primaryBuyingSituation: primaryBuyingSituation === 'eo-security' ? 'Endpoint operations - Security' : primaryBuyingSituation === 'eo-it' ? 'Endpoint operations - IT' : primaryBuyingSituation === 'mdm' ? 'Device management (MDM)' : primaryBuyingSituation === 'vm' ? 'Vulnerability management' : undefined,
leadSource: 'Website - Contact forms',
leadDescription: `Submitted the "Talk to us" form and was taken to the Calendly page for the "${numberOfHosts > 700 ? 'Talk to us' : 'Let\'s get you set up!'}" event.`,
}).exec((err)=>{
if(err) {
sails.log.warn(`Background task failed: When a user submitted the "Talk to us" form, a lead/contact could not be updated in the CRM for this email address: ${emailAddress}.`, err);
}
});
if(numberOfHosts >= 700){
sails.helpers.salesforce.updateOrCreateContactAndAccountAndCreateLead.with({
emailAddress: emailAddress,
firstName: firstName,
lastName: lastName,
organization: organization,
numberOfHosts: numberOfHosts,
primaryBuyingSituation: primaryBuyingSituation === 'eo-security' ? 'Endpoint operations - Security' : primaryBuyingSituation === 'eo-it' ? 'Endpoint operations - IT' : primaryBuyingSituation === 'mdm' ? 'Device management (MDM)' : primaryBuyingSituation === 'vm' ? 'Vulnerability management' : undefined,
leadSource: 'Website - Contact forms',
leadDescription: `Submitted the "Talk to us" form and was taken to the Calendly page for the "Talk to us" event.`,
}).exec((err)=>{
if(err) {
sails.log.warn(`Background task failed: When a user submitted the "Talk to us" form, a lead/contact could not be updated in the CRM for this email address: ${emailAddress}.`, err);
}
});
} else {
sails.helpers.salesforce.updateOrCreateContactAndAccount.with({
emailAddress: emailAddress,
firstName: firstName,
lastName: lastName,
organization: organization,
primaryBuyingSituation: primaryBuyingSituation === 'eo-security' ? 'Endpoint operations - Security' : primaryBuyingSituation === 'eo-it' ? 'Endpoint operations - IT' : primaryBuyingSituation === 'mdm' ? 'Device management (MDM)' : primaryBuyingSituation === 'vm' ? 'Vulnerability management' : undefined,
leadSource: 'Website - Contact forms',
description: `Submitted the "Talk to us" form and was taken to the Calendly page for the "Let\'s get you set up!" event.`,
}).exec((err)=>{
if(err) {
sails.log.warn(`Background task failed: When a user submitted the "Talk to us" form, a lead/contact could not be updated in the CRM for this email address: ${emailAddress}.`, err);
}
});
}

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ module.exports = {
primaryBuyingSituation,
psychologicalStage,
leadSource,
description: leadDescription,
});

await sails.helpers.salesforce.createLead.with({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
firstName: { type: 'string', required: true },
lastName: { type: 'string', required: true },
organization: { type: 'string' },
description: { type: 'string' },
primaryBuyingSituation: { type: 'string' },
psychologicalStage: {
type: 'string',
Expand Down Expand Up @@ -51,7 +52,7 @@ module.exports = {
},


fn: async function ({emailAddress, linkedinUrl, firstName, lastName, organization, primaryBuyingSituation, psychologicalStage, leadSource}) {
fn: async function ({emailAddress, linkedinUrl, firstName, lastName, organization, primaryBuyingSituation, psychologicalStage, leadSource, description}) {
// Return undefined if we're not running in a production environment.
if(sails.config.environment !== 'production') {
sails.log.verbose('Skipping Salesforce integration...');
Expand Down Expand Up @@ -95,6 +96,9 @@ module.exports = {
if(psychologicalStage) {
valuesToSet.Stage__c = psychologicalStage;// eslint-disable-line camelcase
}
if(description) {
valuesToSet.Description = description;
}

let existingContactRecord;
// Search for an existing Contact record using the provided email address or linkedIn profile URL.
Expand All @@ -111,6 +115,10 @@ module.exports = {
}

if(existingContactRecord) {
// If a description was provided and the contact has a description, append the new description to it.
if(description && existingContactRecord.Description) {
valuesToSet.Description = existingContactRecord.Description + '\n' + description;
}
// console.log(`Exisitng contact found! ${existingContactRecord.Id}`);
// If we found an existing contact, we'll update it with the information provided.
salesforceContactId = existingContactRecord.Id;
Expand Down

0 comments on commit adf1405

Please sign in to comment.