Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uhf 7766 sote chatapp #414

Merged
merged 7 commits into from
Dec 21, 2022
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
12 changes: 12 additions & 0 deletions assets/js/user_consent_functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(function (Drupal) {
'use strict';

window.chat_user_consent = {
retrieveUserConsent: () => (Drupal.eu_cookie_compliance.hasAgreedWithCategory('chat')),
confirmUserConsent: () => {
Comment on lines +5 to +6
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User consent functions for IBM to use from their chat app.

if (Drupal.eu_cookie_compliance.hasAgreedWithCategory('chat')) return;
Drupal.eu_cookie_compliance.setAcceptedCategories([ ...Drupal.eu_cookie_compliance.getAcceptedCategories(), 'chat' ]);
}
};

})(Drupal);
25 changes: 25 additions & 0 deletions helfi_platform_config.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
5 changes: 3 additions & 2 deletions src/Plugin/Block/ChatLeijuke.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
],
];

Expand Down
125 changes: 125 additions & 0 deletions src/Plugin/Block/IbmChatApp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php

namespace Drupal\helfi_platform_config\Plugin\Block;

use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;

/**
* Provides a Watson chatbot block.
*
* @Block(
* id = "ibm_chat_app",
* admin_label = @Translation("IBM Chat App"),
* )
*/
class IbmChatApp extends BlockBase {

/**
* {@inheritdoc}
*/
public function blockForm($form, FormStateInterface $form_state) {
$form = parent::blockForm($form, $form_state);
$config = $this->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;
}

}