fleet/website/api/helpers/salesforce/create-historical-event.js
Eric be14f7c10d
Website: Add webinar article template page. (#43627)
Changes:
- Added support for a new article category: `webinar`.
- Added a template page for webinar articles.
- Added an additional route for webinar articles that users are taken to
to watch the webinar recording.
- Added `deliver-webinar-access-request`, an action that updates CRM
records when users fill out the form on the webinar template page.
- Updated the accepted `intentSignal` values in the
create-historical-event helper.
- Added an article for the "Beyond the hype, practical AI for device
management" webinar.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Public webinar pages (/webinars/:slug and /watch) with optional
embedded video and a new page template, script, and styles.
* Sidebar signup form (first name, last name, work email) with prefill
for signed-in users and improved scroll behavior.
* POST API to request webinar access: validates email domain, records a
webinar-request event, triggers background CRM sync, and returns a watch
view on success.
* Static-site build now recognizes webinar articles and enforces
embedded-video URL validation.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Copilot <[email protected]>
2026-04-16 09:14:28 -05:00

163 lines
5.4 KiB
JavaScript
Vendored

module.exports = {
friendlyName: 'Create Historical event',
description: 'Create a historical event related to a particular contact and account in Salesforce.',
inputs: {
// Required values on new historical event records.
salesforceAccountId: {
type: 'string',
required: true,
extendedDescription: 'This ID of the account associated with this historical event'
},
salesforceContactId: {
type: 'string',
required: true,
extendedDescription: 'This ID of the contact associated with this historical event'
},
eventType: {
type: 'string',
required: true,
isIn: [
'Intent signal',
'Website page view',
],
},
// For "Website page view" type historical events:
fleetWebsitePageUrl: {
type: 'string',
description: 'The url of the page this user viewed.',
extendedDescription: 'This input is required when the event type is "Website page view".'
},
websiteVisitReason: {
type: 'string',
description: ''
},
// For "Intent signal" type historical events:
intentSignal: {
type: 'string',
isIn: [
'Followed the Fleet LinkedIn company page',
'LinkedIn comment',
'LinkedIn share',
'LinkedIn reaction',
'Fleet channel member in MacAdmins Slack',
'Fleet channel member in osquery Slack',
'Implemented a trial key',
'Signed up for Fleet event',
'Registered for a conference',
'Engaged with Fleetie at event',
'Attended a Fleet happy hour',
'Stared the fleetdm/fleet repo on GitHub',
'Forked the fleetdm/fleet repo on GitHub',
'Contributed to the fleetdm/fleet repo on GitHub',
'Subscribed to the Fleet newsletter',
'Attended a Fleet training course',
'Submitted the "Send a message" form',
'Scheduled a "Talk to us" meeting',
'Scheduled a "Let\'s get you set up" meeting',
'Submitted the "GitOps workshop request" form',
'Signed up for a fleetdm.com account',
'Requested whitepaper download',
'Created a quote for a self-service Fleet Premium license',
'Requested webinar recording',
]
},
eventContent: {
type: 'string',
},
eventContentUrl: {
type: 'string',
},
linkedinUrl: {
type: 'string',
},
relatedCampaign: {
type: 'string',
}
},
exits: {
success: {
outputType: {
salesforceHistoricalEventId: 'string',
},
},
},
fn: async function ({ salesforceAccountId, salesforceContactId, eventType, linkedinUrl, intentSignal, eventContent, eventContentUrl, fleetWebsitePageUrl, websiteVisitReason, relatedCampaign}) {
// Return undefined if we're not running in a production environment.
if(sails.config.environment !== 'production') {
sails.log.verbose('Skipping Salesforce integration...');
return {
salesforceHistoricalEventId: undefined
};
}
require('assert')(sails.config.custom.salesforceIntegrationPasskey);
require('assert')(sails.config.custom.salesforceIntegrationUsername);
require('assert')(sails.config.custom.RX_PROTOCOL_AND_COMMON_SUBDOMAINS);
// Normalize the provided linkedin url.
if(linkedinUrl){
linkedinUrl = linkedinUrl.replace(sails.config.custom.RX_PROTOCOL_AND_COMMON_SUBDOMAINS, '');
}
// Check for required values depending on the eventType value.
if(eventType === 'Intent signal') {
if(!intentSignal) {
throw new Error(`A intentSignal value is required when creating "Intent signal" type historical events`);
}
} else if(eventType === 'Website page view') {
if(!fleetWebsitePageUrl){
throw new Error(`A fleetWebsitePageUrl value is required when creating "Website page view" type historical events`);
}
}
// Use sails.helpers.flow.build to login to salesforce and create the new histrocial event record.
let newHistoricalRecord = await sails.helpers.flow.build(async ()=>{
// login to Salesforce
let jsforce = require('jsforce');
let salesforceConnection = new jsforce.Connection({
loginUrl : 'https://fleetdm.my.salesforce.com'
});
await salesforceConnection.login(sails.config.custom.salesforceIntegrationUsername, sails.config.custom.salesforceIntegrationPasskey);
return await salesforceConnection.sobject('fleet_website_page_views__c')
.create({
Contact__c: salesforceContactId,// eslint-disable-line camelcase
Account__c: salesforceAccountId,// eslint-disable-line camelcase
Event_type__c: eventType,// eslint-disable-line camelcase
Intent_signal__c: intentSignal,// eslint-disable-line camelcase
Content__c: eventContent,// eslint-disable-line camelcase
Content_url__c: eventContentUrl,// eslint-disable-line camelcase
Interactor_profile_url__c: linkedinUrl,// eslint-disable-line camelcase
Page_URL__c: fleetWebsitePageUrl,// eslint-disable-line camelcase
Website_visit_reason__c: websiteVisitReason,// eslint-disable-line camelcase
Related_campaign__c: relatedCampaign// eslint-disable-line camelcase
});
}).intercept((err)=>{
return new Error(`An error occured when creating a new Historical event record in Salesforce. full error ${require('util').inspect(err, {depth: null})}`);
});
return newHistoricalRecord.id;
}
};