diff --git a/assets/js/user_consent_functions.js b/assets/js/user_consent_functions.js new file mode 100644 index 000000000..cb1a75b96 --- /dev/null +++ b/assets/js/user_consent_functions.js @@ -0,0 +1,12 @@ +(function (Drupal) { + 'use strict'; + + window.chat_user_consent = { + retrieveUserConsent: () => (Drupal.eu_cookie_compliance.hasAgreedWithCategory('chat')), + confirmUserConsent: () => { + if (Drupal.eu_cookie_compliance.hasAgreedWithCategory('chat')) return; + Drupal.eu_cookie_compliance.setAcceptedCategories([ ...Drupal.eu_cookie_compliance.getAcceptedCategories(), 'chat' ]); + } + }; + +})(Drupal); diff --git a/helfi_platform_config.libraries.yml b/helfi_platform_config.libraries.yml index 89cda6971..c24b1ace7 100644 --- a/helfi_platform_config.libraries.yml +++ b/helfi_platform_config.libraries.yml @@ -122,6 +122,23 @@ watson_chatbot: minified: true } +watson_sote: + version: 1.0.x + header: false + js: + 'https://coh-chat-app-prod.ow6i4n9pdzm.eu-de.codeengine.appdomain.cloud/widget.min.js': { + type: external, + minified: true + } + 'https://coh-chat-app-prod.ow6i4n9pdzm.eu-de.codeengine.appdomain.cloud/static/sote-bot/custom.widget.min.js?tenantId=sote-prod&assistantId=sote-bot': { + type: external, + minified: true + } + 'https://coh-chat-app-prod.ow6i4n9pdzm.eu-de.codeengine.appdomain.cloud/default.min.js': { + type: external, + minified: true + } + genesys_neuvonta: version: 1.0.x header: true @@ -154,3 +171,11 @@ chat_leijuke: dependencies: - core/drupal - core/drupalSettings + +user_consent_functions: + version: 1.0.x + header: true + js: + assets/js/user_consent_functions.js: {} + dependencies: + - core/drupal diff --git a/src/Plugin/Block/ChatLeijuke.php b/src/Plugin/Block/ChatLeijuke.php index ea63b6895..66ed51873 100644 --- a/src/Plugin/Block/ChatLeijuke.php +++ b/src/Plugin/Block/ChatLeijuke.php @@ -34,8 +34,9 @@ public function blockForm($form, FormStateInterface $form_state) { 'genesys_kymp' => 'Genesys KYMP', 'genesys_suunte' => 'Genesys SUUNTE', 'genesys_neuvonta' => 'Genesys Neuvonta', - 'watson_chatbot' => 'Watson Chatbot', - 'kuura_health_chat' => 'Kuura Health Chat (dontuse)', + 'watson_chatbot' => 'Asunnonhakubotti (watson)', + 'kuura_health_chat' => 'Kuura Health Chat', + 'watson_sote' => 'Hester/Sotebotti (watson)', ], ]; diff --git a/src/Plugin/Block/IbmChatApp.php b/src/Plugin/Block/IbmChatApp.php new file mode 100644 index 000000000..a3350856a --- /dev/null +++ b/src/Plugin/Block/IbmChatApp.php @@ -0,0 +1,125 @@ +getConfiguration(); + + // hostname: Hostname of chat application. + $form['hostname'] = [ + '#type' => 'textfield', + '#title' => $this->t('Chat Hostname'), + '#default_value' => $config['hostname'] ?? '', + ]; + + // engagementId: will define how our chat application looks and behaves. + $form['engagementId'] = [ + '#type' => 'textfield', + '#title' => $this->t('Chat Engagement Id'), + '#default_value' => $config['engagementId'] ?? '', + ]; + + // tenantId: defines the environment to be used. + $form['tenantId'] = [ + '#type' => 'textfield', + '#title' => $this->t('Chat Tenant Id'), + '#default_value' => $config['tenantId'] ?? '', + ]; + + // assistantId: identifies the bot instance to be used. + $form['assistantId'] = [ + '#type' => 'textfield', + '#title' => $this->t('Chat Assistant Id'), + '#default_value' => $config['assistantId'] ?? '', + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function blockSubmit($form, FormStateInterface $formState) { + $this->configuration['hostname'] = $formState->getValue('hostname'); + $this->configuration['engagementId'] = $formState->getValue('engagementId'); + $this->configuration['tenantId'] = $formState->getValue('tenantId'); + $this->configuration['assistantId'] = $formState->getValue('assistantId'); + } + + /** + * {@inheritdoc} + */ + public function build() { + + $library = ['helfi_platform_config/user_consent_functions']; + + $build = []; + + $config = $this->getConfiguration(); + + $hostname = $config['hostname']; + $engagementId = $config['engagementId']; + $tenantId = $config['tenantId']; + $assistantId = $config['assistantId']; + + $optionsSrc = sprintf('%s/get-widget-options?tenantId=%s&assistantId=%s&engagementId=%s', $hostname, $tenantId, $assistantId, $engagementId); + $widgetSrc = sprintf('%s/get-widget?tenantId=%s&assistantId=%s&engagementId=%s', $hostname, $tenantId, $assistantId, $engagementId); + $defaultSrc = sprintf('%s/get-widget-default?tenantId=%s&assistantId=%s&engagementId=%s', $hostname, $tenantId, $assistantId, $engagementId); + + $build['ibm_chat_app'] = [ + '#title' => $this->t('IBM Chat App'), + '#attached' => [ + 'library' => $library, + 'html_head' => [ + [ + [ + '#tag' => 'script', + '#attributes' => [ + 'type' => 'text/javascript', + 'src' => $optionsSrc, + ], + ], 'chat_app_options', + ], + [ + [ + '#tag' => 'script', + '#attributes' => [ + 'type' => 'text/javascript', + 'src' => $widgetSrc, + ], + ], 'chat_app_widget', + ], + [ + [ + '#tag' => 'script', + '#attributes' => [ + 'type' => 'text/javascript', + 'src' => $defaultSrc, + ], + ], 'chat_app_default', + ], + ], + ], + ]; + + return $build; + } + +}