Configure Dialogs

Dialogs panel is where you design the whole conversation between the chatbot and the end user. It is visually represented by different elements used in the dialog creation.

The dialogs are based on intents. The panel itself is split into three frames, each containing a separate set of configuration options.

Name and group dialogs

The left panel enables you to:

  • Hide side panel
  • Add new dialog
  • Rename the dialog
  • Move the dialog
  • Duplicate the dialog
  • Delete the dialog
  • Add new group
  • Rename the group
  • Move the group
  • Delete the group
  • Collapse group

The Default group and the Default dialog are created automatically when you create the chatbot and have this icon Default dialog iconbeside it. They cannot be deleted.

Default group and default dialog in Answers


The frame containing the list of dialogs can be hidden using the arrows icon in the top right corner of the frame – hovering over it displays the tooltip.

HIde dialog tooltip

The left frame contains the list of dialogs to which you can add a new one by clicking the +ADD DIALOG action. If you have a lot of dialogs, you can organize them logically into groups.

Add dialog action in Answers

Note that where you click on the +ADD DIALOG action, the dialog appears under that grouping.

Clicking the three-dot menu  displays the actions you can perform on the dialog:

  • Edit – used to rename the dialog
  • Duplicate – used to recreate the same dialog
  • Delete – removes the dialog from the list

Actions available for dialogs


The action +ADD GROUP allows creation of new groups (of dialogs) in order to separate dialogs for better logical organization.

Group actions in Answers

All group actions are available through the three-dot menu .

As groups cannot be dragged up and down, use the Move up and Move down actions if you want to rearrange them. Bear in mind that you cannot change the place of the Default group, that one will always stay on top.

To change the name of the group, use the action Edit, and to copy an existing group, use the action Duplicate.

The collapsed arrow is used to collapse the groups or when collapsed, to expand them again.

Collapsed groups in Answers

Session Expire dialog

When you want your chatbot to notify the end users that their session is finished, use the Session Expire dialog (located at the bottom of dialogs panel).

Session expire dialog action

 

Click the + ADD SESSION EXPIRE DIALOG and it will appear in the Default dialog group. Like the Default dialog, it has the icon next to it.

Session expire dialog elements

NOTE

You can drag and drop any dialog inside a group to by clicking the left side of the dialog and dropping it anywhere in the structure (the hand shows that the dialog is being moved).

Dragging dialogs in Answers

Send text element is automatically added to the dialog to add a message for the end users and notify them that the session has expired (and that a new one will start if they decide to continue the conversation).

Bear in mind that you cannot configure this dialog using all building elements – in this dialog you can only use elements that are sent to the end user.

Dialog settings

In the central dialog panel, you can do the following:

  • Select the Intent which will be the basis of the dialog
  • Design the dialog between the bot and the end user

Assign Intent to Dialog

When you have a new dialog ready for configuration, the first building block is automatically displayed - as the whole dialog is usually based on the Intent. For the first element you can either use an existing intent or create a new one at that moment using the TRAIN link. Select an existing intent from the Intent dropdown list or use +Create new intent to create one on the fly.

Create new intent in dialog

If you are missing an intent on the list and decide to create it on the fly, enter the intent name and submit it by clicking the check mark .

Assigne new intent to dialog

IMPORTANT

You can decide not to use an intent only in case you are building a keyword-based chatbot. If you use NLP, intent selection is mandatory.

Templating Language

In order to facilitate the extraction of values and dynamic generation of content, we introduced a templating language – Liquid - to the Answers platform.

Liquid is a templating language with simple markup, made so that users can edit it. 

Liquid code uses objects, tags, and filters in a template which is then rendered and the content is dynamically shown. Template is any message you create that contains templating language elements.

 

Objects

Objects are used to show content on a page. Objects and variable names are denoted by double curly braces: {{ and }}.

Types of objects: String, Number, Boolean, Nil, and Array.

Example of Liquid object in dialog

More about Liquid objects.

Tags

Tags create the logic and control flow for templates. They are denoted by curly braces and percent signs: {% tag %}. Tags do not render into any visible text; you use them to assign variables and create conditions and loops in the background.


There are five different types of tags:

• Comment tags – use {% comment %} and {% endcomment %} tags to turn anything between them into a comment.

• Control flow tags – change the displayed information using programming logic: if, unless, elseif/else, case/when.

• Iteration tags – for, else, break, continue, plus additional tags for parameters (limit, offset, range, reversed), cycle, and tablerows (cols, limit, offset, range) to repeatedly run blocks of code.

• Raw tags – used to temporarily disable tag processing, {% raw %} and {% endraw %}.

• Variable tags – assign, capture, increment and decrement are used to create new variables in the templating language.

Basic operators (used in tags):
==  equals
!=  does not equal
greater than
<  less than
>=  greater than or equal to
<=  less than or equal to
or  logical or
and  logical and


Learn more about Liquid tags.

Filters

Filters change the output of the template language object. They are used within the object and are separated by a | (pipe) character. You can use multiple filters for one output applying them from left to right (each separated by the | character). Check the list of all available filters.

 

How to use templating language

There are three options in Answers how to retrieve data for templating language objects.
• directly use the attributes you have created,
• retrieve values from json files you have saved as attribute values,
• retrieve values from list attributes.


The first option where you use templating language to retrieve values of the attributes is the same as when you use personalization and insert attributes from that list.
But in this case, you can also enter them manually using templating language object syntax - write them inside double curly braces {{attribute_name}}.

