This adapter allows the modification of the labels used by the Chatbot SDK. It performs a request on AppData
and delays the execution of the visual components until the request is fulfilled.
The SDK will show the interface-title label that is retrieved from AppData
. The adapter also uses LocalStorage
to cache the AppData
request.
This is a solution for systems that do not have their own CMS system. The recommended flow is to use system variables directly inside the build method as it allows you to modify the labels and other settings before the SDK starts. The use of Inbenta AppData will perform one additional API request per user, which may delay the render of the SDK view as long as the API request is not fulfilled.
Inbenta recommends that you use your own content management system to store this configuration.
This adapter can be found in the Inbenta Github adapters repository.
First, define the parameters to request the AppData information. For more information, see the methods page. This information is sent to the new adapter.
var appData = {
'dataID':'chatbot_labels',
'name':'CustomLabels'
};
We use this information to request the following AppData object:
Use the onReady
subscription to interrupt the build method. To prevent the loading of the visible portion of the SDK until the labels are updated, return a promise in the onready
subscription to interrupt the build until the promise is fulfilled.
Check if the labels exists in localStorage
. If there are no labels, or if the labels are expired, perform the getAppData
API request.
Once the API request is fulfilled, use the updateConfiguration
with the values retrieved from appData to display the new labels.
Finally, store the labels in the browser's LocalStorage
to avoid the heed for repeated requests. Set an expiration period of 30 minutes.
This adapter uses the following:
action:
updateConfiguration
to update the original labels of the build method.subscription:
onReady
with a promise as a return, to delay the execution of the build until the promise is fulfilled.appData
API Client request:
getAppData
to retrieve the labels stored in the appData
.appData
: You need the group and the name in order to use the getAppData
API Client endpoint.var appData = {
'dataID':'chatbot_labels',
'name':'CustomLabels'
};
adapters:
[
updateConfigurationFromAppData(appData)
]
<script src="updateConfiguration.js"></script>
<script>
var authorization = {
domainKey:<your_domain_key>,
inbentaKey: <your_API_key>
};
var appData = {
'dataID':'chatbot_labels',
'name':'CustomLabels'
};
InbentaChatbotSDK.buildWithDomainCredentials(authorization, {
labels:{
en:{
'interface-title':'original title'
}
},
adapters: [
updateConfigurationFromAppData(appData)
]
});
</script>