Creating our own Intents

Now that we have our entity defined, we’re going to go ahead and create the mechanism used for mapping the users input to the actions to be performed by our application — this mechanism is known as an intent. For this part of the development for Fret, besides from the welcome and fallback intents, we’re going to add just the one intent to our application — this will be the learn.chord intent.

Within our intent, we’re going to want to go ahead and define some conversational triggers which will cause our Intent to be fired up. Our aim here is to tell the user how to play a guitar chord, so we want to listen for terms that will lead to this point in the conversation. Here are some of the terms that I have defined for the intent to listen for:

Now whenever our user inputs any of these terms, our intent will be triggered. So for example I could say “Hey, I want to learn how to play a chord” or “Would you be able to tell me how to play a chord” — when this happens, we need a way to grab some more information from the user about the chord they want to know about.

This is where out Entity comes into play. Our Entity is a piece of data (known as a parameter) that we need to get from the user, so we’re going to add it here as a required parameter when our Action is in process.

When you create a parameter you need to give it a:

Parameter name — This is simply a unique reference for the parameter

— This is simply a unique reference for the parameter Entity — This is the entity which the parameter represents. This can either be one defined by the Api.AI system or one that we have defined ourselves

— This is the entity which the parameter represents. This can either be one defined by the Api.AI system or one that we have defined ourselves Value — This is the value assigned to the parameter, in this case $chord will be the resolved value that has been extracted from the users input.

You can also add a prompt for a parameter. So when the Intent is triggered, one of the prompt variants will be used to ask the user to input the required parameter. The nice thing here is that you can add variants of the prompt to make the conversations with your tool feel more natural.

The last part of setting up our intent involves ticking this Use webhook checkbox. Now if your conversation doesn’t require any form of external operations (such as API requests) then you won’t need to do this. However, ticking this means that the response for our intent will be handled by the webhook that we will be providing. In the case of Fret, this will be the task of fetching the details on a chord based on the one requested by the user.

But first, we need to create our function that will handle the creation of our chord to feed back to the user — this is also the point where we will receive our webhook URL.