Skip to main content

Example: Weather skill

To continue expanding our knowledge about dialogue skills, let's create a skill that allows our bots to respond to users' inquiries about the weather conditions in a city.

We can achieve this by integrating an HTTP call to an external service into our flow of steps, which will provide us with the weather information, and then providing the response to the user.

Create the skill

The first thing we need to do is create the skill. We will provide the following information in the creation window:

FieldDescriptionValue
TitleName of the skill. Preferably in lowercase and without spaces.weather
DescriptionBrief description of the skill. Must be provided in each of the supported languages.Use this function when asked for the weather of a city.
TypeType of skill. Dialogue or search.Dialogue
LanguagesList of languages supported by the skill.English and Spanish
TagsList of tags related to the skill.
Access ModeSelect the access mode for the skill. Public access or members only.Public access
MembersList of members who have access to the skill and their associated privileges.
info

You can find more information on how to create a skill at this link: How to create a skill.

Set intents

Now we need to provide a list of phrases to identify the user's intention to know the weather of a city.

To do this, we'll go to the Bootstrap Intents card in the sidebar and add some phrases that the user might write and that we can associate with our intention. The more different phrases we add, the better our bot can identify the intention. We should provide phrases in all the languages ​​we have enabled.

In our case, we've added the following intents:

Weather skill bootstrap intentsWeather skill bootstrap intents

info

You can find more information about the sidebar at the following link: Sidebar.

Define the parameters

In our weather information skill, we are going to define a parameter to determine which city we need to retrieve weather information for. Parameters are very useful because they allow our bots to understand what information they need to use their available skills.

If our bots are of the LLM type, by correctly defining the description of the skill and providing information about the required parameters, we can make the bot understand what is being asked and search in its function catalog for the skill needed to respond.

In the Parameters tab, we will create a new parameter to obtain the name of the city we want to inquire about. We will select it as type String and mark it as required. Then, we will write the description of the parameter in the available languages.

Weather skill parameterWeather skill parameter

info

We have more information about parameters at the following link: Parameters.

Define the steps

Let's now define the steps needed to provide information about the weather of a requested city. In this example, we will first inform the user that we are going to look for the information, then we will retrieve the data through an HTTP call, and finally, we will display that information to the user.

So, we will need the following steps:

  1. Write a message indicating that we are going to search for the weather of the specified city.
  2. Make an HTTP call to an external service to retrieve the information.
  3. Respond to the user with the requested information.
info

All the information about creating the different steps is available at the following link: Steps.

We will add these steps in the Conversation tab as follows:

1. Information message

We create a Say step to indicate that we are going to look for the weather information of the city provided as a parameter. This will help the user know if they have provided the correct city they want to inquire about. We obtain the value of the parameter using the following syntax: {{@parameters:city.value}}. We should provide this message in all available languages.

We can also add an Event step to inform that we are going to proceed with the query for the information.

Weather skill step 1 and 2Weather skill step 1 and 2

tip

These two steps are actually optional; we could proceed directly to querying the weather information for the city. However, it's a good practice to keep the user informed about what's happening at each moment.

2. Making the request to the external service

Now is the time to make the HTTP call to our external service that provides us with the weather information for the city indicated by the user. We can use a variety of external services to obtain this information and then process their response to retrieve the data we want to show to the user.

In this example, we have used a service called wttr.in, which with a simple GET call and a few parameters, we can obtain plain text information about the city.

We add a step of type Call API and indicate that the request is of type GET. We provide the URL of the service and add the city and the language as parameters. In this case, we don't need to add any additional headers.

https://wttr.in/{{@parameters:city.value}}?lang={{language}}&format=%l:+%c+%C+%t+%w+%m+%p+%P

The format parameter in the URL will serve to indicate to the external service what information it should provide us. In our case, we have requested information about the temperature, wind, lunar phase, and precipitation.

Finally, we specify that the result of the request should be stored in an entity called response.

Weather skill step 3Matrix skill step 3

tip

You can find all the information about this service at the following link: wttr.in

3. Response message

With the response information from the external service, we can now reply to the user regarding the weather information they requested.

In our case, we'll add two more steps. The first step is a Say type step to directly show the user the response provided by the external service. We can do this because this service provides the response directly in text format. However, if the response were in JSON format, we would need to process it and extract only the fields we need.

We'll add the response from the service to our say step using the entity we previously stored, like this: {{@response:body.value}}.

Finally, we can pass this information to our bot to interpret the results and present them to the user in the best way possible. We'll do this by adding an Assign step and assigning the response from the external service {{@response:body.value}} to the Output variable.

Weather skill step 4 and 5Weather skill step 4 and 5

Make sure you have saved your changes by clicking the Save button.

Test Skill

You can test the newly created skill using the Test Skill tab.

info

All the information about the Test Skill tab is available at the following link: Test Skill.

We can also test the skill by assigning it to one of our bots and using the Test Bot tab, or directly by using the chat of our bot.

And now we have a powerful function in our bots to provide us with weather information for any city we desire. 🌤️

Weather skill chatMatrix skill test