01 Dialogflow CX Beginner Tutorial

Course: Learn Dialogflow CX

Lesson: What is a state machine?

What is a state machine?

[00:00] So in this set of slides, I am going to explain what a state machine is. And as I start, the first thing that I would like to point out is if you go to the Dialogflow CX documentation page, you will notice that the first thing it starts with is it says Dialogflow CX provides a new way of designing agents, taking a state machine approach to agent design. What is a state machine? It is a concept from computer science.

And if you go to, let us say if you go to Wikipedia, you can see that unfortunately, this is a very complex explanation. And I would not call it the most simple explanation for the state machine. There is no need for you to get for you for the definition to get this complex. Although a good thing is that the state machine definition does talk about this vending machine. And I think that that is probably the simplest definition that you can have for a state machine.

[01:04] The vending machine is a good example of a state machine, because it goes from state to state, depending on how much money you have added into it. Depending on the state, that is the balance that you have in the coins that you have added to the vending machine, you can actually choose different products. And depending on the state, that is the balance, you will get a different amount of money back from the machine.

If let us say the product that you pay, the product that you selected is less than the amount that you pay. I am going to take a simple example here. Let us say that you start with 0 balance, that is one state, that is the state, the vending machine is in the state of 0 balance, and you add 25 cents or a quarter. At that point, the balance has now become 25 cents, that is the new state, the new state is where the balance in the vending machine is 25 cents, you add one more quarter, and now the state has become 50 cents, that is the balance of the amount in the vending machine is now 50 cents.

[02:21] And then you add another quarter, it gets to 75 cents, and so on. Now, let us make it a bit more useful and interesting.

Let us say that you have exactly 3 products in your vending machine. And those are a Snickers bar, which costs exactly 25 cents, you can have a Twix, which is exactly 50 cents or a KitKat, which costs exactly 75 cents. You start with the 0 balance, and then you insert a quarter into the vending machine. Now, at that point, because you only have a balance of 25 cents, the only product that you can buy is the Snickers bar.

[03:05] If you were to select any of the other products, as you might know, the vending machine will usually complain that you do not have enough balance to buy any other product, at least any other products in this list. And then let us say you add one more 25 cents. Now, you can select either Snickers or Twix. And if you were to select Snickers, and you ask for the refund, you will get 25 cents back.

On the other hand, if you select Twix, that means your balance has now come down to 0, which means that you do not get any money back if you were to ask for a refund. It will just say that it is empty balance or something like that. And finally, if you were to add one more quarter, at that point, you can select any of these three items. You can either go for the Snickers or the Twix or the KitKat. And in fact, you can even go for one Snickers and then one Twix, and the vending machine should still be able to handle that, because the sum of these two is only 75 cents, which you do have in that balance.

[04:10] That is the basic example of a vending machine. And I think that understanding this is sufficient for you to understand how the agents are constructed in Dialogflow CX. I do not think from what I have seen till now, I do not think that you need to complicate this any further than just understanding a basic state machine like the vending machine example that I have shown here.

Lesson: What we are building

What we are building

[00:00] Now that you understand the concept of the state machine, we will build a bot which is going to use the concept of the vending machine and we are just going to call it Vendy and I think that it is probably the simplest way to get started with Dialogflow CX. And when I say the simplest way, I mean that it is the simplest way where you have a Dialogflow CX bot which is actually built using all the Dialogflow CX features.

You can build much simpler like FAQ bots and things like that which do not even have like state changes, but that is not really a use case for Dialogflow CX. In that case, you could as well just stick to the old version of Dialogflow ES which has a very generous free tier and is much less expensive. The bot that we are going to build is going to be called Vendy, it is a vending machine bot and the only unit of currency that it accepts is a quarter that is the vending machine which is a quarter is 25 cents as you know.

[01:11] And there are three products like we saw before, you can get a Snickers for 25 cents, you can get a Twix for 50 cents or you can get a KitKat for 75 cents. And the user can say the following phrases, this is the list of phrases that the user can say and what we support.

