Website: update deliver-contact-form-message (#38640)

Changes:
- Updated the deliver-contact-form-message action to attempt to
create/update CRM records before it sends a contact form email.
This commit is contained in:
Eric 2026-01-22 11:48:48 -06:00 committed by GitHub
parent 2d03130c46
commit 16e8d48396
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -76,6 +76,42 @@ module.exports = {
);
}
let attributionCookieOrUndefined = this.req.cookies.marketingAttribution;
await sails.helpers.flow.build(async ()=>{
let recordIds = await sails.helpers.salesforce.updateOrCreateContactAndAccount.with({
emailAddress: emailAddress,
firstName: firstName,
lastName: lastName,
contactSource: 'Website - Contact forms',
description: `Sent a contact form message: ${message}`,
marketingAttributionCookie: attributionCookieOrUndefined
}).intercept((err)=>{
return new Error(`Could not create/update a contact or account. Full error: ${require('util').inspect(err)}`);
});
// If the Contact record returned by the updateOrCreateContactAndAccount does not have a parent Account record, throw an error to stop the build helper.
if(!recordIds.salesforceAccountId) {
throw new Error(`Could not create historical event. The contact record (ID: ${recordIds.salesforceContactId}) returned by the updateOrCreateContactAndAccount helper is missing a parent account record.`);
}
// Create the new Fleet website page view record.
await sails.helpers.salesforce.createHistoricalEvent.with({
salesforceAccountId: recordIds.salesforceAccountId,
salesforceContactId: recordIds.salesforceContactId,
eventType: 'Intent signal',
intentSignal: 'Submitted the "Send a message" form',
eventContent: message,
}).intercept((err)=>{
return new Error(`Could not create an historical event. Full error: ${require('util').inspect(err)}`);
});
}).tolerate((err)=>{
if(err) {
sails.log.warn(`When a user submitted a contact form message, a contact/account/historical event could not be created/updated in the CRM for this email address: ${emailAddress}. Full error: ${require('util').inspect(err)}`);
}
return;
});
let subject = 'New contact form message';
if(userHasPremiumSubscription) {
// If the user has a Fleet Premium subscription, prepend the message with details about their subscription.
@ -108,42 +144,6 @@ Fleet Premium subscription details:
message,
},
});
let attributionCookieOrUndefined = this.req.cookies.marketingAttribution;
sails.helpers.flow.build(async ()=>{
let recordIds = await sails.helpers.salesforce.updateOrCreateContactAndAccount.with({
emailAddress: emailAddress,
firstName: firstName,
lastName: lastName,
contactSource: 'Website - Contact forms',
description: `Sent a contact form message: ${message}`,
marketingAttributionCookie: attributionCookieOrUndefined
}).intercept((err)=>{
return new Error(`Could not create/update a contact or account. Full error: ${require('util').inspect(err)}`);
});
// If the Contact record returned by the updateOrCreateContactAndAccount does not have a parent Account record, throw an error to stop the build helper.
if(!recordIds.salesforceAccountId) {
throw new Error(`Could not create historical event. The contact record (ID: ${recordIds.salesforceContactId}) returned by the updateOrCreateContactAndAccount helper is missing a parent account record.`);
}
// Create the new Fleet website page view record.
await sails.helpers.salesforce.createHistoricalEvent.with({
salesforceAccountId: recordIds.salesforceAccountId,
salesforceContactId: recordIds.salesforceContactId,
eventType: 'Intent signal',
intentSignal: 'Submitted the "Send a message" form',
eventContent: message,
}).intercept((err)=>{
return new Error(`Could not create an historical event. Full error: ${require('util').inspect(err)}`);
});
}).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 contact/account/historical event could not be created/updated in the CRM for this email address: ${emailAddress}. Full error: ${require('util').inspect(err)}`);
}
return;
});//_∏_
}
};