-
Notifications
You must be signed in to change notification settings - Fork 5
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
996e6b0
UHF-7766: Sotebot integration via leijuke ala asuntobotti.
b21f800
UHF-7766: Untested configurable IBM chatapp integration block.
1f95cbe
UHF-7766: IBM chat app injection block should work now.
8d32727
UHF-7766: User consent functions abstraction exposed to js.
cdcbf83
Fix typo in user consent function.
901e0ea
UHF-7766: Fix phpcs stuff.
b8aab94
UHF-7766: Updated sotebot ids and urls.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: () => { | ||
if (Drupal.eu_cookie_compliance.hasAgreedWithCategory('chat')) return; | ||
Drupal.eu_cookie_compliance.setAcceptedCategories([ ...Drupal.eu_cookie_compliance.getAcceptedCategories(), 'chat' ]); | ||
} | ||
}; | ||
|
||
})(Drupal); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.