Developers

Hyperchat Only

Introduction

Inbenta created a special build method to allow authorization through the SDK, using Hyperchat credentials: buildWithHCCredentials(configuration)

The configuration parameter is almost the same as in the build method. The difference is that the authorization is now handled internally.

This example shows how to:

  • The configuration needed to use the HTML escalation adapter.
  • The configuration needed for the hyperchat-adapter.
  • How to use the internal adapters.

For more information in each adapter:

html-escalation-adapter configuration

  • The bot shows the escalation form when the user sends a message (The force parameter must be set to true).
  • Questions: This is an array that contains all the questions in the form. Each question is an object that has a label, text, type and validation parameter.
  • Displays "What else can I do for you?" when the user rejects the escalation.
  • Displays a preset message when no-agents are available or when it rejects the escalation.

Hyperchat-adapter configuration

We will be using all the default configuration, and will only set the needed parameters:

  • apiKey: The key of the HyperChat API (former "appId"). This defines the instance in which the chat opens.
  • region: The geographical region where the HyperChat app lives.
  • room: The room where the chat will be open, in this case will depend on the value of q in the url

The following examples use both adapters from the internal code.

Example

<!DOCTYPE html>
<html>
    <head>
        <title>SDK Test</title>
        <meta charset="utf-8">
    </head>
    <body>
        <script>
            window.buildUI = function () {
                var rejectedEscalation = 'What else can I do for you?';
                var noAgentsAvailable = 'There are no agents available just now.';

                // question configuration
                var questions = [
                    {
                        label: 'FIRST_NAME',
                        text: 'What\'s your name?',
                        validationErrorMessage: 'Name cannot be empty',
                        validate: function(value) {
                            if (value !== '') {
                                return true;
                            }
                            return false;
                        }
                    },
                    {
                        label: 'EMAIL_ADDRESS',
                        text: 'What\s your email?',
                        validationErrorMessage: 'The email format is not correct',
                        validate: function(value) {
                            return /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/.test(value);
                        }
                    },
                ];

                SDKHCAdapter.configure({
                    apiKey: '<chat_api_key>', // former "appId"
                    region: '<chat_app_region>',
                    room: function () {
                        return SDKHCAdapter.helpers.getQueryParameterValue('q');
                    },
                    lang: function () {
                        return 'en'; // If the instance has languages configured and 'en' is not one of them, this should be changed to the code of a configured language.
                    },
                });

                var configuration = {
                    launcher: {
                        title: "HyperChatbot Demo"
                    },
                    adapters: [
                        SDKHCAdapter.build(),
                        SDKcreateHtmlEscalationForm(SDKHCAdapter.checkEscalationConditions, questions, rejectedEscalation, noAgentsAvailable, false)
                    ]
                };

                InbentaChatbotSDK.buildWithHCCredentials(configuration);
            };
        </script>
        <script src="https://sdk.inbenta.io/chatbot/1/inbenta-chatbot-sdk.js" onload="buildUI()"></script>
    </body>
</html>
Note

The appId parameter is DEPRECATED in favor of apiKey, for consistency with Inbenta terminology. If you use appId, Inbenta recommends that you update your configuration.