REST web service configuration

This section describes the steps involved in configuring a weather REST web service to automatically respond to user requests. To do so, you can use the free service (API page: Attention, it is necessary to create an account to have a key.

To carry out this configuration, you must perform the following steps:

1. Creating and configuring a web service

You will find a tutorial video here:

At first, we will create a web service with analytical data.

Create a web service in REST mode to perform a GET request on Paris (see example below). To do so, go to Content > Web Services. Click Add and select REST Web Service.

The key parameter is sent by WorldWeatherOnline after account creation and the q is the city for which the weather is requested.

Then, click Save.

After saving the web service configuration, click Test at the bottom of the page.

2. Creating knowledge

The goal now is to create knowledge to provide data to the web service and to return it to users.

User sentence: the sentence should look like a request to know the weather in a given city. The important point in this sentence is to not forget the variable.

In our example, the variable is called city which is of Alphanumeric type.

The answer given to the user will show the temperature, the time and the city given by the user and the city understood by the system to identify possible differences.

It is important to note that:

  • the variables retrieved from the web service are structured as follows: ${callapi.WebServiceName.variableName};

  • the variables retrieved from the dialog are structured as follows: ${capture.VariableName}.

3. Updating the web service

After setting up the variables in the knowledge, it is necessary to update the web service to deploy them.

In the parameters, you must change the city sent to account for user input: $ {}

Then, in the result variables, you need to create 3 variables to save the data from the web service and use them in the knowledge:${callapi.TestWeather.ObservationTime},${callapi.TestWeather.Temperture} and ${}

Warning: the variable names are free but must be consistent with what is indicated in the knowledge.

Warning: the variable names must be alphanumeric or underscore characters and start with a letter. They are also case sensitive.

Save the configuration and test the web service again.

In order to make sure everything is working properly, you can start a test session of the bot and try the new knowledge.

4. Using the web service in a condition

Web services can be used in knowledge but also in conditions.

Reuse the weather service to find out if it's hot or cold in a city. In our example, it is considered that it is hot at more than 20 degrees and cold in the opposite case.

Create a new knowledge to answer.

Then create the two possible answer with a new condition that you leave blank for now:

Once the knowledge part is prepared, you have to create a new condition that will use the web service. To do so, visit the Knowledge > Advanced > Context conditions page.

Click Add a condition and create the associated condition:

Note that the operation is of Math expression type and the value must be a correct expression with x the variable returned by the expression in Condition. Here, we must check that callapi.TestWeather.Temperture > 20.

Finally, we must use this new condition in the knowledge we have created. To do so, edit the condition, select IsTempertureGreaterThan20 then click Update.

You can now test your knowledge with the bot.

Another example of configuring a REST web service

We will use the httpbin web services: and more precisely the IP web service to return the IP of the user who requests it.

First, add a web service in REST mode.

Note that in this example, we have selected a JSON response type.

Then, we entered the JSON code in the Result Variables section.

You can add as many variables as you want. Then click Save the configurationthen click on the Test button at the bottom of the page to check that the service web is operational.

If there is no error, the IP will be returned to you otherwise an ERROR element may appear. It is important to mention that HTTPS web services may not work. If this is the case, simply remove the "S" to use only the HTTP protocol.

Then go to the Knowledge page and create a new knowledge.

The function to call a web service works like this: ${callapi.WebServiceName.VariableName}

You can then test your knowledge by asking the question to your bot through the test dialog box. Ask him the question "What is my IP? And the bot will return your IP address.

Last updated

Tous droits réservés @ 2023 dydu.