They can either say add a quarter which is their intent is to add a 25 cents coin into the vending machine, then they can ask what is my balance and it is going to tell them how much money they have inserted into the machine, what can I get with my balance. In this case, it is going to tell them the different products which they can buy using the balance they have and they can select one of the three products by saying give me a Snickers, give me a Twix or give me a KitKat.

[02:03] And finally, they can also say return or refund my balance. These are the different phrases or you can say these are the different things that the user can say to the Vendee bot and it has to perform actions according to whatever the user has said.

Lesson: Initial Demo

Initial Demo

[00:00] As I start, I just wanted to give you a quick demo of the Vendee bot. And this one, which whatever I have built till now is an even more simplified version of the bot, but I’ve just added it here to show you what we are trying to do. So you can see that there are, this sort of looks a bit like the state diagram that we saw in the slide, where it goes from state 0 to State25 to State50 to State75.

And you can also get to that from the start state. And you can see that, you know, you see these arrows here, they are meant to indicate the action of adding a quarter, okay. And you can actually, I have built it out a little bit, I’ll just go show you a quick demonstration. So if I were to say add a quarter, you can see that it just comes back with, okay, I have added a quarter.

[01:06] That means it understood what we are trying to do, right? Then I can say, what is my balance? And you can see that it says your balance is 25 cents. Then I add a quarter again. It said, okay, I’ve added a quarter to your balance. And then I ask again, what is my balance? And now you can see that it says your balance is for 50 cents.

Then I add one more quarter. And it says I have added a quarter. And then it asks, what is my balance? And notice that it says your balance is 75 cents. No, that is all I have. You can’t add any more quarters. It’s sort of like you end the accepting the quarters at this point in your state machine. You can build it out to how many other states you want, of course.

[02:00] But this is all that we are concerned about, because this is an example bot which is supposed to explain how Dialogflow CX works. So this is the sort of bot that you can build by using Dialogflow CX. And of course, I’ll probably add something here. This is a very representational bot in the sense that this is a beautiful state machine bot, which actually is a state machine, acts like a state machine in every way.

But the important thing that we care about is to understand this concept so that we can adopt it to a conversational agent that you might build, where in your case, as you are building out your bot, in some ways, you might say that this is too simplistic a bot to build in the real world scenarios. At the same time, I think that getting started by building a bot like this will also give you a much faster way to understand how Dialogflow CX actually works.

[03:11] Thank you.

Lesson: Terminology

Terminology

[00:00] So as we get started, I would like to point out a tutorial or an article that I have on my site, which is talking about tips for learning Dialogflow CX. And if you go down the tutorial, you will find something interesting. I ask that you ignore all the complex terminology when you begin learning Dialogflow CX. And an example of the complex terminology would be things like scope and state handlers and things.

And I want you to remember this as I go through the next set of videos, because I will be walking you through a set of steps, and I will not be explaining everything that you see on the screen. And it is quite intentional, because there is a lot of stuff which you might see in a screen full of, you know, the video that you see, which is not relevant at that point, as you are trying to learn how Dialogflow CX works. So I just wanted to point this out, because that will prepare you for what the next set of videos, which are going to come.

Lesson: Initial View

Initial View

[00:00] So now I am in the Dialogflow CX web console and this is what you see. You will see a screen similar to this when you are creating your bot and I do recommend that you choose a single project and create multiple agents under that same project because you do incur some type of like limits, you do have some kind of limits as you are using your Dialogflow slash Google account and making sure that you have multiple bots under a single project, make sure that you maximize the number of projects which are allotted to you.

So now I am going to create a new agent and I am just going to call it Vendee and let us, I do not want to change anything here, let us just go ahead and save it. And notice that as soon as I do that, you are just taken to this start page and you see this thing called the Default Start Flow. I will just walk you through the list of things that you see here, although I would say that you do not have to really understand everything that you see on the screen right now and we will be going over a lot of things in detail at a later point.

[01:13] So for now, the first thing you see is that there is such a thing as a Default Start Flow okay. And what you see here is the start page and also see that there are two more pages and in the case of Dialogflow CX, pages are, they represent states, it is similar to the states that we saw in the state machine for the vending machine diagram that you saw before.

So you have these predefined states, the start state and if you scroll, rather you hover over it, you will notice that it says when a flow becomes, initially becomes active, this page becomes the current active page. Once again, do not worry too much about what it means when it says the current active page and things like that. Just know that as soon as you create a new bot, you will have these three pages show up by default to your, they are just added to your agent okay.

[02:09] And the Default Start Flow is your, I would say the visualization of the set of pages that you have. A flow is actually, you can think of it as like a set of states okay. Now let us click on the start page and notice that it has an intent route.

Actually there is just a single one. If you were to click on this, it will say add intent route which indicates that you can have many of them here and you have condition route and event handlers. So I’m not going to go over condition routes or event handlers at all in the first set of videos. We’ll be concerned only with the intent routes and you can already see that there is a Default Welcome Intent and let’s just go ahead and click on it and what you see again is quite a few things and a lot of things that you don’t really need okay.

[03:04] So there is the intent name which is called Default Welcome Intent and if I were to click on edit intent, you will find that it’s going to open this list of training phrases which you have seen many of these before. Let’s just go back to the previous view and then there’s this condition. I want you to ignore it and then you have this fulfillment which just provides the response from the agent okay and then you have a bunch of things after that which I want you to ignore too.

Now let’s go ahead and just test what we have as it stands. If you were to just say hello, you can see that it comes back with a response which was already provided in the Default Welcome Intent okay and you can also see that it points out that the Default Welcome Intent has been mapped to the user’s training phrase. So that’s what we have to start with and over the next few videos, I will be modifying this bot to add a lot of things that we saw in the vending machine flow diagram.

Lesson: User asks for balance

User asks for balance

[00:00] So as I pointed out in the previous video, a page represents a state in your vending machine flow diagram. So what I am going to do now, if you remember the vending machine flow diagram, you had 4 states, you had the state of 0 balance, 25 cent balance, 50 cent balance and 75 cent balance. So what we are going to do now is create a page representing each of these states.

I am going to add a page and I am going to call it state 0 and I want you to notice that it comes, it gets added under the list of pages but it is also added into a new section so that you do not confuse it with the defaults which are always present in any given flow. And then you have State25, then you have State50 and then you have State75.

[01:07] So I am just making it very simple, calling the name of the state by the remaining balance at that point in the interaction you can say. So now the next thing I am going to do is when the user asks what is my balance, I want the bot to provide the balance to the user based on what state they are in.

Now there is a question that should be on your mind right now which is how does the user go to any of these states and that is a good question but we will come to that later. Okay, so for now what I am going to do is I am going to just go into the start page and notice that the start page is actually different from the state 0 and I have a reason for that and you will understand why as I go through this set of videos.

[02:01] What I am going to do is create a new intent okay and notice that here in the selection you can either select a new intent or you can select an existing intent. I am going to say new and here I am going to say what is my balance, that is just an indication that the user is asking for their balance okay. Now it says what is my balance that is the training phrase, let us press enter and let us go ahead and save it.

Now ignore this condition but come down to this fulfillment section and here the agent should say you have not yet added any money, please begin by adding a quarter alright. So that is all and you do not do anything else after that just go ahead and save it okay. So now if I were to go to the test agent and if I were to say hello, you can see that it got mapped to the Default Welcome Intent as expected and if I were to say what is my balance, it just says you have not added any money, please begin by adding a quarter okay.

[03:17] So what I am going to do now is I am going to add another intent here called into the intent routes of the start state and this time I am going to create a new intent and call it add a quarter okay.

So let us just go ahead and type that in add a quarter and let us just go ahead and save that alright. Now in the fulfillment the agent is simply going to say okay I added a quarter and we do not want anything else, the agent to say anything else other than sort of like echo back what the user did but this is the important thing.

