Answers
How to

How to

Regular Expressions

For more information about regular expressions, refer to the Concepts section.

Check Length and Format of a Phone Number

You want to check if a phone number 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.

Templating Language

For more information about templating language, refer to the Concepts section.

Retrieve Data for Templating Language Objects

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.

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.

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

Save Postback Values from Buttons and Quick Replies

When you use buttons or quick replies to make selection easier for your end users, you also want to save their choices so they can be used in other elements of the dialog(s).

In order to save the end user's choice, you need to add the Save user response element after elements with buttons or quick replies.

As mentioned in the chapter on the Save user response element, if you use it only for saving postback values, you need to delete the message input field.

Click the trash bin icon and select DELETE VARIATION – this deletes the last message variation and the field disappears (if necessary, you can add it again by clicking +ADD VARIATION).

Delete message field in Save user response element

Once the message field is deleted, continue with attribute configuration.

Select the attribute where you will save the value from the Save answer as dropdown list of available attributes.

Since in this case you only want to save the user's choice, you shouldn't configure the Repeat message, but the Fallback option is always mandatory (there is always a chance it might be needed).

Save user response element without message

Save Received XML Files

When it comes to saving XML files you receive in the response, the attribute is saved a bit differently than when using JSON and this depends on client documentation.

In the example, you can see SOAP API call which returns the capital city of any country. Keep in mind that when using SOAP API calls, it is the client who specifies how the data has to be sent.

SOAP API link example

For the response, you will need to save the data into an attribute based on the xml path. In this case we have (http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?op=CapitalCity (opens in a new tab)), so we need to access Envelope, then Body, then CapitalCityResponse, and then CapitalCityResult which contains a string that we will save in the attribute. Therefore, the configuration of the response should look like this:

SOAP response saving attribute example

The full path is: /Envelope/Body/CapitalCityResponse/CapitalCityResult/text()

Calculate distance between coordinates

Prerequisites

Integrate the Chatbot tools application with your chatbot.

Calculate the distance

Use the Geolocation Distance Calculator function in Chatbot Tools to get the distance between 2 coordinates. Example: Calculate the distance between your stores and the end user's location, and let them know the location of the nearest store.

For more information, refer to the Chatbot Tools documentation.

Convert files to Base64 format

Prerequisites

Integrate the Chatbot tools application with your chatbot.

Convert file format

When end users send you media or image files in other formats, use the File to Base64 function in Chatbot Tools to convert the file to Base64 format.

For more information, refer to the Chatbot Tools documentation.

Need assistance

Explore Infobip Tutorials

Encountering issues

Contact our support

What's new? Check out

Release Notes

Unsure about a term? See

Glossary

Research panel

Help shape the future of our products
Service Terms & ConditionsPrivacy policyTerms of use