Example of Liquid object as attribute value in Answers


The advantage of using templating language for attribute values is that you can use filters to display the values in different ways (upper case, lower case, capitalized, round the numbers, format dates, etc.). Example: {{attribute_name | capitalize}}, or  {{attribute_name | round}}.

 

Example of liquid tag

The more complex option is to use objects, tags, and filters to retrieve values from the json file you saved as attribute value and render such a template into a message for the user.

Liquid template in Answers with filter, tag and object

The output of this template will look like this when you use the Simulator:

Simulation of chatbot conversation using templating language

The question is retrieved from the qa attribute (where the json file was saved), filter is set to display the question in uppercase, and the tag is there to index the answers starting at 1.
You can use the templating language in all elements of the Answers platform where it is possible to enter text and variables (Send text/image/video/audio, Attribute, Conditions, etc.).

IMPORTANT

In cases you have a message that will return only attribute value (there is no additional text message), sometimes you can have scenarios where the attribute value returns empty. If you expect such cases to occur, and you don’t want the conversation to stop there, use templating language to prevent it.

{% if attribute_name %}
  {{attribute_name}}
{% else %}
  Fallback message.
{% endif %}

Create Dialogs

The dialog frame on the right contains the building blocks necessary for the dialog structure:

  • Bot Sends items
    • Text
    • Image
    • File
    • Audio
    • Video
    • Location
  • Bot Receives items
    • User Input
    • Attribute
  • Bot Actions
    • To Dialog
    • To Agent
    • API
    • Conditions
    • Coding
    • Webhook
    • Delay

All elements for dialog creation

To start building the dialog, click on an element from the right frame and drag’n’drop it under the intent.

After the element is added to the central frame, clicking it will display its configuration options in the right frame.

NOTE

All the elements that send a file (audio, image, video, and file) have the allowed maximum size of 10MB whether you use the upload or link function. Some file formats are not supported in some of the browsers (like .mp3 in Internet Explorer). We recommend using Firefox or Chrome.

Check the table below which elements and formats are available on which channels:

Elements per channel in Answers

Send text

Send text element contains the message frame where you write the message that the bot sends to the user and you can personalize the message with attributes, objects from the templating language, and emoticons.

If the message contains a link and you want the end user to have a preview of it, use the Link preview toggle (by default it is on). Link preview is only available for chatbots using WhatsApp as channel.

Send text element with link preview

 

 

Depending on the channel you use for your chatbot, the character limit of messages will differ.

Here is the list of channels and their limits:

Channel Character Limit
WhatsApp 4096
Viber 1000
Facebook Messenger 1000
LiveChat 1000
RCS 1000
Push 1000
SMS 25 messages/160 characters (depending on the encoding)
Line 1000

Send image

Send image element has two options for sending images. You can upload the image from your computer (either by drag and dropping it in the expected frame or by using the Browse link). Available formats are listed there as well (.jpg or .png). The other option is to click on the LINK button and add a link to your image which you can personalize through attributes as well. The image caption text box lets you enter text and personalize it with attributes and emoticons.

Send image element with upload option

Send audio

Send audio element enables the bot to send audio files to the user by uploading a file using the UPLOAD button or by entering a link to the audio file clicking on the LINK button and adding the link in the Audio URL field.

Answers displays the allowed formats for upload.

You can personalize the link using variables inside the { } icon.

NOTE

Send audio element is not available for Viber, LINE, and SMS channels.

Send video

To send a video to the user, the configuration options are the same as for the audio. Use the UPLOAD button or enter a link to the Video URL field.

Only .mp4 format is available at the moment.

Captioning the file is optional.

Send video element with upload option

NOTE

Send video element is not available for Viber, LINE, and SMS channels.

Send Document

Send Document element allows you to upload or link files of the following formats: .pdf, .doc, .docx, .ppt, .pptx, .xls, .xlsx.

Again, use either the UPLOAD or LINK button, depending whether you have the file stored locally or you are adding a link to it.

Send document element with upload

Send document element is not available for RCS, Viber, LINE, and SMS channels.

Send location

You can send a location to the end user by using one of the three available options of entering the location:

  • Search for a location
  • Enter longitude and latitude
  • Get location through attribute (saved as an MO Location attribute)

All options for Send location

  1. For the first option, type the address for the Google search to find it:

Send location using Google search

Optionally, you can give the location a name to be displayed when sent to the user.

  1.  If using longitude and latitude, enter the coordinates and again, give the location a name if you want to.

Send location by latitude and longitude

  1. For the last option you need to have the MO Location attribute created in Answers and location saved as the attribute value in order to be able to send it further.

Send locations using MO Attribute

NOTE

Send location element is not available for RCS and SMS channels.

User Input

For the element Process User Input which the bot receives in reply, the configuration is threefold. You can use keywords you have set up under the Keywords tab and based on them the bot will recognize the next dialog step. Keywords are added by clicking the Add Keyword Mapping and the value is selected from the drop-down list of existing keywords configured for this bot.

In addition to using keywords mapping to direct the conversation, you can also enable NLP engine to process input in case the correct keyword or keyword synonym is not entered.

You can learn more about how NLP engine processes data under Advanced Options - NLP.

Process user input element

The next part of the configuration concerns the option where the chatbot doesn’t recognize the user input. The first possibility here is to ask the user to repeat their communication. From the Repeat drop-down list select how many times you want the bot to ask the end user to repeat themself.

Additionally, you can add specific text for the repeated bot responses.

The Link preview toggle is on by default and will display a preview of the link in cases where there are links in the messages to your end users (only when WhatsApp is selected as the channel).

Process user input with fallback option

In situations where processing user input has failed through the previous two options, the last thing to configure is the Fallback.

The Fallback action you can select is either to send the end user to another dialog  (Go to dialog option) and from Dialog drop-down menu, you select which dialog will that be; or to send the conversation to the agent (Connect to agent).

In either case, it would be wise to enter a Fallback message in order to let your end user know that the conversation is being transferred either to another dialog or directly to the agent (whichever is more appropriate for the conversation).

Attribute

Attribute element in the dialog design contains the frame for message input (with variables) and the option to Save answer to an attribute from the Attributes tab. The type of attribute is automatically recognized and is read-only.

This element is useful when you want to send a message to the end user while at the same time gather information that will be stored in the attribute that is part of that message.

The first available option is the checkbox Skip question if attribute is not empty. This will be valid in cases where you are using NER attributes and the attribute already has a prepopulated value as the end user’s utterance contained the information. In such scenarios, you don’t need to ask the end user for the information one more time and can check this option to skip the message that is sent with the attribute element.Attribute element with link preview

Link preview toggle is enabled by default and will display a preview of the link in the conversation with the end user if you include it in the message (available on WhatsApp channel).

Checking the option Enable custom validation enables you to enter a regex pattern for attribute value validation. The validation based on regex supports BRE (Basic Regular Expressions) standard.

Regex is useful in situations where you want to check, match, or validate different inputs, like check if a string contains numbers, or validate if the input is a phone number.

Here is a list of the most commonly used operations in Regex:

Character classes

  • .               any character except newline
  • \w \d \s    word, digit, whitespace
  • \W \D \S  not word, digit, whitespace
  • [abc]       any of a, b, or c
  • [^abc]     not a, b, or c
  • [a-g]       character between a & g

Anchors

  • ^abc$    start / end of the string
  • \b           word boundary

Escaped characters

  • \. \* \\    escaped special characters

Groups & Lookaround

  • (abc)      capture group
  • \1            backreference to group #1
  • (?:abc)   non-capturing group
  • (?=abc)  positive lookahead
  • (?!abc)   negative lookahead

Quantifiers & Alternation

  • a* a+ a?     0 or more, 1 or more, 0 or 1
  • a{5} a{2,}    exactly five, two or more
  • a{1,3}          between one & three
  • a+? a{2,}?    match as few as possible
  • ab|cd          match ab or cd

Let’s have a look at an example.

You want to check if an MSISDN is 12 digits and starts with 254 (format: 254xxxxxxxxx). In that case, your regex would look like this:

^254[0-9]{9}$

The first character ^ means you match the string at the beginning, followed by the exact "254", after which you expect numbers only from 0 to 9 which is [0-9], and you expect 9 of these {9}. $ is to mark the end of the expression.

In case the attribute value is not recognized as valid, you can configure the Repeat option, meaning the chatbot will repeat the message depending on the value you select from the Repeat drop-down list. Repeat message textbox is there for you to insert a different message in cases when the bot has trouble recognizing values that the end user sent.

If repeating the message still doesn’t help with resolving the attribute value, the last option you can use is Fallback.

The available Fallback action(s) are Go to dialog or Connect to agent. For Go to dialog you need to select one of the configured dialogs in the Answers platform. Fallback also allows you to enter a message for the end user if you want to explain what is happening and that you are redirecting the end user to either another dialog or to a person (an agent).

To Dialog

To Dialog element is used when the conversation is ready to transition from one dialog to another. It can be to a dialog with an intent to finish the conversation, or it can simply be a transition to a new dialog based on a different intent where the end user is asking for new information.

Go to dialog element

With the transition to another intent, you can decide what attributes will be transferred with it.

Check the checkbox Share attribute value(s) to next intent and Answers will enable you to click Add attribute and select an attribute from the list of all available attributes.

Select next dialog

You can add as many attributes as are configured in the chatbot but take into consideration which are used in the intent and have values that can be transferred.

Once selected, the attribute no longer appears on the list and cannot be added again.

To Agent

When you reach the place in your conversation where no further intents can be resolved for the chatbot to continue chatting with the end user, you can redirect the conversation to the agent.

Once directed to the agent, the conversation cannot be returned to the chatbot.

You can also select tags which will route the conversation to the right queue in the Conversations module where the agent continues to resolve the issue.

Redirect conversation to agent

Call API

Call API element is there for you when you need to retrieve information from an external system or send information to another system.
The element itself contains two tabs, one where you define the request, and the other where you define the response.

When defining the request, you need to start with the Method you will use for it. You can select one of the following methods in Answers:
POST – primarily used to create a new resource on the third-party side.
GET – is used to retrieve information from the called API.
PUT – is used to store something on the third-party side (primarily updates an existing resource).
DELETE – used to remove something on the third-party side.
PATCH – used to make partial changes to an existing resource.

Call API element in Answers

After the method, you need to enter the URL for the API call – that’s the URL of the third-party system with which the chatbot communicates.

NOTE

Use checkbox Enable escaping of URL parameters to replace all characters that are deemed “unsafe” by web standards. For example, if you have parameters in your URL that will return an empty space, this will escape that character and return a valid URL.

After you define the Request URL and Method, specify what type of content you are sending (dropdown list Select content type).
There are several options of content type for the API call and depending on what you select, you will be given the option to either use a Key-value pair and/or the Editor where to write the body of the API call.

Call API method types in Answers

None - select if your API has no body (only header)
Raw – use for unstructured requests (for example containing only numbers or blocks of texts). Also, can be used for content types not available on the predefined list (text/xml for example)
JSON – commonly selected for most REST API calls. For the body you can choose between key-value pair(s) or writing in the Editor
Text – supported only through Editor
XML – supported only through Editor
URL-encoded – sends the body as key-value pairs in one query
Form Data - used when sending binary (non-alphanumeric) data or a significantly sized payload

Once you select the content type, define the header of the API call (and body if necessary)
HEADER – data sent in the URL. You can enter data in KEY-VALUE format
BODY – data sent along with the URL.

For BODY you can use either a Key-Value pair or the Editor to write the body in it. Depending on the selected content type, you will either be able to choose from one of these options, or only Editor will be available (for example if content type is raw).

Key-value pair or Editor

For all content types except None and Raw, the header key-value pair will have a predefined value specifying the type. After that, if you need additional values in your header, you can select them from the list of most commonly used header options (authorization, cache-control, cookie, etc.)

Call API content types

The list is not definitive. If a key-value pair is not on the predefined list, click +ADD KEY-VALUE PAIR and add the values needed for your API call.


Responses to API calls are saved to attributes. To save the response you expect to receive, click the Response tab.

Call API Response tab

In case you want to save responses to your APIs (whether they were successful, bad, unauthorized, etc.), you can select an attribute from the Response code dropdown list.
When you expect values in the return body of your API call and want to save them, use +Add attribute and select the appropriate one from the list of existing attributes (or more than one depending on your API).
You will also need to enter the path to the attribute. The path is the location in the json file hierarchy where the value of that attribute is located. Depending on the level where the attribute is located, all the previous levels need to be included in the attribute path separated by a dot “.”.

The Timeout in seconds is how long you want to wait for the response – default setting is 10 seconds and the maximum you can set is 60 seconds.

What about SOAP?

Answers Call API now lets you send SOAP requests as well.
If you want to send a SOAP API call, you can only use xml as format. That means that there can only be one root element in that file, and in this case, it is the Envelope.

In Answers, there are two ways to write the xml for the SOAP API call.
You can either select:

  1. Content type raw and in the Header enter key-value pair: Content-Type + text/xml
  2. Or content type xml where you will have a predefined header value for the selected content type (application/xml)

When deciding between the two, consider that if a user can read your XML document (the source XML document), text/xml is preferable to application/xml.
In either case, only Editor is available for xml configuration.

Example of SOAP API call in Answers

Most SOAP APIs use WSDL (Web Service Definition Language). WSDL defines the structure of the xml, for example if an element or attribute can appear multiple times, whether it is required or optional, or the order of the elements. If the service you are interfacing with has a WSDL, it will be much easier to connect with it.
SOAP response xml will follow the same logic as the incoming request, and in case of an error, will contain the message regarding it.

Considering that the SOAP APIs are slower and more complex than REST APIs, that they cannot handle anything except XML files and do not cache information, we would recommend using REST communication protocol in Answers.

Conditions

Conditions element is used to configure the branching logic in the dialog. Depending on the values of each attribute, you can proceed differently through the dialog and branch the dialog according to different responses.

Use the IF drop-down list to select one of the available attributes and its corresponding operator (depends on the type of attribute you selected, regular, MO or NER-enabled attribute) and then finish with the value that is expected in that condition.

If you use operators Is null and Is not null – there will be no need to define the attribute further.

In Conditions element you will also be able to see the fixed attributes that exist in Answers. You don’t have to create fixed attributes to use them, they are always available.

The last column in each condition element (one that is automatically there) is Else under which branch you have to configure the option for situations where the conditions haven’t been met. This can of course be Send text to let your end user know that you didn’t catch the necessary value to continue the dialog and then using Go to Dialog transfer the end user to a more appropriate dialog.

IMPORTANT

You cannot have two Conditions elements in one dialog and can use only two additional elements after adding the conditions to your configuration. That is valid in case if the next element is not Go to Dialog in which case the conversation is completely transferred to the new dialog. If you don’t add Go to Dialog element, the NLP engine will take care of the conversation by resolving the intent and selecting appropriate dialog to continue the conversation.

Conditions element

Coding

Coding element gives you more flexibility when designing a dialog and what you can do with attribute values, and also provides encryption capabilities.

Currently, two classes are available:
• attributeAPI and
• encryptionUtils (with the following hash functions: MD5, SHA-1, SHA-256, SHA-512)

NOTE

Use JavaScript when writing the code.

You can use the element for the following:

  • randomization of available information

var items=Array(1,2,3,4,5);
var item = items[Math.floor(Math.random() * items.length)]
attributeApi.set('random',item)

  • Usage of counters (can be followed by the Conditions element to branch the results)

let correct = attributeApi.get('correct');
correct = correct == null ? 1 : (correct + 1);
attributeApi.set('correct', correct);

  • Transfer of large json files into variables (for easier manipulation of attributes)

