Datamodels

Datamodels

Sometimes you need a chatbot to answer a series of questions about similar objects, like a product catalogue or FAQs.Instead of having to set up many identical dialogues, you can create dynamic dialogues with placeholders that automatically select the right data from a data model. In the Chatbot Builder, you can use the menu point ‘data model’ to create so-called entities or data models. You can imagine an entity as a table with rows and columns that house your data. Each entry in the table is associated with a unique identifier contained in the first column in the datamodel. Other columns are properties or object attributes containing various pieces of information relevant to the object.

Consider our example – a data model containling information about travel destinations – cities Munich and Berlin. If a user asks for more information on Munich or Berlin, the bot should be able to look up the datamodel and return description of the city, a wikipedia link, a picture and name of the city’s airports.

Before creating a datamodel, decide which entities (which series of similar objects) are practical for your purposes and which attributes are required. You can easily add extra attributes later and delete those that end up being less useful.

Basically, the entity feature is useful for groups of objects that have similar characteristics and that you can logically arrange in a table format. Usually the name of the entity would be an umbrella term for the included objects: for example, products in a product catalogue. The attributes would then be the characteristics of those objects.


Creating Entities

Navigate to the menu “Datamodel ” and click on the button +Entity, create a new entity. Give your entity a name and add the desired attributes with +Attribute.

Now you have two options: either continue editing the entity directly in the interface or import an appropriate table.

To edit a datamodel from the interface, click on a table-symbol “show entity data” and select an entry you wish to edit. You can use single words but also phrases as identificators, or list multiple separated by commas. Please note, that identificators must be written in lower case. It doesn’t matter however whether a user writes “Munich”, “munich”, or even “mUnich”: letter cases are ignored in user input recognition.

You can also export the entity, edit it in Excel or a comparable program and import back. Formats that can be imported include “Text (Tabstop separated) (*txt.)” and CSV, supported is UTF-8 encoding.

With a click on the trash can, you can easily delete the entity.


Using Entities in a Dialogue

A data model can easily be integrated into a dialogue.

Put the name of the entity in between two percent signs as a placeholder as user query in a dialogue box, for example %Traveldestinations%. The chatbot will automatically check the user’s query against the identifiers from the data model and will return the appropriate data from the datamodel. Attributes to be returned are addressed in the bot-answer as follows %name-of-datamodel.name-of-attribute%, for example, %Traveldestinations.description% or %Traveldestinations.city%.

In our example, a user input “hi” should trigger a greeting from the chatbot. The bot then changes the topic from “Default” to “Traveldestinations Inquiry” and asks a user to choose between Munich and Berlin. If a user type “Munich” or “Berlin”, the chatbot will automatically return the description of the city.

This is how a conversation looks from a user perspective:

Directly calling a datamodel (%datamodel%) allows to return information from the datamodel immediately as response to user input, but now elsewhere in conversation. The bot can however store information about what entry in the datamodel a user was interested in and make use of the datamodel throughout the conversation. This is done by using variables of datatype “entity”.

 


Variables of type “entity”

Variables of datatype “entity” contain datamodels. Such variables inherit the structure and properties of the entailed data model. The variable can take as a value identifiers of the entailed data model.

The variable can called in a dialogue as user input in a usual way – by enclosing its name in dollar symbols $variable-ot-type-entity$. The attributes of the data model can be retrieved in bot-answers as follows $variable-ot-type-entity.attributename$The bot can can make use of the attributes of an identified object (a table row) across several dialogues and conditions.

Here is an example of how variables of type datamodel can be used in a dialogue. Here customers should be able to retrieve certain information via a customer portal. Note, that to keep the bot-structure organized we also work with topics in this example.

First we create a new topic “customer portal” and a data model “customer”. The datamodel contains a customer database with information on the name of the customer, purchased product and appointment date. Each customer entry is identified by a customer ID.

Next, a variable “customerID” of the type entity containing the datamodel “customer” is created. The variable customerID is saved permanently.



A user writes “start”, the chatbot greets him and moves the dialogue to a topic “Ask for customer ID” where the user is prompted to enter his ID.  If the entered ID matches with one of the identifiers in the datamodel “customer”, a respective entry in the datamodel will be activated. Then the context will be changed to the topic “customer portal”, where the user can now ask the bot to retrieve various types of information about his account. With the keyword “exit” the topic “customer portal” can be left.

Here is how a setup looks like in a messenger:


Save an attribute value to a variable

It is possible to save an attribute value from an entity to a variable. This can be handy when you for example want to define target groups of users based on their product holdings.

In our example we want wo save the value of the attribute product to a variable that we can later use to form a target group.

The syntax is the following: $variableName=$entityName.attributeName$$ in this example it is $productholdings=$customerID.product$$


Making use of media in a data model

Besides normal text it is also possible to add media like images or videos to a data model.

First we add a new entity (table) “animals” in the data model. Then we add two attributes (columns) “img” and “text“. Now we fill it with data. The attribute img holds the urls of the images. The attribute text holds a description of the image.


Then we connect the datamodel to a variable. We create a variable named “animals” of type entity with the value of “animals.

Now we can make use of this variable in a dialogue. In the detailed view of the dialogue you have to switch to the image tab of the bot answer. Then you can click on the little pen symbol for editing the image settings.

Now you have the opportunity to add the image attribute from the entity with the help of the connected variable using the known Dollar syntax like this: $animals.img$

Great, you are all set and can test what you built in WhatsApp: