We can also use the Prompts section to create more detailed, actionable commands that take into account a wider range of parameters. For example, we can create a command for our restaurant reservation app that allows us to book tables for different locations and numbers of guests: Copy code Copied to clipboard.
Copy link Dialogflow isn’t limited to just mapping simple intents. We can also map out more complex intents using the prompts within the DialogFlow console. In this example, we’ve mapped out an intent that allows users to book a table at two different restaurants and two different times: Copy code Copied to clipboard. Copy link
These Prompts help us to create a more conversational chatbot experience, where users are able to ask for different tables at different restaurants and at different times. In the next section, we’ll look at how we can turn these commands into actions that our app can execute.
Using DialogFlow To Create Actions In Our App
While it’s great that we can map out the intents in our app via DialogFlow, this isn’t really useful unless it is translated into something actionable. This is where DialogFlow Actions come in. Dialogflow Actions allow us to take the information that we get from our conversation with the user and map them into functions within our app. For example, if a user said “book table for four people tomorrow evening” then we might want to send them a calendar appointment or send them on their way to book the table themselves using an online booking system like OpenTable or Bookatable. But how do we do this? Let’s take a look at how to set up DialogFlow Actions so that they trigger when certain phrases are detected in your conversations with users:
Step 1: Creating A New Action In The Dialogflow Console We need to begin by creating a new Action within the Dialogflow console. Go ahead and click on your project name from within the left hand menu of your console and then click on “actions”. From here you can either create a new Intent or Action depending on which you wish to map a command too by clicking on “Create Intent / Action”: Copy code Copied to clipboard. Copy link Now let’s create an Action: Copy code Copied to clipboard. Copy link We’ve named our action “Reserve table for four people at restaurant tonight” and we’ve set it to “book a table”.
Step 2: Connecting Your Action With The Dialogflow Console We now need to connect our new Action with the existing intent in our dialogflow app so that it can trigger when the user asks for something within the conversation. To do this, we need to click on our new action and then click on “Connections”: Copy code Copied to clipboard. Copy link We can then search for the intent that we want to connect our new action too: In this case, simply enter in “reservation” into the search box and you should be able to find your existing intent called “Reservation for Four People At Restaurant Tonight”: Click on your Intent and then click on “Connect Action”: Copy code Copied to clipboard. Copy link Now click on your Action again (in this case, you will see that there is a green arrow next to it indicating that the connection has been made) and then click on “Test Actions On Simulator / Device”: Once you have clicked here you will see a popup appear asking you whether or not you want allow DialogFlow access inside of your app: You will be asked if you want DialogFlow to access your app via two different methods (one which allows them access via simulator or device depending on where the test is being run from). Clicking yes in both cases gives DialogFlow permission to map out any intents in your app using its own testing tools only (so as long as it has access rights!). If however you are worried about this you can only allow DialogFlow access to your app using the simulator.
Step 3: Testing Your Connections In The Simulator If you aren’t concerned about DialogFlow accessing your app then go ahead and click on “Allow On Device”, however if you are concerned about privacy or security then click on “Allow On Simulator”: Copy code Copied to clipboard. Copy link If you have clicked yes in both cases, then when you click on “Test Actions On Simulator / Device”, a popup will appear inviting you to test your connection. Clicking yes here will give DialogFlow permission to access information within your app via the device or simulator that it is being run from: Copy code Copied to clipboard. Copy link
Once connected to the simulator it should look something like this (although yours may be slightly different depending on how many intents have been mapped out): Now let’s test our connection by saying something that is contained within the intent we want our action to trigger (in this case, we want it to trigger when the user says “book my table for two people tonight at restaurant”), once we say this we should see a message appear telling us that our action has been triggered within the console: We can then view all of the parameters associated with our command by clicking on “View Action Details”: This command has sent us some data back into the console from my app including a map of where I need to book my table, who I need to book it for and at what time I need to do it at! Now that we know how Dialogflow Actions work let’s take a look at how we use them inside of an existing app!