const qa = attributeApi.get('qa');
let answers = [...qa.incorrect_answers, qa.correct_answer];
answers.sort();
let answerId = answers.findIndex(a => a === qa.correct_answer);
attributeApi.set('answers', answers);
attributeApi.set('answerId', String(answerId + 1));

  • Secure hashing of attributes

var encrypted = encryptionUtils.md5('test');
var encrypted = encryptionUtils.sha1('test');
var encrypted = encryptionUtils.sha256('test');
var encrypted = encryptionUtils.sha512('test');

 

Coding element with sample code

The Coding element also enables you to select the Theme (Light or Dark).
The Answers platform compiles and validates whether the code syntax is correct (will not display where the error occurs). The validation happens at the moment you activate the bot and an error will occur in case validation fails.

Webhook

Generally speaking, a webhook is a user-defined HTTP callback that gets triggered when a particular event occurs at the source site (for example, the user enters their authorization data). When that trigger event occurs, the webhook registers the event, collects the data, and sends it back to the URL you specified in your HTTP request (where you said that the user authentication is the trigger event you are waiting for and where you want that event information to be sent). 
Webhooks are useful when you need real-time notifications and data synchronization.
 
In Answers, the Webhook element will usually follow after the Call API element.
For example, you use the Call API element to send the webhook URL to the external system (source site). Once the requested data becomes available, the source site sends a request back, webhook receives that data and saves it to an attribute (you have to configure the attribute in the Answers webhook element).
To configure the webhook element, you need to do the following:

  • Define the Webhook URL type – there are two possible choices, to use the sessionId as a parameter, or to use it in the body of the request
  • Webhook URL – the URL is predefined and shouldn’t be changed, depending on the webhook URL type, it will update itself
  • Define the Method POST and GET are possible choices (availability depends on the webhook URL type you selected)
  • Define the Attribute(s) – where the values will be saved
NOTE

If you use Body parameter session Id, you can only use it with the POST method, and you need to define the Session ID body parameter name that will be automatically added to the Webhook URL.

Webhook URL type body parameter

If you are using the POST method, you can select an attribute from the Attribute dropdown list, and in this case, what you need to define is the path to the parameter where that value is saved.

Webhook with URL type path

The path is the location in the json file hierarchy where the value of that attribute is located, levels are defined by the number of entries separated by a dot “.”.

If using the GET method, and you want to save the value to an attribute, select the attribute from the Attributes dropdown list and define the Query parameter  which carries the needed value.

Webhook GET method example

IMPORTANT

The Webhook URL should not be changed!

Webhook element is often combined with the Call API element, so let's take a look at the following use case example.

  1. You need to authorize your end user with an external authorization service, so you use Call API element to send an authorization request towards the service which contains the webhook URL and you wait for the response
  2. Answers platform receives the response with the URL for the user authorization and you store that URL in an attribute in Answers (attribute is defined in the Call API element)
  3. The next step is to ask the user to authorize themselves through the URL you received from the external authorization service. You can use Send text element to send the authorization link to the user.
  4. After the user performs the authorization, the webhook receives a request from the external authorization service with a token that the user is authorized, and that token is also stored in an attribute (for further authorization needs if necessary).
  5. For the receipt of the user authorization and for saving the token, you use the Webhook element where you have defined the method and the attribute where the token value is going to be saved.

Delay

When you want your dialogs to run as a conversation in real life would (there is a pause between two consecutive messages while the other person types the message), you can use Delay element. It allows you to select a pause in between the elements to make the conversation seem more natural.

Add the element where you want a pause to happen in the conversation and from Delay time dropdown list select how many seconds you want it to last:

Delay element in dialog creation

Send Button for Facebook Messenger

Send Button element will appear in dialog design when you create a Facebook Messenger chatbot.

This Send Button element has a limit of 3 buttons you can use. Enter the Message you want to send as the introductory text for the buttons (character limit for the message is 1000) and configure each button:

  • Button name – text that will appear on the button. You can personalize it with attributes.
  • Action – either a URL or a Postback.
  • If URL – enter the link where you want the button to lead (you can also personalize the URL with attributes)
  • If Postback – enter text that will be used for the next step in chatbot conversation

Send button element for Facebook Messenger

For the Postback configuration of buttons, since you expect a return message when the end user clicks that button, the dialog configuration needs to continue with the Process User Input element in order to route the conversation further.

NOTE

There is a limit to the number of characters that the Facebook Messenger supports in button names so please stick to 20 characters limit (with spaces) for button names.

Send button for Viber

When you create a chatbot that uses Viber as the channel, Send button element for Viber becomes available. This element supports one button and you can only configure it to use URLs.

For the Send button element, you need to define the following:

  • Button message – introductory message for the element
  • Button caption – text that will be visible on the button
  • Button action URL – URL you want to send the end user to
  • And the Button image is optional if you want to add it (upload or link to it)

Send button element for Viber

Send Button for Live Chat

When you create a chatbot on Live Chat channel, Send Button element will be one of the available elements for dialog design.

You can upload the button image (it is not mandatory) and if you decide to do so, use either .jpg or .png format.

This  element has a limit of 3 buttons you can use.

In addition to the image, the element can have a message as the introductory text for the buttons (character limit for the message is 1000).

For each button configure the following:

  • Button name – text that will appear on the button (maximum 20 characters). You can personalize it with attributes.
  • Action – either a URL or a Postback.

        →If URL – enter the link where you want the button to lead (you can also personalize the URL with attributes) 

        →If Postback – enter text that will be used for the next step in chatbot conversation

Send button element for Live Chat

When you use Postback configuration for buttons, you offer end users the option to choose among available buttons (click one of them). This means that when the end user clicks that button, postback text will be used as the input for  the Process User Input element in order to route the conversation further.

NOTE

In cases where you fill the canvas with many elements and they are no longer visible when adding new elements, scrolling option through the canvas will appear.

Scrolling through canvas

Message Randomization

Answers enables you to vary the messages you send to your end users and enables you to enter up to 5 different messages for one text field. This feature is available in the following bot text fields:

  • Send text,
  • Attribute,
  • Fallback, and
  • Repeat.

This means that every time your end user is in the situation to receive a message that has this option configured, Answers will randomly select one of the available messages to send to the end user, thus making the user experience varied.
Once you select the element where you want to add additional messages, click on the +Add Variation option. For each message variation, add a different message.

Display of messages for randomization

INFO

You can add a maximum of 5 messages to be sent at random.

Message randomization text 2

To delete a message, click on the trash bin icon and confirm by clicking the DELETE VARIATION button:

Delete randomization message

Dialog Creation Constraints

When you create a dialog, you drag’n’drop different elements from the right panel to combine them into a coherent conversation.

The Answers platform is going to let you know where it is possible to put a certain element as the green placeholder will appear where you can drop the element.

The opposite is true as well. If you want to drop an element that is not allowed logically into that part of the dialog, no placeholder will be visible, and you won’t be able to drop the element onto the panel.

Dialog creation constraints

You should bear in mind that this will also happen if you want to add an element after Call API or Conditions in the dialog if you haven’t configured them yet.

Conditions element also has the additional restriction where you can add a maximum of two more elements under each condition branch. And they cannot be another Conditions element.

As the last element in the schema you can put the To Dialog where you transfer the end user to the dialog that is a logical continuation of the current conversation.

In case you do not finish the dialog with the To Dialog element, the chatbot’s NLP engine will handle further inquiries and try to resolve them in order to send the end user to the correct dialog.

 

Once you finish the configuration of the dialog(s), it is time to check how well they work. Go to Simulator tab to simulate the conversation between the bot and the end user.

Example of Dialog Creation

Each dialog starts with an intent element but if you create a keyword-based bot, the intent can stay empty – you don’t need to select it.

Still, when creating a chatbot, it would be best if all attributes, keywords, and intents were created before you start designing dialogs.

Create as many dialogs as you have intents. When you start designing your conversations, you will be able to move the conversation from one intent to another depending on what are your end users’ intentions.

Let's create a dialog where the end user is asking about the gate for their flight.

So, after you have created a new dialog, in the first block:

  1. Select for which Intent are you building this dialog

Now to start the conversation from the chatbot end (the conversation is already recognized as belonging to this intent), it makes sense to ask the end user for information regarding their flight. 

  1. Drag’n’drop the Attribute element underneath the intent block
  2. Enter the text the chatbot will send to the end user - asking about flight number, and, if you want, you can incorporate previously created attributes to make the message less impersonal (using variables like first_name, etc.)

As we are expecting an answer to the question for which flight the end user wants to know the gate, the following element should be Conditions.

  1. Click on the Conditions element and position it under the Attribute element.

Depending on how the flight numbers are classified, add enough branches to cover all flight number cases. 

  1. To branch the Conditions element, in the right frame add all flight number conditions and configure them accordingly.
  2. Each Conditions element needs to have a follow-up element where you answer your end user depending which condition was met.
  3. The last branch in the Conditions element is the Else branch - this is where you configure what happens in the situation when the end user reply doesn't fit with any of the configured conditions

So, now that the conditions are branched properly, you can finish the conversation by adding the element with the clear information requested by the end user:

     8. Add a new Send message element with the information what gate corresponds to the sent flight number under each condition branch.

     9. Add a separate Send message element for the Else branch to explain that the requested information could not be gathered.

And in the case of the Else branch, you can add one more element to send the end user to a different dialog, one that deals with unresolved queries.

    10. Add Go to Dialog element under the Send message element under Else branch.

Bear in mind that when you add the Conditions or Process User Input elements, the dialog has only space for two more elements to follow under each branch, one of which could be Go To Dialog (unless this is an ending dialog). The reason behind this is to ensure that the conversation experience exists without too many branches and that it isn't too complex to follow.

Example of dialog creation

This is just one example of how a dialog can be constructed. With the myriad of elements you have available, there are many ways you can construct the dialogs and make the conversations run smoothly and your end users happy with the interaction.

Once all the dialogs are ready, you can activate your chatbot.

Coding Examples

Here are some real-life examples how to use code in the Coding element.

Retrieve access list with approved MSISDNs from a 3rd party service

When there is an access list with approved MSISDNs at the 3rd party service you can use Call API to retrieve that list and store it in an attribute.

Code for getting a list od MSISDNs

var user_input = attributeApi.get('phoneNumber');
var list = attributeApi.get('MSISDNlist');
if(list.indexOf(user_input) > -1){
    response = true;
} else {
    response = false;
}
attributeApi.set('response', response);

In the coding element, you compare MSISDN from the request with the list of approved MSISDNs. If the MSISDN from the request is on that list, the end user can access the specific content.

Transfer end-user's location into latitude and longitude

When the end user sends the location and you want to determine exact latitude and longitude.

Code example for location setting

