In the following dialog, Bob tells Dialogflow that he wants to buy a book. He also mentions that he likes sci-fi books. This is the initial intent: The first thing we need to do is map this intent to an action in Dialogflow. We can do this by adding a new action: Then we set it to Reply and we let the input be prompted with text like “What book would you like?”

Note that on this screen, the value for “Prompts” should be filled with natural language like “What book would you like?” so that it will parse correctly when it comes into Dialogflow later on. The next thing we need to do is add a new intent to help Dialogflow understand the user’s request: We can see that it already has an initial intent called “Intent” and additional intents for “book”, “sci-fi book”, and “fiction book”. We will not be using those — they are simply examples of intents that you may want to have. In this case, we are going to add a new one called — you guessed it — “book_request”.

Now we need to set up Dialogflow so that it triggers when Bob says the words “What book would you like?”: In order for your bot to respond appropriately once the action is triggered by Dialogflow, go ahead and create a response with the same name as your trigger event: Reply in this case. Make sure to also set up the appropriate responses for when he wants fiction or non-fiction books as well: Then click on Add Action and you should see something like this: Now go to your Dialogflow console and test the new action: Once you’re satisfied with the results, we can move on to mapping out Bob’s preferences.

Mapping User Preferences Inside Dialogflow

Once Bob tells his bot that he wants a sci-fi book, there are three possible ways this interaction could play out: He explicitly names a sci-fi book He asks for a fiction book without specifying which genre He says nothing and we assume that he means to specifically ask for a sci-fi book in this case. I will cover how to deal with all of these scenarios below. The first thing we want to do is add another intent so Dialogflow knows what should happen if the user gives us more information about what they want. Let’s call it “book_selection_intent” just because we need an intent name. Then we add two intents under it called “sci-fi_book_selection” and “fiction_book_selection”. We will not be using those either but they are there as examples of how you might handle the user input if you wanted to do something different than my approach. Now let’s create a trigger event for each of our possible outcomes: The first one is where the user explicitly names a sci-fi book — for instance, he says “I am looking for Dune by Frank Herbert!” We can see above that he has named his trigger event Reply but then again, technically speaking, this could happen several times over the course of this interaction so I am going to change it from Reply to SciFiBookSelection since that is more descriptive of what happens here. Then all I did was click Add Action, and then I set it to SciFiBookSelection: This is where the user asks for a fiction book without specifying which genre — for instance, he says “I am looking for a good novel!” Again, we can see above that he has named his trigger event Reply but then again, technically speaking, this could happen several times over the course of this interaction so I am going to change it from Reply to FictionBookSelection since that is more descriptive of what happens here. Then all I did was click Add Action, and then I set it to FictionBookSelection: Finally, when the user has said nothing at all to help us infer his preferences (for example “Show me a sci-fi book”) — we will use this as an opportunity to ask him directly if he means a sci-fi book or not. The only difference in creating this trigger event is that we give it the name AskForSFiBook instead of Reply. And now go ahead and test out your new interactions in Dialogflow: Now you might be wondering how these actions relate back to our initial intent? Well let’s take a look at the next part of our conversation with Bob: As you can see above, Bob hasn’t explicitly said anything about whether or not he wants a sci-fi book or not yet. So far we have only been able to infer his preferences based on his behavior (or lack thereof). Now Dialogflow knows that Bob has asked for two different books but none of them are sci-fi books yet. So now we need some way of telling Dialogflow what kind of action should happen when this occurs. We do this by setting up a new intent called “ask_for_fifi_book” and then assigning it a response like the following: Now we can see that this is what happens when our user asks for a sci-fi book: Then we can see the same thing happening if he instead asks for a fiction book. Now when he says nothing at all, Dialogflow knows to ask him directly whether or not he means a sci-fi book or not.

Bob Takes Action Inside Slack

Lastly, let’s look at what happens when Bob clicks on one of the books in our #book channel: In order to be able to set up Actions in Slack, you will need to go into your app and turn on Webhooks (the link is under “Your Apps”): Once you’ve done that, head back into Dialogflow and start mapping out the Actions that will trigger when Slack is used: In this case, we want to add a new action called “ShowBook”. Then we set it up so that it can trigger when Bob says the words “Show me a sci-fi book” or “Show me a fiction book”. This means we need to set up two different triggers: Now go ahead and test your new Function in Slack: And there you have it! You now have a bot that can handle any number of situations where users ask for books/authors/titles as well as preferences based on genre. And with the help of Dialogflow, you are also able to parse natural language queries into more structured inputs — which means that you are able to handle these requests much more accurately than if you had been relying solely on plain text input.


Marco Lopes

Excessive Crafter of Things

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *