My first skill
To get started with skills in Ainhoa, let's create a simple example of a dialog skill to get an idea of the potential this tool offers.
The main idea of the skill we are going to implement is to identify an intent from the user and ask them a simple question, and then act accordingly based on their response.
Using a somewhat geeky π example, we'll identify if the user is asking about "Matrix," and if so, we'll propose that they choose between the red pill π΄ or the blue pill π΅.
Create the skillβ
The first thing we need to do is create the skill. We will provide the following information in the creation window:
Field | Description | Value |
---|---|---|
Title | Name of the skill. Preferably in lowercase and without spaces. | matrix_pills |
Description | Brief description of the skill. Must be provided in each of the supported languages. | Use this function when the user wants to know what Matrix is or wants to enter the Matrix. |
Type | Type of skill. Search or dialogue. | Dialog |
Languages | List of languages supported by the skill. | English and Spanish |
Tags | List of tags related to the skill. | |
Access mode | Select the access mode to the skill. Public access or members only. | Public access |
Members | List of members who have access to the skill and their associated privileges. |
You can find more information on how to create a skill at this link: How to create a skill.
Set intentsβ
Now that we have our skill created, we need to indicate how to identify the user's intent. In this case, the intention is "Matrix," and we will identify it if the user asks what Matrix is or wants to enter the Matrix.
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 intent. The more different phrases we add, the better our bot will be able to identify the intent. We must provide phrases in all the languages ββwe have enabled.
In our case, we have added the following intents:
You can find more information about the sidebar at the following link: Sidebar.
We're also going to add the possible responses the user might give us as intents. In this case, the options are Red and Blue. Let's go to the Intents tab and add two new intents with values in the different supported languages, as shown below:
You can find more information about the Intents tab at the following link: Intents.
Define the stepsβ
Now that we have created the intents, we can start defining our conversation by adding the necessary steps. In this example, what we want to do is, once we have identified the user's intent to learn more about Matrix, ask them a question to choose which pill they want and then display a message according to their choice.
Therefore, we will need the following steps:
- Send a welcome message to the user to let them know that we have detected their interest in learning more about Matrix.
- Ask which pill they want to choose.
- Provide a response based on their choice.
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. Welcome messageβ
We create a step of type Say with our welcome message, we won't provide any condition for it to execute, so it will always be executed, and we select that the next step is Continue. This will allow the flow to move to the next step.
2. Ask the questionβ
Next, we ask the user to choose the option they want. We'll do this with a Ask step, not setting any condition so it executes always.
We provide the question text in different languages and select the two intents we added, Red or Blue, as possible response options.
We assign the response to an entity named pill. Finally, we set the next step to Continue to proceed with the flow.
The user can select one of the two possible responses, Red or Blue, but they can also directly type the response into the chat. If the user's response does not match any of the intents we have defined (#red or #blue), the skill will display a message saying that it did not understand the user's response.
3. Reply messageβ
Finally, we need to check the user's response and display a different message depending on the chosen option. We can do this by creating two different steps, one for the response if the choice is Red and another for Blue.
We'll use the condition field to identify the selected option and display one message or the other. In this case, since we previously added intents for the possible user responses, we'll create a step with the condition #red
, which will display the desired message when the user selects the Red option. And we'll use the condition not #red
to respond when the user has selected the Blue option.
We write the text we want to display for each of the options and mark the next step as Finish to end the flow.
You're right, we haven't used the pill entity where we stored the user's response. This is because we used intents to provide possible responses to the user. However, we can still use the value provided by the user in our condition, as in the following example: @pill.value = "red"
.
Don't forget to provide the texts in the different supported languages in your skill to ensure it works correctly for all languages.
Test skillβ
We have everything ready to test our skill and see if it behaves as expected. Before proceeding, make sure you have saved the changes by clicking on the Save button.
Click on the Test skill tab where you have a chat to interact directly with our newly created skill. You can change different parameters such as languages for testing purposes.
All the information about the Test skill tab is available in the following link: Test skill.
To initiate our skill, simply type in the chat, and you can see how the sequence of steps we defined is executed. You can also click on the chat messages to view associated debugging information, which can be very useful in your testing.
You can make changes to your skill and quickly test the results in different conditions before publishing your new version.
Congratulations! π You now have your first skill ready to be used in your bots. You can continue exploring the rest of the examples to keep learning how to harness the full potential of dialog skills in your bots.