const loc = attributeApi.get('Location');
attributeApi.set('latitude', loc.latitude);
attributeApi.set('longitude', loc.longitude);

Define working hours

If the end user wants to talk to an agent, they can reach them during working hours. But outside of working hours, the end user won't be redirected to an agent.

With the coding element, you can define those working hours and configure the dialog accordingly.

Example of code for setting agent working hours

Take into account the different  time zones.

var config = [
  { Monday: {
    open: 8,
    close: 17
  }},
  { Tuesday: {
    open: 8,
    close: 17
  }},
  { Wednesday: {
    open: 8,
    close: 17
  }},
  { Thursday: {
    open: 8,
    close: 17
  }},
  { Friday: {
    open: 8,
    close: 12
  }},
  { Saturday: {
    open: 0,
    close: 0
  }},
  { Sunday: {
    open: 0,
    close: 0
  }},
  { timeZone: "Europe/Sarajevo"
  }
];

function isWorkingHour (now) {


  var day = new Date (now).getDay();
  var hours = new Date (now).getHours();

  var obj = config[day-1];
  
  for (var key in obj)
    obj = obj[key];

  return hours >= obj.open && hours < obj.close;
}
 
var result = isWorkingHour(new Date().toLocaleString("en-US", config[7]));

attributeApi.set('isWorkingHrs',result);

Detect the language of the incoming message (Latin or Non-Latin)

If you expect to receive messages in different languages and want Answers to recognize whether the incoming language is English or not, you can use the following code in the Coding element:

var input = attributeApi.get('lastReceivedTextMessage')
var pattern = /^[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"" "\\|,.<>\/?]*$/;
function isEnglish(txt)
{
    if(txt.match(pattern)) {
        return true;
    }
    else{
        return false;
    }
}
var result = isEnglish(input);
attributeApi.set('isEnglish',result);

Branch dialogs according to incoming promo messages

Use lastreceivedtextmessage fixed attribute to check whether incoming messages contain a promo code.

Example how to use lastreceivedtextmessage in Coding element

attributeApi.set('bonus_code', attributeApi.get('lastReceivedTextMessage') === 'promo code' ? true : false);

Initialize parameters only once using Global Attributes

In many instances when creating a chatbot, you need to make multiple API calls for various use cases that the bot supports. Instead of hardcoding the API details such as the base URL, username, password, encryption key (if applicable), etc., you can create global attributes for each of these parameters and then initialize them using the coding element once the user enters the default dialog.

Example of attributes for banking bot

This is the code you can use for initializing values:

//attributeApi.set('base_url', 'http://144.76.108.226:8180/WhizzAPIChannel/RequestProcessor/request');
attributeApi.set('base_url', 'https://51.144.138.141:9030');
attributeApi.set('msisdn', attributeApi.get('phoneNumber'));
attributeApi.set('username', encode('infoBipUserName'));
attributeApi.set('password', encode('infoBipPassword'));

The initialized values are then accessible in all dialogs in the chatbot as attributes (without hard coding them everywhere you need to use them).

Use initialized values in dialog creation

Should you need to change the bot environment from development to production, and the API URL and credentials change, you just need to change those details only once in the coding element.

Perform testing with a closed group of end users

In cases where chatbot development has been completed and the client wants to perform UAT on their dedicated WhatsApp sender but make it accessible only to a closed user group (specific mobile numbers).

In cases where chatbot development has been completed and the client wants to perform UAT on their dedicated WhatsApp sender but make it accessible only to a closed user group (specific mobile numbers).

  1. Create a global Boolean attribute can_access_bot (for example)
  2. In the default dialog, have a coding element that does the following:

      a) Lists all the permitted mobile numbers
      b) Checks if the phoneNumber in the active session is in the permitted list
      c) If (b) above is true set the value of can_access_bot to True, else, False


The coding element should contain this code:

 

