Developers

AppData Labels

Introduction

This adapter allows the modification of the labels used by the Chat 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.

Caution

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.

Adapter code and public Github repository

This adapter can be found in the Inbenta Github adapters repository.

Click here to see the adapter code

How does it work?

  1. 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: appData

  2. 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.

  3. Check if the labels exists in localStorage. If there are no labels, or if the labels are expired, perform the getAppData API request.

  4. Once the API request is fulfilled, use the updateConfiguration with the values retrieved from appData to display the new labels.

  5. Finally, store the labels in the browser's LocalStorage to avoid the heed for repeated requests. Set an expiration period of 30 minutes.

interface-title

Actions and Subscriptions required

This adapter uses the following:

action:

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.

Configuration parameters

  • 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)
]

HTML demo with the configuration

<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>