Scott returns to Visual Studio and modifies the bot he built earlier by replacing a dialog-based conversation with one that utilizes FormFlow.
- [Instructor] We're back in VisualStudio, and we're going to take a look at replacing a standard dialog for bot conversations, with a FormFlow created dialog-guided experience. So, right now, we're calling this random fact dialog, from earlier in the session, instead we're going to create a dialog using FormFlow. First step to that, is just to create a class. So, under forms I've created this device-order class. And you'll notice this is just a standard C# class, the only caveat is we need to mark it serializable.
This is because this data is going to be serialized, and deserialized across channels and we need to make sure that as it's created, it's serializable. And then, by default we just have to have a method to build the form. Now I've got this method, build-form, that uses the form builder, and gives it a type of device order, and then we've got a message, and then we have an on-completion event, and then we just say "Build." And then for the first step in this demo, let's just comment that on-completion out, and take a look at that.
So we're just saying, return a new form builder of type device-order, show this message to the user when they start it, and then build the form. And build the form is going to take a look at this class object and intelligently build the steps of this process on its own. Now, we can override this, we can adjust this, we can get really complicated with this, we can do all sorts of things. But the cool thing is, for fairly plain, vanilla, guided experiences, like creating a sandwich or ordering a pizza, or ordering something from Starbucks, it just works essentially out-of-the-box.
Now for this example, we're going to have a guided experience to recommended device, for a user. So we're going to ask the user a couple of questions, like how old they are, what kind of apps they want, and then based on the device-type and other things like that, we're going to make a recommendation on what device and OS they ought to have. So, if we were to set this up, we could, for example, just create an enum, device-type and we could say phone, tablet, desktop, and then down in our form, we could have public device type, device-type.
And when we call this build form, it's going to take a look at the properties that are here, right now, we just have one property called device-type. And it's going to automatically build that form with whatever we've shown. Since we only have one property in this class, it's only going to ask one question. So, for fun, let's just take a look at that. We're going to have to call that, though, a little bit differently. We've got a little helper method that I've called make-device-order, and then instead of calling that we're going to call it this way, and pass this method, make-device-order.
So, you'll see what's happening is we're doing a send async, but instead of passing that iDialog reference, we're going to go to this method, and make the device order dialog. And you'll notice now, we're doing a chain from microsoft.bot.builder.formdialog, from form. So we're creating this form, and it's going to create a dialog from this form. And we're passing it the method, that build-form method. So it's just going to run this code, here.
Want to see how this looks, but in order to make this a little bit easier, let's just take out this authentication part of the process, so we can take a look at that. So, again, a request is going to come through, we're not really going to look at anything about the request, it's just going to send it right to this device-order dialog. So, let's run that.
Let's go over to our bot emulator. And let's just say "Hi," and see what happens. So there we go, it's already gone into our form, and said, "Welcome to the personality based device recommendation bot, please select a device type." So, this is really cool. Based on this enumeration that we had in the class, it's automatically showing the user, these options: phone, tablet, desktop.
If we make a selection, it's going to say, "Is this your selection?" 'Cause that's the end of the form, and I'll say, "Yes." And at this point in the process it doesn't do anything else. So let's see if we can spice that form up a little bit. So I've created a number of steps, actually all I had to do was just create the enumerations, and set the properties, and FormFlow handled creating the steps for me. So, here are the options that we have. And we're going to review some of these additional meta-data labels as well.
Drag those properties in, there we go. So, let's take a look at this. So, the first enumeration I've got, is now these app options. And I want to talk specifically about each one of these mark-ups that we're putting in here, these attributes. So, we're going to have an app options enumeration in here, now, if this is going to be a list of options, that we're going to show, if we're going to let a user select more than one, just as a note: this none will not be shown. So any enumeration that has zero, and gets shown in a list, will be skipped.
So, essentially when the user is asked about app options, they'll be shown lots of crummy apps, really trendy apps, free games, professional apps, or banking apps. And then I've added this, terms here, to kind of help the bot understand what lots of crummy apps might reference, or really these are kind of synonym terms. So if someone types in, "Crap apps," or "Crappy," it's going to evaluate back to, "Lots of crummy apps." And I could do this for all of these. I could give these, essentially synonyms, for all of these enumerations.
And then we've got device type, we've got intelligence level, I'm selecting as low-average or high, so we're going to ask the user how smart they are, and I've got an age range. So we're going to ask the user their age range. But we're essentially just going to ask them in a friendly way. So normally we would just have this age range: teenager, millennial, seasoned adult, and of course these are all just made up. But now we have the advantage of being able to say, put this label, describe teenager as, "I'm just a teenager." Or describe millennial as, "I'm young and trendy." Or describe seasoned adult as, "I've lived life and know things." And the reason that this is important, is that when these enumerations get shown to a user and a bot, maybe we don't want them to see the label, "Seasoned adult." Or, "Millennial." Or, "Teenager." Even though, the FormFlow process cleans up these labels for us.
So, by default, instead of showing, "bankingapps" without a space, it'll actually show, "Banking Apps," two words. So it's pretty smart about that, handling enumeration proper case. So we've got these enumerations now, that we've created, app options, device type, intelligence level, and age range. And now all we have to do is just add those to our device-order class. And this is really important, the order that we add them in the class, top to bottom, is the order that they'll be shown in the guided experience.
The very first thing a user is going to be asked for, is device type. After the device type, they're going to be asked for their level of intelligence, or their IQ. Then they're going to be asked their age range, and then they're going to be asked, what type of apps they want. But let's look at the attributes that I've added here. So, by default, we could have just had device-type. And it's going to ask a user what type of device they want.
It could also just say, intelligence level. And it would intelligently show this label as, "Intelligence Level," with a space. But we can add this prompt and say, "What's your IQ?" Or for age, "How old are you?" We can also add templates for how the bot framework will handle problems. For example, if the user enters a value that's not understood, we can say, "What does that mean?" The value that they passed.
We can also say, OK we're going to have a list of apps how do we want them shown? So the choice style is going to be auto, you can just figure out how to render it based on how many choices there are, we can say they're all going to be in-line, they're going to be in-line, no parenthesis, so they may have numbers, they may have parenthesis, all sorts of things there. We're just going to keep that as auto. And then when the form builds, it's just going to iterate through these, and create a step for each one of these properties.
I want you to notice that we have single selections, for device type, intelligence level, and age range, but I've got a list of app options for app options. This is automatically going to allow a multi-select. I could put a lot of things here, I could say, "public int SomeAgeMax" and the form would then ask for SomeAgeMax, and I might say 99.
So, there, I could evaluate things based on SomeAgeMax. And really, what it's going to do, is just build these based on our properties. We could also mark these as optional, if we want to, and then add them in later. So don't feel like you have to be forced, once you put them in, your class properties, don't feel like you're forced to show them at any time. We could put a lot of conditional logic in there.
- Recall the concept of a connector.
- Apply appropriate commands to create a dialog using FormFlow.
- Name the service that Cortana uses for language and semantic interpretations.
- Explain how a user can exchange messages with a bot.
- List three platforms where the services and features of Cortana are available.