mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
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:
parent
2d03130c46
commit
16e8d48396
1 changed files with 36 additions and 36 deletions
|
|
@ -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;
|
||||
});//_∏_
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue