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
15 changes: 12 additions & 3 deletions config/install/ucb_site_configuration.configuration.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Configuration for this module will go here

site_type_options:
college:
college:
label: 'College'
school:
label: 'School'
Expand Down Expand Up @@ -174,7 +174,7 @@ site_search_options:
parameter: 'cse'

external_services:
mainstay:
mainstay:
label: Mainstay
content_label: Mainstay
settings:
Expand All @@ -190,7 +190,7 @@ external_services:
- auto_open
- auto_open_delay
- eyecatcher
livechat:
livechat:
label: LiveChat
content_label: LiveChat
settings:
Expand All @@ -206,3 +206,12 @@ external_services:
availability:
content: true
sitewide: true
goodkind:
label: Goodkind
content_label: Goodkind
settings:
- ai_bot_id
- ai_bot_api_key
availability:
content: true
sitewide: true
22 changes: 22 additions & 0 deletions js/service-goodkind.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(function (drupalSettings) {
const settings = drupalSettings.service_goodkind[0];
if (!settings) return;

console.log(settings)
// Set config BEFORE loading the script
window.gkCBWConfig = {
aiBotId: settings.ai_bot_id,
apiKey: settings.ai_bot_api_key,
domain: 'https://www.colorado.edu'
};

// Load the Goodkind widget
const script = document.createElement('script');
script.type = 'module';
script.src = 'https://widget.goodkind.com/gk-chatbot-widget.js';
script.defer = true;

// Append script to body
const body = document.body || document.getElementsByTagName('body')[0];
body.appendChild(script);
})(window.drupalSettings);
42 changes: 42 additions & 0 deletions src/Form/ExternalServiceIncludeEntityForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
}
break;

case 'goodkind':
$aiBotIdFieldName = $externalServiceName . '__ai_bot_id';
$botId = $form_state->getValue($aiBotIdFieldName);

if (strlen($botId) != 24 || !preg_match('/^[a-z0-9]+$/', $botId)) {
$form_state->setErrorByName($aiBotIdFieldName, $this->t('A valid bot ID is 24 characters long and a mix of lowercase letters and numbers.'));
}

$aiBotApiFieldName = $externalServiceName . '__ai_bot_api_key';
$botApi = $form_state->getValue($aiBotApiFieldName);

if (strlen($botApi) != 230 || !preg_match('/^[a-z0-9]+$/', $botApi)) {
$form_state->setErrorByName($aiBotApiFieldName, $this->t('A valid Bot API key is 230 characters long and a mix of lowercase letters and numbers.'));
}
break;

default:
$form_state->setErrorByName('service_name', $this->t('Unrecognized third-party service selected.'));
}
Expand Down Expand Up @@ -328,6 +344,32 @@ private function buildExternalServiceSiteSettingsForm(array &$form, $externalSer
],
];
break;
case 'goodkind':
$form[$externalServiceName . '__ai_bot_id'] = [
'#type' => 'textfield',
'#size' => 24,
'#maxlength' => 24,
'#title' => $this->t('AI Bot ID'),
'#default_value' => $externalServiceSettings['ai_bot_id'] ?? '6765a3c67b1f300012149d6e',
'#states' => [
'required' => [
':input[name="service_name"]' => ['value' => $externalServiceName],
],
],
];
$form[$externalServiceName . '__ai_bot_api_key'] = [
'#type' => 'textfield',
'#size' => 230,
'#maxlength' => 230,
'#title' => $this->t('Goodkind API Key'),
'#default_value' => $externalServiceSettings['ai_bot_api_key'] ?? '659425d1a56d1027865e1d658b27679e288bdd07adb4814d0d812a69bba6b429c77939ec0214f41e731ec17a26ce1ddcff47d138efbfc5199ff87a2569ed8115f4fbfca462109099a2cdf031b6c7b55fb3734024368179943a227b5cc6ec566bb01a45695e42a074f00d15ad0029775f46b7ad',
'#states' => [
'required' => [
':input[name="service_name"]' => ['value' => $externalServiceName],
],
],
];
break;

default:
}
Expand Down
9 changes: 9 additions & 0 deletions ucb_site_configuration.install
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,12 @@ function ucb_site_configuration_update_9510() {
}
}

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

function ucb_site_configuration_update_9511() {
_ucb_site_configuration_update_config([
'external_services',
]);
}
9 changes: 7 additions & 2 deletions ucb_site_configuration.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ service-mainstay:
https://webbot.mainstay.com/static/css/webchat.css: { type: external }
js:
js/service-mainstay.js: {}

service-servicecloud:
version: '1.0'
css:
theme:
theme:
css/service-servicecloud.css: {}
js:
js/service-servicecloud.js: {}
Expand All @@ -23,3 +23,8 @@ service-statuspage:
version: '1.0'
js:
js/service-statuspage.js: {}

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