diff --git a/config/install/ucb_site_configuration.configuration.yml b/config/install/ucb_site_configuration.configuration.yml index 691c8c8..b331793 100644 --- a/config/install/ucb_site_configuration.configuration.yml +++ b/config/install/ucb_site_configuration.configuration.yml @@ -1,7 +1,7 @@ # Configuration for this module will go here site_type_options: - college: + college: label: 'College' school: label: 'School' @@ -174,7 +174,7 @@ site_search_options: parameter: 'cse' external_services: - mainstay: + mainstay: label: Mainstay content_label: Mainstay settings: @@ -190,7 +190,7 @@ external_services: - auto_open - auto_open_delay - eyecatcher - livechat: + livechat: label: LiveChat content_label: LiveChat settings: @@ -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 diff --git a/js/service-goodkind.js b/js/service-goodkind.js new file mode 100644 index 0000000..1c0b32a --- /dev/null +++ b/js/service-goodkind.js @@ -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); diff --git a/src/Form/ExternalServiceIncludeEntityForm.php b/src/Form/ExternalServiceIncludeEntityForm.php index f663b3e..e337bc3 100644 --- a/src/Form/ExternalServiceIncludeEntityForm.php +++ b/src/Form/ExternalServiceIncludeEntityForm.php @@ -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.')); } @@ -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: } diff --git a/ucb_site_configuration.install b/ucb_site_configuration.install index de6ae94..9a54ea4 100644 --- a/ucb_site_configuration.install +++ b/ucb_site_configuration.install @@ -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', + ]); +} diff --git a/ucb_site_configuration.libraries.yml b/ucb_site_configuration.libraries.yml index b3c639d..4f5964b 100644 --- a/ucb_site_configuration.libraries.yml +++ b/ucb_site_configuration.libraries.yml @@ -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: {} @@ -23,3 +23,8 @@ service-statuspage: version: '1.0' js: js/service-statuspage.js: {} + +service-goodkind: + version: '1.0' + js: + js/service-goodkind.js: {}