fleet/website/api/controllers/deliver-contact-form-message.js
Eric 2af2c41572
Website: Update round robin in salesforce helpers & move lead creation to save-questionnaire-progress. (#19209)
Closes: #18932

Changes:
- Updated `update-or-create-contact-and-account.js` to not round robin
new account records created.
- Updated create-lead to reassign accounts owned by the integrations
admin user when a new lead is created.
- Updated logged warnings in signup, deliver-contact-form-message and
deliver-talk-to-us-form-submission.
- Updated signup.js to not create salesforce leads (only account and
contact records)
- Updated save-questionnaire-progress to create Salesforce leads when we
know the user has a use case for Fleet.
2024-05-27 16:43:40 -05:00

89 lines
2.7 KiB
JavaScript
Vendored

module.exports = {
friendlyName: 'Deliver contact form message',
description: 'Deliver a contact form message to the appropriate internal channel(s).',
inputs: {
emailAddress: {
required: true,
type: 'string',
description: 'A return email address where we can respond.',
example: '[email protected]'
},
firstName: {
required: true,
type: 'string',
description: 'The first name of the human sending this message.',
example: 'Emma'
},
lastName: {
required: true,
type: 'string',
description: 'The last name of the human sending this message.',
example: 'Watson'
},
message: {
type: 'string',
required: true,
description: 'The custom message, in plain text.'
}
},
exits: {
invalidEmailDomain: {
description: 'This email address is on a denylist of domains and was not delivered.',
responseType: 'badRequest'
},
success: {
description: 'The message was sent successfully.'
}
},
fn: async function({emailAddress, firstName, lastName, message}) {
if (!sails.config.custom.slackWebhookUrlForContactForm) {
throw new Error(
'Message not delivered: slackWebhookUrlForContactForm needs to be configured in sails.config.custom. Here\'s the undelivered message: ' +
`Name: ${firstName + ' ' + lastName}, Email: ${emailAddress}, Message: ${message ? message : 'No message.'}`
);
}
let emailDomain = emailAddress.split('@')[1];
if(_.includes(sails.config.custom.bannedEmailDomainsForWebsiteSubmissions, emailDomain.toLowerCase())){
throw 'invalidEmailDomain';
}
await sails.helpers.http.post(sails.config.custom.slackWebhookUrlForContactForm, {
text: `New contact form message: (Remember: we have to email back; can't just reply to this thread.) cc @sales `+
`Name: ${firstName + ' ' + lastName}, Email: ${emailAddress}, Message: ${message ? message : 'No message.'}`
});
// Use timers.setImmediate() to update/create CRM records in the background.
require('timers').setImmediate(async ()=>{
await sails.helpers.salesforce.updateOrCreateContactAndAccountAndCreateLead.with({
emailAddress: emailAddress,
firstName: firstName,
lastName: lastName,
leadSource: 'Website - Contact forms',
leadDescription: `Sent a contact form message: ${message}`,
}).tolerate((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);
});
});//_∏_ (Meanwhile...)
}
};