[04:06] After this has happened that is the agent has responded back with okay I added a quarter, the next thing that I want you to do is go down to this transition and click on State25. So what are we doing here? This is an example of moving from one state to another that is what this transition means.

So if based on the fact that it is called page transition, you should be able to somewhat understand that it is effectively saying that you are moving from one state to the other state and if you remember the vending machine bot, if you were to add a quarter from the start state, it should go to the state called the 25 cent state which is what we represent here as State25 right and I do not want you to do any of the other things over here just ignore all these things and just save this intent that we have created.

[05:07] So right now in the start state we have default welcome, what is my balance, add a quarter okay and the thing is let us say that the user says add a quarter right and that actually fires this intent as you can understand and it also goes to this new page called State25 by doing this page transition but how do you know that you are in State25?

See right now State25 is completely empty right so what I am going to do now is I am just going to edit fulfillment okay and I am going to say something like you have entered State25 okay let us just make it simple right so let us do that and as I test the agent I think it will become quite clear what is going on here.

Lesson: Testing it in the simulator

Testing it in the simulator

[00:00] Now let us just click on this to test the agent in the simulator, let us just start by saying hello. It just says hello, how can I help you, right. And then I am going to say what is my balance, it says you have not added any money, please begin by adding a quarter, ok. Now, if I say add a quarter, see it did two things.

If you notice the first thing it did is that it actually responded with ok, I added a quarter and then also see that it says you have entered State25. And the reason for that is because in the start state, if you were to go to add a quarter, you will notice that the intent already has a response coming back, which is ok, I added a quarter and then it does a transition to a new page that is a new state.

[01:02] And if you notice in the new state called State25, it has something called an entry dialogue, which actually says that you have entered State25. That is why the response that you see here has two phrases, ok, I added a quarter and it also says you have entered State25. With just what we have seen till now, you should be able to understand a few things. The first is that the states that we see here, the states that we see here, or rather the pages that we see here, sorry, the pages that we see here represent states in your state diagram, right, that is the first thing that you understand.

The other thing that you must notice is that when you are in this state, you can, the user is able to say a certain set of phrases and the bot is, you know, programmed to behave in a certain way, but I hope that you also noticed one more thing.

[02:05] If I were to click on the Default Welcome Intent, you can see that the user could say any number of welcome phrases like hi and hello and all that. And you can see that the fulfillment here says that, you know, how can I help you, how can I assist and all that, but notice that this is empty, right. What happened here is that the user types a message, right, and the agent comes back with a response.

We know that this intent was mapped, but because it did not transition to a new page, that is a new state, it is still going to be active for the other phrases which you have defined in the set of intent routes. I hope that you are clear about that, because that part is, I mean, you need to understand that before you can move on to the, you know, the future videos, because here’s the thing, there is a lot of things going on here, really, I would say that even though this part is very simple, it’s still actually doing a lot of things.

[03:15] It is simultaneously trying to understand which set of intents are actually candidates to fire at a given point in the conversation. Now, if you notice in the tips for learning Dialogflow, the article that I pointed out before, one of the first things that I will say there is you should understand how Dialogflow ES works, and in ES, there is this concept that I defined called candidate intents.

Now, I came up with the term candidate intents, I don’t know whether Google calls it exactly the same thing, but the concept is quite similar. It is that at any given point in the conversation, not all intents that you have defined can fire.

[04:05] There are only a subset of all the intents that you have already created, which are eligible to fire at the point in the conversation, and that’s decided by a set of factors. In Dialogflow ES, it’s based on the context which is active at that point. In the case of Dialogflow CX, it is based on the actual state, which is, in fact, represented by a page in your CX agent.

So the reason I’m saying all this is because you have to understand that as your user types something, what response you get actually depends on which page is currently active, that is, which state is currently active. We will be looking at this in quite a lot more detail later on when we talk about scope and stuff, but for now, this is an important thing to understand. And that is also why when you clicked on, I’m sorry, when the user said, add a quarter, it not only came back with the fulfillment response saying, okay, I added a quarter, but it actually, you know, it affected the state transition.

