Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config/install/ucb_site_configuration.configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,14 @@ external_services:
availability:
content: true
sitewide: true
salesforce:
label: Salesforce Enhanced Chat
content_label: Salesforce Enhanced Chat
settings:
- salesforce_id
- embedded_service_name
- endpoint_url
- scrt2_url
availability:
content: true
sitewide: true
33 changes: 33 additions & 0 deletions js/service-salesforce.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(function (drupalSettings) {
const settings = drupalSettings.service_salesforce?.[0];
if (!settings) return;

function initEmbeddedMessaging() {
try {
embeddedservice_bootstrap.settings.language = 'en_US';

embeddedservice_bootstrap.init(
settings.salesforce_id,
settings.embedded_service_name,
settings.endpoint_url,
{
scrt2URL: settings.scrt2_url
}
);
} catch (err) {
console.error('Error loading Embedded Messaging:', err);
}
}

function loadSalesforceBootstrap() {
const endpoint = settings.endpoint_url.replace(/\/$/, '');
const script = document.createElement('script');
script.src = `${endpoint}/assets/js/bootstrap.min.js`;
script.type = 'text/javascript';
script.onload = initEmbeddedMessaging;
script.onerror = () => console.error('Failed to load Salesforce bootstrap.min.js');
document.head.appendChild(script);
}

loadSalesforceBootstrap();
})(window.drupalSettings);
72 changes: 72 additions & 0 deletions src/Form/ExternalServiceIncludeEntityForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,24 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
}
break;

case 'salesforce':
$idField = $externalServiceName . '__salesforce_id';
$nameField = $externalServiceName . '__embedded_service_name';
$endpointField = $externalServiceName . '__endpoint_url';
$scrt2Field = $externalServiceName . '__scrt2_url';

$endpointUrl = $form_state->getValue($endpointField);
if (!filter_var($endpointUrl, FILTER_VALIDATE_URL) || strpos($endpointUrl, 'https://cu.my.site.com') !== 0) {
$form_state->setErrorByName($endpointField, $this->t('The Endpoint URL must start with https://cu.my.site.com'));
}

$scrt2Url = $form_state->getValue($scrt2Field);
if (!filter_var($scrt2Url, FILTER_VALIDATE_URL) || strpos($scrt2Url, 'https://cu.my.salesforce-scrt.com') !== 0) {
$form_state->setErrorByName($scrt2Field, $this->t('The SCRT2 URL must start with https://cu.my.salesforce-scrt.com'));
}

break;

default:
$form_state->setErrorByName('service_name', $this->t('Unrecognized third-party service selected.'));
}
Expand Down Expand Up @@ -370,7 +388,61 @@ private function buildExternalServiceSiteSettingsForm(array &$form, $externalSer
],
];
break;
case 'salesforce':
$form[$externalServiceName . '__salesforce_id'] = [
'#type' => 'textfield',
'#size' => 24,
'#maxlength' => 24,
'#title' => $this->t('Salesforce Org ID'),
'#default_value' => $externalServiceSettings['salesforce_id'] ?? '',
'#required' => TRUE,
'#states' => [
'visible' => [
':input[name="service_name"]' => ['value' => $externalServiceName],
],
],
];

$form[$externalServiceName . '__embedded_service_name'] = [
'#type' => 'textfield',
'#size' => 64,
'#maxlength' => 64,
'#title' => $this->t('Embedded Service Name'),
'#default_value' => $externalServiceSettings['embedded_service_name'] ?? '',
'#required' => TRUE,
'#states' => [
'visible' => [
':input[name="service_name"]' => ['value' => $externalServiceName],
],
],
];

$form[$externalServiceName . '__endpoint_url'] = [
'#type' => 'url',
'#title' => $this->t('Embedded Service Endpoint URL'),
'#default_value' => $externalServiceSettings['endpoint_url'] ?? '',
'#required' => TRUE,
'#description' => $this->t('Example: https://cu.my.site.com/EmbeddedServiceName1234'),
'#states' => [
'visible' => [
':input[name="service_name"]' => ['value' => $externalServiceName],
],
],
];

$form[$externalServiceName . '__scrt2_url'] = [
'#type' => 'url',
'#title' => $this->t('SCRT2 URL'),
'#default_value' => $externalServiceSettings['scrt2_url'] ?? '',
'#required' => TRUE,
'#description' => $this->t('Example: https://cu.my.salesforce-scrt.com'),
'#states' => [
'visible' => [
':input[name="service_name"]' => ['value' => $externalServiceName],
],
],
];
break;
default:
}
}
Expand Down
11 changes: 11 additions & 0 deletions ucb_site_configuration.install
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,14 @@ function ucb_site_configuration_update_9513() {
'site_affiliation_options',
]);
}

/**
* Updates the Third-party services to add the Salesforce chatbot option.
*/

function ucb_site_configuration_update_9514() {
_ucb_site_configuration_update_config([
'external_services',
]);
}

5 changes: 5 additions & 0 deletions ucb_site_configuration.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ service-goodkind:
version: '1.0'
js:
js/service-goodkind.js: {}

service-salesforce:
version: '1.0'
js:
js/service-salesforce.js: {}