attributeApi.set('msisdn', attributeApi.get('phoneNumber'))
var permitted_numbers = ["254721686033","254710760282"];
if (permitted_numbers.indexOf(attributeApi.get('msisdn')) > -1){
    attributeApi.set('can_access_bot', true);
} else {
    attributeApi.set('can_access_bot', false);
  1. Add a Condition element, where if can_access_bot is True, show the bot, else do not allow the user to chat with the bot.

Conditons element to confirm if true or false to talk to bot

Compare numerical attribute values

For example, if you have customers applying for loans, and the customer should not be allowed to apply for a loan amount greater than their credit score (loan limit). This loan limit varies from customer to customer and cannot be hardcoded.

  1. Create a global Boolean attribute is_valid_loan_amount
  2. After the user enters loan amount to borrow (loan_amount), use the coding element to compare the loan amount Vs the loan limit (credit_score), setting the is_valid_loan_amount to true or false depending on the comparison results
var credit_score = attributeApi.get('credit_score');
var loan_amount = attributeApi.get('loan_amount');

if(loan_amount <= credit_score) {
    attributeApi.set('is_valid_loan_amount', true);
} else {
     attributeApi.set('is_valid_loan_amount', false);
}
  1. Add a Conditions element, such that if is_valid_loan_amount is true, proceed with loan application, else notify the user to apply for a lesser amount.

Loan amount validation example

Select a valid option from dynamically generated API response

For example, if you have a banking chatbot, and the end user is presented with a list of account numbers to transact from, they should select one account number from the list. If the selected account number is not in the provided list then the bot should respond with an error message.

  1. Create a list attribute response_accounts to store the list of user bank accounts from the API response. Define the account_number attribute which will hold the account number the user has typed in.
  2. Display the dynamic list of accounts for the user to select from. The user input will be stored in the account_number attribute.

Select on of available accounts

  1. Using the coding element, validate whether the user input (account_number) is in the list of the valid account numbers:
var user_input = attributeApi.get('account_number');
var accounts = attributeApi.get('valid_accounts');
var valid = accounts.indexOf(user_input);
var index = user_input-1;
if(valid > -1) {
    var account_number = user_input;
} else if(typeof accounts[index] == 'undefined') {
    account_number = null;
} else {
    var account_number = accounts[index];
}

attributeApi.set('account_number', account_number);
  1. In the above coding element, if the account_number is not valid (i.e. it’s not in the valid list), its set to null.
  2. Using the conditions element, if the account_number attribute is null, display the invalid account number message, else continue conversing with the bot:

Validating selected account value

Allow multiple selection from a dynamically generated API response

When you have an onboarding chatbot, and want the end users to select their disability, it can be selected from a dynamically generated list (using API call). Each disability has an ID and a Name. To enable users to select multiple values, they can type in several numbers separated by space. Using a second API, the selected disability IDs (not the number options the user typed in) are passed as a single white-space delimited parameter.

  1. Create the following attributes:

Attributes needed for disabilities bot

disabilities_response – will hold the list of disabilities to select from (returned by the first API)

user_selection – Will hold the list of disabilities the user has selected

disability_found –a Boolean attribute keeping track whether the user input is valid

user_input – will store the disabilities that the user types in

api_response – complete api response in the root json path($.)

invalid_input –the user input that doesn’t match expected responses

selected_ids – the disability IDs that the user selected

  1. Display the dynamic list of disabilities for the user to select. The user input will be stored in the user_input attribute. This user input is validated using a regex expression that only allows numbers and spaces (^[0-9\s]*$)

Regex definition for attribute element

  1. Using the coding element:

a) Convert the space delimited user input into an array for easier processing
b) Loop through the elements in the array generated in the previous step. For each iteration, check if the current element (user input) is an index in the list of disabilities. If it is, store the corresponding disability in the user_selection list attribute defined in step 1. For good measure, you can separately push the matched disability ID to a separate list selected_ids (also defined in step 1).
c) Convert the selected_ids list into a space delimited string as expected by the second API call.
The final coding element should be like this:

/**
 * This validates disability type based on user input
 **/
var user_input = attributeApi.get('user_input');
var disabilities = attributeApi.get('disabilities_response');
var inputs_array = user_input.split(" ");
var selected_ids = [];

attributeApi.set('inputs_array', inputs_array);

var user_selection = [];
var disability_found = true;
var i = 0;
for(i=0; i<inputs_array.length; i++){
    var val = inputs_array[i];
    var index = parseInt(val)-1;
    attributeApi.set('invalid_input', val);
    
    if(val == "") {//Means multiple white spaces between numbers
        //Pass
    }else if(typeof disabilities[index] == 'undefined') {
        disability_found = false;
        attributeApi.set('invalid_input', val);
        
    } else { //Found
        user_selection.push(disabilities[index]);
        selected_ids.push(disabilities[index].Id);
    }
}

attributeApi.set('disability_found', disability_found);
attributeApi.set('user_selection', user_selection);
attributeApi.set('selected_ids', selected_ids.join(" "));
  1. Using the conditions element, if disability_found attribute is True, proceed with chatbot converstaion, otherwise display a validation error message.

Conditions for regex attribute validation

Find the closest ATM/branch/store location

  1. Create the following attributes: location, locationLat, locationLon, name
  2. Save incoming MO location message as the value of the location attribute
  3. Insert latitude, longitude and name in tempDataList
  4. Create a location block and use the attributes to populate the values.
var tempDataList = [
        {'lat': 25.276987,  'lon': 55.296249, 'name': 'Dubai'},
        {'lat': 24.466667,  'lon': 54.366669, 'name': 'Abu Dhabi'},
                        ];
     

var locationClient = attributeApi.get('location');

var locationCode = {'lat': locationClient.latitude, 'lon': locationClient.longitude};

var i=1;

    function distance(lat1, lon1, lat2, lon2) {

            var radlat1 = Math.PI * lat1/180;
            var radlat2 = Math.PI * lat2/180;
            var theta = lon1 - lon2;
            var radtheta = Math.PI * theta/180;
      var minimalDistance = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
            if (minimalDistance > 1) {
                minimalDistance = 1;
            }
            minimalDistance = Math.acos(minimalDistance);
            minimalDistance = minimalDistance * 180/Math.PI;
            minimalDistance = minimalDistance * 60 * 1.1515;
            minimalDistance = minimalDistance * 1.609344;
            return minimalDistance;        
        }
        
var minimalDistance = [];
        
tempDataList.forEach(myFunction);

function myFunction(value, index, array){
            
minimalDistance[index] = distance(locationCode.lat, locationCode.lon, value.lat, value.lon);
        }
     
var closestDistance = Math.min.apply(null , minimalDistance);
     
var index = minimalDistance.indexOf(closestDistance);
     
        attributeApi.set('locationLat', tempDataList[index].lat);
        attributeApi.set('locationLon', tempDataList[index].lon);
        attributeApi.set('name', tempDataList[index].name);