[05:15] And we know that it affected the state transition because it also came with the, it also provided the response, which is, you have entered State25.

So you saw that it did all of those things when the user said, add a quarter into the start state. So all these things you need to recognize as we are moving forward to the next video.

Lesson: No state transition

No state transition

[00:00] Like I pointed out in the previous lesson, there is an important distinction between the two intent, intents called what is my balance and add a quarter and the difference is that the intent called what is my balance does not have any page transition at the end while the intent called add a quarter does have a page transition at the end and it goes to this thing called State25. Now if you were to represent that on the state flow diagram that we had seen before, this is what it will look like.

Now for a moment I want you to imagine that instead of saying balance zeros and this is the start state, effectively they are similar but there is just a small few differences and that is why I had to create a new state for that, we will see that later. But for now let us just pretend that that is what it is and here this is how we represent action which effectively does not change state.

[01:03] So when the user is asking what is my balance, you will have to do, you will have to provide a response that is the agent does provide some type of response which we saw in the fulfillment but it is not changing state. So the way you represent that in a flow diagram is just having an arrow which starts from a given state and then it just loops back into the same state. Now there is one more thing that I want you to notice, right.

Imagine if you had to cram all these possible actions corresponding to all these possible states into a single diagram, you will notice very quickly that it becomes so dense, so information dense that you cannot make sense of anything, right. So that is one more balance that Dialogflow CX has to achieve in its, you know the state diagram representation and I just want you to remember that because it is quite easy to look at the agents which are provided in the pre-built, they actually provide a set of pre-built agents and you can go and take a look at some of these, I will do that I think in the forthcoming videos and you just take a look at the flow and it all looks like really really complex but there is a reason for that because the more states and the more actions that you want to handle for each state which is the same as saying that the more things that you want the user to be able to say and be able to handle it properly in your Dialogflow bot, the more complex your flow diagram becomes just automatically.

[02:46]

So Dialogflow CX is an attempt to somewhat restrict and I guess you can say that visualize that information, present that information in such a way that it strikes that balance and you will notice that sometimes it does, sometimes it is probably not so great but ultimately that is more a result of the actual complexity of your bot than because the way the CX visualization works.

[03:16] In any case this is something that I want you to remember if you want to have, if you want to picturize the flow where no transition happens, if you want to picturize the action where no transition happens, you will have to imagine the arrow which actually starts from a given state and then loops back to the same state and then you might want to add the corresponding text on that arrow.

Lesson: Add state transition

Add state transition

[00:00] So now let’s add more state transitions into our bot. If you go and click on this State25, the state, you will see that the only thing that we have right now is you have entered State25, the entry dialog. What I’m going to do is I’m going to add an intent in the intent routes in this page. So here, this is one of the nicest features in Dialogflow CX. You can just reuse an intent you have declared before.

So in our case, we know that we already created this add a quarter intent which has this phrase which just says add a quarter and now when I select that intent, notice that it allows me to change the response. In other words, you can have different responses for the same intent based on which page you have added that intent into. That is what is the state, the current state of the bot and that makes perfect sense if you think about it because if you are in State25 and you add 25 cents by adding a quarter and let’s say that the agent is going to give you the balance, right?

[01:13] If it’s in state zero and you add a quarter, the balance here, it should say 25 cents. On the other hand, if you are already in State25 and then you add a quarter, the balance should say 50 cents. It shouldn’t say 25 cents, right? So this is an important distinction because in the case of Dialogflow ES, you will come back, it will come back with the same response.

When I say it comes back with the same response, what I’m really saying is yes, you can select from a set of possible responses but that’s actually selected at random as you know, right? Here the concept is very different. You took an intent which we have already declared but you have changed the response not randomly selected from a list but you have actually changed the, you know, the meaning of the response because you are able to edit the fulfillment depending on which state you are in right now.

