WEBVTT
00:00:01.990 --> 00:00:04.322
Welcome to Microsoft Build 2017.
00:00:04.322 --> 00:00:08.418
My name is Christopher Harrison,
and today I'm going to talk
00:00:08.418 --> 00:00:12.533
about Dialogue Management in
Bot Framework, using Node JS.
00:00:12.533 --> 00:00:16.109
Just as a real quick little
bit of background, I'm an SDE
00:00:16.109 --> 00:00:19.984
here inside of Microsoft and
you'll also notice that you've
00:00:19.984 --> 00:00:23.281
got my Twitter handle there
if you feel so inclined.
00:00:23.281 --> 00:00:27.364
Now, let's talk a little bit
about building bots that
00:00:27.364 --> 00:00:30.395
are going to be able
to work with humans.
00:00:30.395 --> 00:00:32.508
There's some basic facts
that we need to understand.
00:00:32.508 --> 00:00:36.980
For starters,
humans are complex.
00:00:36.980 --> 00:00:40.191
We can't simply take
human interaction and
00:00:40.191 --> 00:00:44.015
distill that down into
a handful of function cause.
00:00:44.015 --> 00:00:45.382
It's just not gonna work.
00:00:45.382 --> 00:00:50.161
Humans are random, we can get
distracted by different things,
00:00:50.161 --> 00:00:52.090
our minds can change.
00:00:52.090 --> 00:00:56.218
Something else in our
environment may be different,
00:00:56.218 --> 00:01:00.805
might change and that might
cause me to do something that's
00:01:00.805 --> 00:01:02.835
completely unexpected.
00:01:02.835 --> 00:01:04.426
And finally, and
00:01:04.426 --> 00:01:10.055
I think we can all agree on this
is that humans can be illogical.
00:01:10.055 --> 00:01:14.811
On top of that, humans are very
rarely going to provide all
00:01:14.811 --> 00:01:19.190
of the information that's
required right upfront.
00:01:19.190 --> 00:01:23.021
Imagine if you will, that I was
gonna create a bot for Build or
00:01:23.021 --> 00:01:25.250
some other conference.
00:01:25.250 --> 00:01:27.450
And one of the things that
somebody might want to be able
00:01:27.450 --> 00:01:31.620
to do through the bot is
register for a hotel room.
00:01:31.620 --> 00:01:34.270
And needless to say, there's
a few pieces of information that
00:01:34.270 --> 00:01:35.173
need to be provided.
00:01:35.173 --> 00:01:36.139
So in theory,
00:01:36.139 --> 00:01:40.710
I can setup a bot where a user
can type in something like this.
00:01:40.710 --> 00:01:43.420
I'd like to book a room for
Bot Conference.
00:01:43.420 --> 00:01:45.995
I need a single occupancy
king-sized room,
00:01:45.995 --> 00:01:48.919
checking in on Tuesday and
checking out on Friday.
00:01:48.919 --> 00:01:52.340
And of course, my bot responds
back with, sure thing.
00:01:54.571 --> 00:01:56.109
There's only one
problem with this.
00:01:57.230 --> 00:02:01.980
That is literally
never going to happen.
00:02:01.980 --> 00:02:06.226
Nobody comes in with
everything right up front.
00:02:06.226 --> 00:02:08.373
Now what's gonna happen is
somebody's gonna send in
00:02:08.373 --> 00:02:10.690
a message saying I'd
like to book a room.
00:02:10.690 --> 00:02:14.884
And now, my bot is gonna have to
start to figure out okay, well,
00:02:14.884 --> 00:02:16.214
what type of a room?
00:02:16.214 --> 00:02:18.010
What dates are they looking for?
00:02:18.010 --> 00:02:21.230
So it's gonna need some
level of back and forth.
00:02:21.230 --> 00:02:24.601
On top of that, the human
might provide some partial
00:02:24.601 --> 00:02:28.583
information, so that maybe that
they send a message saying,
00:02:28.583 --> 00:02:30.820
I'd like to book
a king size room.
00:02:30.820 --> 00:02:33.992
Okay cool,
we know that we've got that, but
00:02:33.992 --> 00:02:37.421
we still need the check in and
the check out date.
00:02:37.421 --> 00:02:40.509
So there's going to be a little
bit of back and forth,
00:02:40.509 --> 00:02:43.392
a little bit of dialoguing
that's going to need to
00:02:43.392 --> 00:02:46.070
go on to collect the rest
of the information and
00:02:46.070 --> 00:02:48.490
perform the action on
behalf of the user.
00:02:49.540 --> 00:02:52.742
In addition, it's also very
possible, that I would set up
00:02:52.742 --> 00:02:55.380
a bot and an interaction
like this could happen.
00:02:55.380 --> 00:02:59.855
So let's say that we got
a possibility to reserve lunch
00:02:59.855 --> 00:03:01.160
tables.
00:03:01.160 --> 00:03:03.652
So somebody sends a message
to the bot and says,
00:03:03.652 --> 00:03:06.470
I'd like to make a lunch
reservation for two people.
00:03:06.470 --> 00:03:09.620
So the bot comes back and says,
absolutely, I have 11:30 and
00:03:09.620 --> 00:03:11.030
12:30 available.
00:03:11.030 --> 00:03:11.612
What time slot do you want?
00:03:11.612 --> 00:03:15.900
And then my user sends back
do you have a vegan menu?
00:03:17.090 --> 00:03:21.135
Because maybe he just remembered
that the person that he's gonna
00:03:21.135 --> 00:03:23.267
be doing lunch with is a vegan,
and
00:03:23.267 --> 00:03:26.576
wants to make sure that they're
going to be able to eat
00:03:26.576 --> 00:03:29.313
something other than
just a sliced tomato.
00:03:29.313 --> 00:03:34.395
So again, that's perfectly
logical from the human's
00:03:34.395 --> 00:03:39.812
perspective, but that's not
overly logical for the bot.
00:03:39.812 --> 00:03:43.836
So once again, we need to be
able to manage how the bot
00:03:43.836 --> 00:03:49.080
interacts with the user and how
the bot responds to the user.
00:03:49.080 --> 00:03:52.761
And this is done through
what are known as Dialogs.
00:03:52.761 --> 00:03:57.337
Dialogs are reusable modules,
you can think of them as
00:03:57.337 --> 00:04:01.225
a module, you can think
of them as a function.
00:04:01.225 --> 00:04:05.842
That in a perfectly designed
system, where typically,
00:04:05.842 --> 00:04:10.746
your dialogs would be there to
perform a single operation and
00:04:10.746 --> 00:04:14.700
would be called
from other dialogs.
00:04:14.700 --> 00:04:18.686
And one other really cool
thing that we'll see a little
00:04:18.686 --> 00:04:21.903
bit later is that our
dialogs can be global.
00:04:21.903 --> 00:04:25.141
Now, there's really actually
two main types of dialogs
00:04:25.141 --> 00:04:25.820
with a bot.
00:04:25.820 --> 00:04:28.901
The first type is a root dialog,
and
00:04:28.901 --> 00:04:33.350
there's only ever one
root dialog on a bot.
00:04:33.350 --> 00:04:37.779
And this is gonna be called when
there is no other dialog on
00:04:37.779 --> 00:04:42.409
the stack, meaning that we
have no ongoing conversation.
00:04:42.409 --> 00:04:44.853
And when the message
was sent in,
00:04:44.853 --> 00:04:49.046
the bot looked at the message
and couldn't figure out any
00:04:49.046 --> 00:04:52.640
other dialogue that could
handle that message.
00:04:53.690 --> 00:04:56.268
You'll also notice that
the dialog is going
00:04:56.268 --> 00:04:59.340
to be registered inside of
the constructor in code.
00:04:59.340 --> 00:05:04.047
Now the other type of dialog
that we can set up is
00:05:04.047 --> 00:05:07.323
a globally registered dialog.
00:05:07.323 --> 00:05:11.776
And we'll do this by utilizing
a cool little function called
00:05:11.776 --> 00:05:13.120
triggerAction.
00:05:13.120 --> 00:05:17.561
Now, what's cool is that this is
always going to be executed when
00:05:17.561 --> 00:05:20.320
the recognizer matches
the utterance.
00:05:20.320 --> 00:05:23.846
And that recognizer
could be using LUIS or
00:05:23.846 --> 00:05:28.680
it could be using your
own custom recognizer.
00:05:28.680 --> 00:05:32.260
And so this is great for
conversation support.
00:05:32.260 --> 00:05:34.591
So let's say that the user
types in help, or
00:05:34.591 --> 00:05:36.923
let's say that the user
type's in cancel.
00:05:36.923 --> 00:05:41.841
I can setup a one global dialog
that can then handle that,
00:05:41.841 --> 00:05:44.230
or how about tangents?
00:05:44.230 --> 00:05:46.760
Going back to our
previous example,
00:05:46.760 --> 00:05:50.186
we have the human send
them a little message, hi,
00:05:50.186 --> 00:05:54.120
I'd like to make a reservation
for lunch for two people.
00:05:54.120 --> 00:05:56.907
And the bot comes back and
says sure, I've got 11:30 and
00:05:56.907 --> 00:05:59.265
12:30, and the human
comes back and says hey,
00:05:59.265 --> 00:06:00.400
do you have a vegan menu?
00:06:00.400 --> 00:06:05.189
It would be nice to be
able to handle that ,and
00:06:05.189 --> 00:06:09.107
then pick up right
where we left off.
00:06:09.107 --> 00:06:13.256
And so fortunately we can do
that with dialog management,
00:06:13.256 --> 00:06:14.610
inside of node JS,
00:06:14.610 --> 00:06:19.050
with this cool little thing
called triggerAction.
00:06:19.050 --> 00:06:23.220
Let's see how
triggerAction might work.
00:06:23.220 --> 00:06:28.810
So over here,
I've got the starters for a bot.
00:06:28.810 --> 00:06:32.368
Now, I've set this up by
utilizing a little Yeoman
00:06:32.368 --> 00:06:34.286
generator that I created.
00:06:34.286 --> 00:06:39.026
And it's just got a single
dialog registered as
00:06:39.026 --> 00:06:41.220
the root dialog.
00:06:41.220 --> 00:06:43.110
And you'll notice that it's
really just an echo bot.
00:06:43.110 --> 00:06:47.593
So, it's just going to send
a little thing saying hi,
00:06:47.593 --> 00:06:51.290
I'm and
then the build dialogues bot.
00:06:51.290 --> 00:06:54.194
And then it will come back and
say, in a nutshell,
00:06:54.194 --> 00:06:55.518
here's what I can do.
00:06:55.518 --> 00:07:00.226
Ask me for my name, and
then we'll respond back with
00:07:00.226 --> 00:07:04.410
whatever the user's
name happens to be.
00:07:04.410 --> 00:07:07.809
So they're a very basic
straightforward little bot here.
00:07:07.809 --> 00:07:13.510
Let's go ahead and add in,
maybe, a help dialog.
00:07:13.510 --> 00:07:17.145
So we could give the user
the opportunity to ask for help.
00:07:17.145 --> 00:07:21.855
And so the way that we can do
this is by saying, bot.dialog
00:07:21.855 --> 00:07:27.280
and then giving this a name,
and we'll call this help.
00:07:27.280 --> 00:07:31.843
And then specifying what we want
the rest of the dialog to look
00:07:31.843 --> 00:07:32.383
like.
00:07:32.383 --> 00:07:36.380
And so in my case I'm gonna
keep it nice and simple.
00:07:36.380 --> 00:07:40.218
And I'm just simply gonna say,
00:07:40.218 --> 00:07:45.195
session.endDialog('This is
a simple
00:07:45.195 --> 00:07:49.895
demo bot for
a sample conference').
00:07:49.895 --> 00:07:54.040
Or whatever else it is that
you might want that to do.
00:07:54.040 --> 00:07:58.954
Now, if I wanna make sure that
this will always respond to some
00:07:58.954 --> 00:08:01.979
particular utterance
from the user,
00:08:01.979 --> 00:08:05.110
I can do that by
saying triggerAction.
00:08:05.110 --> 00:08:07.576
And with triggerAction,
00:08:07.576 --> 00:08:12.065
I can tell it what it is
that I want it to match on.
00:08:12.065 --> 00:08:13.877
So I can say matches,
00:08:13.877 --> 00:08:17.604
and then if I was using
a custom recognizer or
00:08:17.604 --> 00:08:21.936
a LOUIS recognizer,
I could then just simply put in
00:08:21.936 --> 00:08:27.660
whatever the name of the intent
happened to be right here.
00:08:27.660 --> 00:08:31.135
Or if I want to look at
the text of the message,
00:08:31.135 --> 00:08:34.525
I can then just put in
a regular expression.
00:08:34.525 --> 00:08:38.910
So I can just simply say
something like this, so, help.
00:08:40.010 --> 00:08:41.649
And I can even,
of course, go in and
00:08:41.649 --> 00:08:44.126
anchor that to the beginning and
the end and so forth.
00:08:44.126 --> 00:08:47.390
And you start to see where
all of this is going.
00:08:47.390 --> 00:08:50.660
So now if I go in and
I run my bot, so
00:08:50.660 --> 00:08:52.110
let's just use nodemon here.
00:08:55.449 --> 00:08:59.230
Cool, and then I start
interacting with my bot and
00:08:59.230 --> 00:09:01.220
let's say I say hi there.
00:09:03.750 --> 00:09:05.710
And it will ask me for my name,
and I say Christopher.
00:09:05.710 --> 00:09:08.042
And it comes back and
says Welcome, Christopher.
00:09:08.042 --> 00:09:13.810
So, you'll notice that was our
default dialog or root dialog.
00:09:13.810 --> 00:09:15.781
And if I go in and say help,
00:09:15.781 --> 00:09:18.833
you'll notice that it
will come back and
00:09:18.833 --> 00:09:23.259
will say this is a simple demo
bot for a sample conference.
00:09:23.259 --> 00:09:27.663
Now here's a very
important thing to note,
00:09:27.663 --> 00:09:30.113
about triggerAction.
00:09:30.113 --> 00:09:35.181
TriggerAction is always
going to replace any
00:09:35.181 --> 00:09:40.523
dialogs that happen to
be working with the bot.
00:09:40.523 --> 00:09:44.954
Or in other words, it's going
to replace the dialog stack.
00:09:44.954 --> 00:09:47.486
Now, for those of you that
are not familiar with
00:09:47.486 --> 00:09:50.588
the Dialog Stack, the Dialog
Stack is simply the series of
00:09:50.588 --> 00:09:53.018
dialogs that your bot
currently has active.
00:09:53.018 --> 00:09:55.792
And as one completes, that
gets popped off the stack, and
00:09:55.792 --> 00:09:57.610
then potentially
a new one pushed on.
00:09:57.610 --> 00:10:02.060
Or it just simply goes back to
whatever happens to be left
00:10:02.060 --> 00:10:06.806
on the stack Trigger action
will always replace the stack.
00:10:06.806 --> 00:10:08.950
What does that mean?
00:10:08.950 --> 00:10:10.820
Well, it means
behavior like this.
00:10:11.820 --> 00:10:14.160
Let me clear out
the screen here.
00:10:14.160 --> 00:10:18.323
And let me send in
my little hello.
00:10:18.323 --> 00:10:20.220
And then it comes back and
says, hi there,
00:10:20.220 --> 00:10:22.080
I'm the Build Dialogs Bot
in a nutshell.
00:10:22.080 --> 00:10:23.210
Here's what I can do.
00:10:23.210 --> 00:10:24.239
What's your name?
00:10:24.239 --> 00:10:27.628
Now if you remember previously,
when I said Christopher,
00:10:27.628 --> 00:10:31.250
it came back and
it said hello, Christopher.
00:10:31.250 --> 00:10:34.444
Well, now you'll notice
that if I say help,
00:10:34.444 --> 00:10:37.468
it's gonna come back and
it's gonna say,
00:10:37.468 --> 00:10:41.014
this is a simple demo bot for
a sample conference.
00:10:42.924 --> 00:10:45.710
And it's not asking me for
my name anymore.
00:10:45.710 --> 00:10:47.920
So whatever it was that it
was doing a minute ago,
00:10:47.920 --> 00:10:51.540
in this case collecting my name,
it's now not doing that.
00:10:51.540 --> 00:10:55.150
Because the entire .log
stack has now been replaced
00:10:55.150 --> 00:10:58.160
by this help dialog.
00:10:58.160 --> 00:11:00.744
It's not really a good
experience for the user.
00:11:00.744 --> 00:11:03.076
Think about it,
that if I ask for help,
00:11:03.076 --> 00:11:06.187
I probably want to get a little
bit of information and
00:11:06.187 --> 00:11:09.120
then be able to pick
up where I left off.
00:11:09.120 --> 00:11:12.214
Or again, going back to the
original scenario that we had
00:11:12.214 --> 00:11:15.703
introduced that I go in and say
hey, I wanna make a reservation.
00:11:15.703 --> 00:11:18.380
It says sure, what time?
00:11:18.380 --> 00:11:20.510
And then I say do you
have a vegan menu?
00:11:20.510 --> 00:11:23.050
It would be really nice if it
would give me the information
00:11:23.050 --> 00:11:26.110
about whether or not there's
a vegan menu, and then allow me
00:11:26.110 --> 00:11:29.650
to pick up from where I left off
with the reservation process.
00:11:29.650 --> 00:11:33.200
So just re-prompt me, re-ask me.
00:11:33.200 --> 00:11:37.040
Fortunately, I can modify the
way that trigger action works.
00:11:38.080 --> 00:11:40.710
So you'll notice that I've
got my little matches here.
00:11:40.710 --> 00:11:44.110
And I'm just gonna update
my formatting here.
00:11:44.110 --> 00:11:47.465
This is really the way
that I like to have it.
00:11:47.465 --> 00:11:48.710
There we go.
00:11:48.710 --> 00:11:51.538
I'm particular about
formatting of my code.
00:11:51.538 --> 00:11:57.740
And so now what I'm gonna do is
I'm gonna say onSelectAction.
00:11:57.740 --> 00:12:04.990
Now onSelectAction is an event
handler that's going to execute
00:12:04.990 --> 00:12:10.680
when it's about to run
this particular dialog.
00:12:10.680 --> 00:12:13.610
And so
it gives me the opportunity to
00:12:13.610 --> 00:12:17.600
maybe write some information out
that I need to store for later.
00:12:17.600 --> 00:12:19.690
Maybe do some
potential clean-up.
00:12:19.690 --> 00:12:24.030
Or in my case,
to change that default behavior.
00:12:24.030 --> 00:12:28.300
So what I'm gonna do is set
this up with a function
00:12:29.880 --> 00:12:33.760
that's going to have two
parameters, the session, and
00:12:33.760 --> 00:12:37.420
then args, which is the args
that are passed into here.
00:12:37.420 --> 00:12:42.654
And so now what I can do is I
can say session.beginDialog.
00:12:42.654 --> 00:12:46.650
And then, args.action, which
will give me the information
00:12:46.650 --> 00:12:49.140
about the action that it's
just about to launch.
00:12:49.140 --> 00:12:51.160
And then simply say args,
00:12:51.160 --> 00:12:54.414
which would then get
passed into the dialog.
00:12:54.414 --> 00:12:57.230
The upshot of using
this beginDialog
00:12:57.230 --> 00:13:01.710
is that now when I go back and
I start this over again,
00:13:01.710 --> 00:13:05.860
let's say, hello,
and now I say, help.
00:13:05.860 --> 00:13:08.860
Now what you're gonna notice is
that it will come back and say,
00:13:08.860 --> 00:13:10.330
this is a simple bot demo.
00:13:10.330 --> 00:13:13.430
There's our help message,
and then you're gonna notice
00:13:13.430 --> 00:13:16.470
that it will come back with
that what's your name?
00:13:16.470 --> 00:13:18.500
So it picked up
where it left off.
00:13:18.500 --> 00:13:22.070
And so now I could go in and
say, Christopher, hit Enter and
00:13:22.070 --> 00:13:24.570
then it will come back and
say Welcome, Christopher.
00:13:24.570 --> 00:13:29.480
So it completed what it
had started previously.
00:13:29.480 --> 00:13:33.545
Now the reason that it did that
is because I used beginDialog.
00:13:34.600 --> 00:13:38.317
There's actually two different
functions that you can
00:13:38.317 --> 00:13:40.457
use to start a brand new dialog.
00:13:40.457 --> 00:13:42.412
One of them is beginDialog,
00:13:42.412 --> 00:13:45.431
which will push a new
dialog onto the stack.
00:13:45.431 --> 00:13:48.944
And then the next one is
replaceDialog, which will take
00:13:48.944 --> 00:13:53.055
your current dialog, move that
off to the side that's now gone,
00:13:53.055 --> 00:13:56.700
and then put the new
dialog into its place.
00:13:56.700 --> 00:14:00.940
The main key difference here
is that if I call beginDialog,
00:14:00.940 --> 00:14:02.610
when that new dialog completes,
00:14:02.610 --> 00:14:07.440
it's going to come back to the
one that was running previously.
00:14:09.290 --> 00:14:14.070
And if we go in and
we take a look at a slide
00:14:14.070 --> 00:14:17.020
to kinda walk through what
a dialog stack might look like,
00:14:17.020 --> 00:14:20.150
I might have a dialog
that's called register.
00:14:20.150 --> 00:14:21.100
Now register, of course,
00:14:21.100 --> 00:14:24.030
is going to be a whole
series of various steps.
00:14:24.030 --> 00:14:26.700
And rather than build all
of that into that one
00:14:26.700 --> 00:14:30.560
single register dialog,
I might break that apart.
00:14:30.560 --> 00:14:34.430
So maybe I've got another
dialog called GetAttendeeInfo.
00:14:34.430 --> 00:14:37.870
And so, I can launch that
by calling beginDialog.
00:14:37.870 --> 00:14:39.790
And then maybe get attendee info
00:14:39.790 --> 00:14:41.930
is going to walk through
all the different pieces of
00:14:41.930 --> 00:14:44.240
information that we need
about the attend date.
00:14:44.240 --> 00:14:46.880
So maybe one of those pieces
of information that we need
00:14:46.880 --> 00:14:49.310
is GetDietaryRestrictions.
00:14:49.310 --> 00:14:52.924
And if we use beginDialog,
what's gonna wind up happening
00:14:52.924 --> 00:14:55.886
each time is that a new
dialog is gonna get put on,
00:14:55.886 --> 00:14:58.000
a new dialog is
going to get put on.
00:14:59.580 --> 00:15:03.770
Now once that dialog completes,
it's then going to reverse and
00:15:03.770 --> 00:15:05.930
work its way back
down the stack.
00:15:05.930 --> 00:15:09.340
So when GetDietaryRestrictions
finishes,
00:15:09.340 --> 00:15:14.330
it can then send information
back to the previous dialog.
00:15:14.330 --> 00:15:17.400
So in this case, maybe it
sent back the information
00:15:17.400 --> 00:15:20.330
that the attendee is vegan.
00:15:21.800 --> 00:15:24.630
And then when that finishes, it
can then send information down
00:15:24.630 --> 00:15:28.100
to register, and then register
can act upon that information,
00:15:28.100 --> 00:15:33.010
and then determine what
the appropriate next steps are.
00:15:33.010 --> 00:15:37.850
And the great power to this is
it can make it much easier for
00:15:37.850 --> 00:15:40.530
you to structure your bot.
00:15:40.530 --> 00:15:44.920
And to allow your bot to be able
to respond to all of the various
00:15:44.920 --> 00:15:48.940
random messages that a user
might be sending to it.
00:15:48.940 --> 00:15:54.113
So having nice, tight,
small single purpose dialogs
00:15:54.113 --> 00:15:59.740
is going to make it that much
easier to work with your bot.
00:15:59.740 --> 00:16:02.810
It's going to make those
things more reusable.
00:16:02.810 --> 00:16:07.350
And it's going to give your
users a better experience.
00:16:08.690 --> 00:16:13.240
Let's go in and see how we might
do this inside of our bot.
00:16:15.140 --> 00:16:20.600
So maybe I go in and
I set up a brand new
00:16:21.880 --> 00:16:25.440
little dialog here, and
let's call this register.
00:16:26.590 --> 00:16:31.340
Now for simplicity's sake,
I'm just gonna set this up
00:16:31.340 --> 00:16:35.648
with a regular expression,
rather than using a recognizer.
00:16:35.648 --> 00:16:39.462
I again wanna highlight
the fact that if you were using
00:16:39.462 --> 00:16:42.769
a recognizer,
just simply string literal and
00:16:42.769 --> 00:16:45.247
then put in the name
of the intent.
00:16:45.247 --> 00:16:47.880
And let's set up
one other one here.
00:16:47.880 --> 00:16:52.030
And we'll say
dialog-waterfall and
00:16:52.030 --> 00:16:57.349
then maybe this is going
to be getAttendeeInfo.
00:16:57.349 --> 00:17:01.800
Cool, and l'm actually gonna get
rid of the trigger action that's
00:17:01.800 --> 00:17:05.392
there because l wanna make
sure that this is just called
00:17:05.392 --> 00:17:06.815
programmatically.
00:17:07.860 --> 00:17:11.406
Now inside of getAttendeeInfo,
00:17:11.406 --> 00:17:16.351
I'm going to prompt the user for
a bit of text.
00:17:16.351 --> 00:17:19.497
We'll kinda keep this nice and
simple.
00:17:19.497 --> 00:17:25.380
And we'll simply ask, do you
have any dietary restrictions?
00:17:26.950 --> 00:17:31.945
And then that information is
gonna come back inside of
00:17:31.945 --> 00:17:35.830
my results.response
just like normal.
00:17:38.160 --> 00:17:43.210
There we go, and so now I can
pass this back to the original
00:17:43.210 --> 00:17:49.800
dialog by calling in my case
sesson.endDialogWithResult.
00:17:49.800 --> 00:17:51.771
So as opposed to endDialog,
00:17:51.771 --> 00:17:55.799
which will just simply
endDialog, endDialogWithResult
00:17:55.799 --> 00:17:59.588
will pass the information
back to the calling dialog.
00:17:59.588 --> 00:18:05.142
And if I just simply use a very
common pattern where I say,
00:18:05.142 --> 00:18:11.276
just like before, response and
then pass in the dietary, now I
00:18:11.276 --> 00:18:17.670
can use that exact same pattern
up above inside register.
00:18:17.670 --> 00:18:19.950
So now, let's go ahead and
call that.
00:18:19.950 --> 00:18:24.814
So we'll say session, and
we'll say beginDialog, and
00:18:24.814 --> 00:18:29.997
the name of the dialog is
getAttendeeInfo, just like that.
00:18:29.997 --> 00:18:35.119
So this is going to pass control
00:18:35.119 --> 00:18:43.788
to getAttendeeInfo when
the new dialog completes,
00:18:43.788 --> 00:18:48.130
returns control to here.
00:18:49.370 --> 00:18:52.880
And it really is just as if I
was calling an external prompt.
00:18:52.880 --> 00:18:55.730
Because now the information
is going to come back and
00:18:55.730 --> 00:18:58.880
that result is what's
going to get passed in.
00:18:58.880 --> 00:19:00.680
So this right here.
00:19:00.680 --> 00:19:03.492
That little response, and
then whatever the dietary
00:19:03.492 --> 00:19:06.800
restrictions were, comes
back inside of that result.
00:19:06.800 --> 00:19:09.830
So now I can do whatever
it is that I want with it.
00:19:09.830 --> 00:19:10.430
We'll keep it simple.
00:19:10.430 --> 00:19:15.673
We'll just make it a little
eco bot and we'll simply say,
00:19:15.673 --> 00:19:21.559
session.endConversation, which
will get rid of everything,
00:19:21.559 --> 00:19:25.955
and say, You said and
then results.response.
00:19:29.198 --> 00:19:30.940
Just like that.
00:19:30.940 --> 00:19:33.800
So now let's watch
this in action here.
00:19:33.800 --> 00:19:34.670
So let's save that.
00:19:35.700 --> 00:19:37.560
Let's come back over here,
let's clear all this out.
00:19:39.420 --> 00:19:41.740
And now let's go in and
say register.
00:19:41.740 --> 00:19:44.370
And you'll notice that it
will come back to me and say,
00:19:44.370 --> 00:19:46.980
Do you have any
dietary restrictions?
00:19:46.980 --> 00:19:50.908
And then I could go in and
say none, hit Enter.
00:19:50.908 --> 00:19:55.440
And then it will come back to
me and say, You said none.
00:19:55.440 --> 00:19:58.844
Cool, and if you really
wanna see what's going on
00:19:58.844 --> 00:20:02.086
behind the scenes,
maybe what we could do right
00:20:02.086 --> 00:20:05.183
here is let's just
print out console.log.
00:20:05.183 --> 00:20:08.623
And let's say session and
00:20:08.623 --> 00:20:13.790
my dialogStack just so
we can see that.
00:20:15.820 --> 00:20:22.990
Let's just come back over here,
register, none, cool.
00:20:22.990 --> 00:20:25.168
And now let's go back over here,
and
00:20:25.168 --> 00:20:28.400
now what you'll notice is
just as I mentioned before,
00:20:28.400 --> 00:20:31.159
that it is going to have
pushed that new one on.
00:20:31.159 --> 00:20:34.057
So we started at register and
then we went ahead and
00:20:34.057 --> 00:20:37.232
we called beginDialog for
that getAttendeeInfo, and
00:20:37.232 --> 00:20:40.100
you can see that
behind the scenes.
00:20:40.100 --> 00:20:43.880
Now one other thing that's very
interesting here is if you take
00:20:43.880 --> 00:20:47.210
a look at behind the scenes,
we can also see the state.
00:20:47.210 --> 00:20:49.770
So we can see what's
about to happen,
00:20:49.770 --> 00:20:51.770
where it happens to be, etc.
00:20:51.770 --> 00:20:57.932
So in our case, when we set up
our call to getAttendeeInfo,
00:20:57.932 --> 00:21:04.060
we did that from the first
step in the register dialog.
00:21:04.060 --> 00:21:05.710
And then when we printed
out the information,
00:21:05.710 --> 00:21:08.050
we actually happened to
be in the second step,
00:21:08.050 --> 00:21:10.030
we were right here.
00:21:10.030 --> 00:21:13.780
So we were in the second step
of that waterfall dialog.
00:21:13.780 --> 00:21:18.690
So that dialog stack
can give you a lot of
00:21:18.690 --> 00:21:23.720
great information about what's
going on inside of your bot.
00:21:23.720 --> 00:21:25.266
It's also worth
highlighting here,
00:21:25.266 --> 00:21:26.963
and this gets a little
bit more advanced.
00:21:26.963 --> 00:21:31.364
But it is worth highlighting the
fact that you can use that to
00:21:31.364 --> 00:21:35.502
not only just manipulate
the dialogs that are currently
00:21:35.502 --> 00:21:40.079
on the stack, but also to see
what information is being stored
00:21:40.079 --> 00:21:42.850
inside of each one
of those dialogs.
00:21:42.850 --> 00:21:44.240
And potentially,
00:21:44.240 --> 00:21:49.410
dynamically figure out where
the user needs to be next.
00:21:49.410 --> 00:21:53.125
So the long and short of all
of this is the fact that bot
00:21:53.125 --> 00:21:57.360
framework gives you a lot of
power in controlling dialogs.
00:21:57.360 --> 00:22:02.191
And in responding to all the
various requests that might come
00:22:02.191 --> 00:22:04.240
in from your users.
00:22:04.240 --> 00:22:07.570
Even the ones that you
weren't necessarily expecting
00:22:07.570 --> 00:22:10.940
in the path that
you were heading.
00:22:10.940 --> 00:22:13.520
Now if you're curious about
where to go from here,
00:22:13.520 --> 00:22:17.250
there's an MBA course, where we
spend more time going in and
00:22:17.250 --> 00:22:18.950
building bots.
00:22:18.950 --> 00:22:21.830
I actually have a blog
post where I have a lot of
00:22:21.830 --> 00:22:27.950
information about how to go in
and manage all of your dialogs.
00:22:27.950 --> 00:22:29.110
And then finally, last but
00:22:29.110 --> 00:22:33.370
not least is the sample
code that I did up here.
00:22:33.370 --> 00:22:35.630
So you can go check
all of that out.
00:22:35.630 --> 00:22:37.340
Thanks again for tuning in and
00:22:37.340 --> 00:22:40.390
I hope you enjoy the rest
of your Build 2017.