MS Bot with Multiple Form Dialog

845 views Asked by At

I have 4 Dialogs in my Project the First one is a

RootDialog

with some enum. This is my root dialog so If user select the first option then I want to send him to the

CreateContact

Dialog which I added below and if user selcts

GetContact

or

SendMail

then I will send him to the appropriate Dialog but I am unable to call anothe form dialog on completion or selection of first Dialog.

 [Serializable]
        public enum RootOptions
        {
            CreateContact = 1, GetContact = 2, SendMail
        };

 [Serializable]
        public class RootForm
        {
            public RootOptions? Option;
            public static IForm<RootForm> BuildForm()
            {
                return new FormBuilder<RootForm>()
                        .Message("Welcome to TEST BOT!")
                        .OnCompletion(async (context, rootoption) =>
                        {
                            switch(rootoption.Option.Value.ToString()) "")
                            {
                                case "CreateContact":
                                //How to call Contact Dialog
                                break;
                                case "GetContact":
                                //Call Get Contact Dialog
                                break;
                                case "SendMail":
                                //Call Send Mail Dialog
                                break;
                            }
                        })
                        .Build();
            }
        }

Create Contact Dialog

[Serializable]
        public class ContactForm
        {
            [Prompt("What is the name? {||}")]
            public string Name;
            [Prompt("What is the Mobile No? {||}")]
            public string Mobile;
            [Prompt("What is the Email? {||}")]
            public string Email;
            public static IForm<ContactForm> BuildForm()
            {
                return new FormBuilder<ContactForm>()
                        .Message("Let's create a contact")
                        .OnCompletion(async (context, profileForm) =>
                        {
                        await context.PostAsync("Your contact has been created.");
                        })
                        .Build();
            }
        }

Send Mail Dialog

[Serializable]
        public class MailForm
        {
            [Prompt("What is the Email Id? {||}")]
            public string Email;
            [Prompt("What is the Subject? {||}")]
            public string subject;
            [Prompt("What is the Message? {||}")]
            public string Message;
            public static IForm<MailForm> BuildForm()
            {
                return new FormBuilder<MailForm>()
                        .Message("Let's Send a Mail")
                        .OnCompletion(async (context, mailForm) =>
                        {
                        await context.PostAsync("Mail Sent.");
                        })
                        .Build();
            }
        }
2

There are 2 answers

0
Ezequiel Jadib On BEST ANSWER

To call a dialog, you need to use context.Call as explained in this post. However, I'm not fully sure if this will work in the OnCompletion event of a Form.

If it doesn't work, my recommendation would be to encapsulate the RootForm into a IDialog<object> dialog and use that dialog as the starting point for the Conversation.SendAsync of the controller.

0
Upendra On

You can use below line of code to call multiple dialogs:

await Task.Run(() => context.Call(new OptionDialog(),
    this.OptionDialogResumeAfter)).ConfigureAwait(false);