[02:11] But in our case, I’m just going to say you have added a quarter. I’m not going to provide the balance here, that’s what I mean but I will change the state to State50. That is, I’m going to transition to the page called State50. So let’s save this.

Now let’s go to State50 and if it doesn’t open, you can actually click on this edit here and in the fulfillment, I’m going to say you have entered State50. Okay, now save it and let’s test it quickly. I’m going to start with add a quarter. You can see that it’s coming back with okay, I added a quarter, you have now entered State25.

[03:03] It’s already in State25 so if I were to say add a quarter again, you can see that it says you have added a quarter, you have entered State50 which is exactly what we want. So let’s continue in that same fashion. Now we are in State50, let’s edit State50 and go to the page view of, okay, what I’m going to do is minimize this and expand this.

State 50, we will add a new intent. Well, we are just adding the old intent back into this new page and once again, the agent says, okay, you have added a quarter and then it will transition to State75, right? Let’s save that and let’s go to State75 and in the entry dialog, we will just say you have now entered State75.

[04:06] That’s pretty much all we have for the, in terms of changing the state. So let’s go ahead and test the agent. We start by saying add a quarter, you have entered State25, then I say add a quarter, you have entered State50, you say add a quarter and you can see that it’s now entered State75.

We don’t allow the user to add any more quarters. You remember the logic of the vending machine. So this is explaining to you what is going on in terms of the state transitions, that is the page transitions in our bot. And if you come to the visualization of the flow, you can see that it’s got this nice, I guess you can say that it’s got this nice flow diagram where you can see that the bot is able to move from start to State25, to State50, to State75.

[05:09] Now you may not be able to see the full details. So if you remember the image that I had here, you can even see exactly which text moves it from which state to which state. That level of granularity is not available in the overall view in your CX console, but you could click on this, right?

And then you can see, you should click on this specific intents and you do have this information here. And of course, the reason for that is because they are trying to provide you with the most compact representation of the flow diagram. If it was, if they tried to provide all this information in one view, I am pretty sure that there will be so much information on this page that you’ll not be able to make sense of what is going on. So they have to, you know, decide on some kind of trade-offs as to how much of a high-level picture they can show on this flow diagram.

[06:05] And I think that to me, it looks like a reasonably good balance till now. So what we’ve done now with this particular video is that we’ve added all the state transitions into our Vendee bot.

Lesson: Ask for balance after transition

Ask for balance after transition

[00:00] So now let’s modify our bot to report the balance amount at each state. So let’s go to the start state and you know that if you were to click on what is my balance, it’s just going to say you haven’t added any money, please begin by adding a quarter, right? So now let’s go to State25. We don’t go to state zero yet in this flow diagram, so we don’t have to worry about it. Now I’m going to add an intent and I’m just going to select what is my balance just like I did for the previous type.

Now here, the agent is just going to say your balance is 25 cents. So notice that there is no transition to any new state because all we are doing is asking for the balance, right? So it’s just going to come back with what is your balance is 25 cents, it’s just going to give you a response and not do any page transitions. Let’s save that. Let’s go to State50 and do basically the same thing.

[01:03] You just ask, add what is my balance and then provide the answer here. Your balance is 50 cents, save it. No need to do any page transitions here either. And in this case, you have to add a new intent and go to what is my balance and the dialogue should be balance is 75 cents.

Okay, so that’s all we have and we have effectively hard-coded the responses into each of these states. So that now if you were to test the agent, we say add quarter and if I were to ask what is my balance, you can see that it says your balance is 25 cents, then you add a quarter again.

[02:00] What is my balance? You can see that it says your balance is 50 cents, add a quarter, what is my balance? And you can see that it says your balance is 75 cents. So this is how you’re going to modify the bot so that it reports the balance that the vending machine has at each state.

Lesson: Assignment 1

Assignment 1

[00:00] Just using what you have already learned, it should be possible for you to do a few more things and just based on the state machine idea and the concept of page transitions that we have already learned, you should be able to first of all ask the Vendee bot what you can get with your current balance and based on the balance the bot should be able to give you different answers. And you should be able to ask for specific candy or specific you know product and it should be able to provide it provided the balance is available and finally you should be able to ask it to return the balance whatever you have added into the vending machine and you should be able to return the correct balance.

The first assignment is to find out what you can buy with the current balance that you have. What I am going to do is I am going to say add a quarter and you can see that it says you have entered State25 and I am going to say what can I get with my balance.

[01:12] You can see that it says your current balance is 25 cents you can get a snickers bar which is the only thing you can get with 25 cents. Right now I am going to say add a quarter and it says you have entered State50 and now I can ask what can I get with my current balance.

You can see that it says your current balance is 50 cents and you can get a snickers bar which is 25 cents or a Twix which is 50 cents. Let us go ahead and add one more quarter and now it is in State75 and now I can ask what can I get with my balance and you can see that it says your current balance is 75 cents and you can get a snickers bar a Twix or a KitKat.

[02:04] And this is your first assignment using just the concept of page transitions you should figure out how you can build the bot so that it comes back with the responses that you have seen in this in the simulator demo that I have just shown you.

Lesson: Assignment 2

Assignment 2

[00:00] Okay, so the next assignment is to allow the user to actually buy a product. Now, what I’m going to do is, as soon as I start, I’m going to say, give me a Snickers, okay? And you can see that it says, you need at least 25 cents to buy a Snickers, your current balance is zero cents, because we haven’t added anything, right? I’m going to say, add a quarter, and it says, okay, I added a quarter, you entered State25. Now, I’m going to say, give me a Snickers.

And you can see that it says, okay, here is a Snickers bar, your balance is now zero cents, which is great, wonderful. And the next thing I’m going to do is, I’m going to say, give me a Twix. You can see that it says your balance must be at least 50 cents to buy a Twix, your current balance is zero cents. What I’m going to do is, I’m going to add a quarter, and I’m going to say the same thing again, give me a Twix.

[01:01] And once again, it’s not going to allow you to buy, because your balance is still not sufficient. Let’s add another quarter. And now, I’m going to say, give me a Twix. And this time, it’s coming back with, okay, here is a Twix, your remaining balance is zero cents, okay? Now, let’s just change it a bit. Let’s add a quarter, add another quarter. And now, the balance is 50 cents.

And if I were to say, give me a Snickers, you can see that, okay, here’s a Snickers bar, your balance is now 25 cents. And because I still have 25 cents left, I should be able to get another Snickers bar. Let’s check that. Give me a Snickers. And you can see that it says, okay, here’s a Snickers bar, your balance is now zero cents. If I were to get, try to get one more Snickers, it should refuse it, because I don’t have any balance left at the moment.

[02:04] This is the flow, which you should, again, you should be able to do all this just using page transitions, and the state machine concept that you’ve already learned. And you should be able to move the, move the bot from state to state based on what balance is available based on the action that the user has performed. This is the second assignment.

Lesson: Assignment 3

Assignment 3

[00:00] So the third assignment is to be able to return the balance that is left in the vending machine, you should return it back to the user. In this case, what I am going to do is I am going to say add a quarter and it says you have entered State25 and if I say return my balance, you should say okay I have returned your balance of 25 cents, your remaining balance is now 0 cents, you can check that by asking for a product, give me a Snickers and you see that it says you need at least 25 cents to buy a Snickers, your current balance is 0 cents.

Let us try again, add a quarter and let us add another quarter and now we can say return my balance and it says okay I have returned your balance of 50 cents, your remaining balance is now 0 cents and once again if you were to ask for a product, give me a Twix, it says your balance must be at least 50 cents to buy a Twix, your current balance is 0 cents.

