botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

No Examples of Conditional Dialogs?

Open runxc1 opened this issue 10 years ago • 9 comments

So I have been reading over the examples (in C#) and I am not seeing any examples of how to conditionally decide which dialog to return. So as an example I have a bot that listens to all messages. If someone asks to tell a joke then I want to return the IFormDialog that lets them pick the type of joke. If on the other hand someone asks "What's the weather" I want to return an IFormDialog this has to be already baked in but I am not seeing it anywhere

runxc1 avatar Mar 31 '16 21:03 runxc1

The AlarmBot example binds to LUIS intents and then uses system dialogs depending on the intent that was selected--this sounds exactly like what you are looking for. If you grab the source code you can also see some examples of Conditional fields in a form in the FormTest project and also of two forms being hooked together.

chrimc62 avatar Mar 31 '16 22:03 chrimc62

I read over the LUIS but then you would have to create LUIS intents, I will look at the FormTest

runxc1 avatar Mar 31 '16 22:03 runxc1

You can do the same thing with a CommandDialog that uses regular expressions instead of LUIS.

chrimc62 avatar Mar 31 '16 22:03 chrimc62

Do you have an example of how to hook the CommandDialog up to the IFormDialog

runxc1 avatar Mar 31 '16 23:03 runxc1

If you look at the commit d2eb5b7, you can find a simple example of a bot that uses multiform dialogs.

msft-shahins avatar Apr 01 '16 01:04 msft-shahins

@runxc1 Both the CommandDialog & LuisDialog classes are best thought of as switch statements which as Chris & Shahin suggest sound like exactly what you want. CommandDialog is nice because its RegEx based but the LuisDialog is way more flexible from a matching perspective. You just have to bite the built and learn LUIS.

The normal pattern we envision for most bots is a switch at the root (either a CommandDialog or LuisDialog) and then various other dialog types hung off the switch. The switch determines the initial intent, "tell a joke" or "what's the weather?" and then redirects to the appropriate Joke or Weather dialog.

Stevenic avatar Apr 01 '16 09:04 Stevenic

Ok so what was throwing me off without examples was that all of the methods in the CommandDialog called for ResumeAfter and I hadn't seen that it was a delegate and not a generic class. So I finally wired something basic up and now get an error that the CommandDialog is not serializable

     internal static IDialog ContextSwitch()
        {

            var cd = new CommandDialog();
            cd.On(new Regex("Garmin Joke"),  (x,y)=> { return FormDialog.FromForm(GarminJoke.BuildForm).StartAsync(x); });

            return cd;
        }

        /// <summary>
        /// POST: api/Messages
        /// receive a message from a user and reply to it
        /// </summary>
        public async Task<Message> Post([FromBody]Message message)
        {
            if (message.Type == "Message")
            {
                return await Conversation.SendAsync(message, ContextSwitch);
            }
            else
            {
                return HandleSystemMessage(message);
            }
        }

The Nodejs documentation has more examples and shows how to use the CommandDialog but I am not seeing any examples on the CommandDialog. @Stevenic am I close or is it intended to be used much differently?

runxc1 avatar Apr 01 '16 15:04 runxc1

On a side note a lot of the dotnet teams (cli,roslyn,corefx) have created a https://gitter.im/ chat room associated with the Github repo and put a link on the information page for the repo... That could be of use here

runxc1 avatar Apr 01 '16 15:04 runxc1

Thanks for the suggestion on gitter. I've setup a BotBuilder room there. We will also work up some examples of CommandDialog.

chrimc62 avatar Apr 03 '16 00:04 chrimc62