[01:02] You can see that not only is it responding with the fact that it is returned the balance, but you should also go to the appropriate state where it is got a 0 balance, which is basically the start state okay. This is going to be the third assignment and once again I will emphasize that you should be able to do all the three assignments just based on whatever we have learned till now and you should just, I will say it is tedious and it is a little bit involved, but it is definitely not very complicated and if you find that it is complicated then that means you have not really understood the concept of the state machine very well.

Once you understand what the state machine is and how it is supposed to work, implementing these three assignments should, it could take you some time, but it should not be too difficult to do.

Lesson: Assignment Hints

Assignment Hints

[00:00] So in this video, what I’m going to do is I’m going to give you a few hints to solve the assignments that I just provided. And I think that this is also a good way to see some of the features that we haven’t yet seen. And the first one would be this manage tab that you have over here. And let’s say, let’s take a look, I click on this. And you can see that there are a lot of intents over here. So we have already seen the welcome intent. And I don’t know if we explicitly saw the negative intent.

But you know that it’s similar to the fallback. And you can also see that these are the kind of intents that you should have in your agent as you are trying to build out all the intents for the assignment. Let’s just take a quick look at one of the things, which is what can I get. That was one of the things that we were trying to implement the first assignment. And you can see that the what can I get intent has only training phrases.

[01:03] And remember that the CX has this notion of separating out the training phrases from the responses, because it’s a state machine, as you know. So you only have the training phrases in the intents in CX, which means that what you see here is merely the words or the phrases that the user can say. But we don’t really know what the response is going to be, because that’s going to be based on the current state and what we want the bot to do.

And in fact, that’s the, you know, the big, I guess, the special feature of CX, because it allows us to reuse these intents. And now let’s say if I were to go and look at give me snickers, you just see that I have these three phrases, give me snickers, give me a snickers and give me a snickers bar. And you can have other training phrases too. You don’t have to limit yourself to just three. The idea is that you’re going to give all the variants that the user might use.

[02:01] You’re going to add that into the list of training phrases, right? So this is something like what you should have once you have completed your assignment. And the other thing that I want to show you is just take a look at what the intents might be inside of these different states, okay? So you have the start state, and you can see that there are all these intents.

What is my balance? Add a quarter. What can I get? Give me snickers. Give me tricks. Give me KitKat. Return my balance. All of them should be a part of that state. And you should, in fact, have the same set of intents in the State25 also. Add a quarter. What’s my balance? What can I get? And so on. And in fact, you should also have the same set of intents in State50 and 75. So this is why the CX is such a, I guess, a big improvement over Dialogflow ES because you just define these intents over here, and you are able to reuse.

[03:08] For example, you could have used give me KitKat in all the different states. You have the give me KitKat intent in state start. You have it in this State25, and you have it in State50, right? And you also have it in the State75.

And I didn’t have to retype out the training phrases again. I just used the training phrase. And I’ll just give you one more hint here. If you are in State75 and you ask for KitKat, once the agent has completed the response, which is, okay, here is a KitKat, your remaining balance is 0 cents, you have to remember to transition to the start state. Now, in contrast, let’s say that you were in State50, and you asked for KitKat.

[04:02] You will see that here the agent is supposed to say your balance must be at least 75 cents to buy a KitKat. And we know that it’s not 75 cents because we are in State50, right? And your current balance is only 50 cents. And also notice that it doesn’t do any state transition or page transition because it’s not done anything. It’s not going to change its state because all it did is refuse to provide the product to the user, which means that it’s as if it came back to the same state.

So it’s just something that you need to think about because not all the intents will have to trigger page transitions. It will only trigger a page transition where it makes sense because something happened to the total balance which is available. So that’s the set of hints. And if you still find that you are not able to build out the assignment, the bot as I specified in the assignments, the other thing you can do is you can take a look at my Dialogflow CX beta course.

[05:03] And I will tell you that it’s a paid course. So you have to pay to get this course, but the bots file that is the blob file that you can use for importing this agent will be available in this Dialogflow CX beta course so that you can just import it into your Dialogflow CX console. And maybe you can see what you might have missed.

Leave a Reply