Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling Forms from Dialogs

I have a simple form,

 [Serializable]
class CreateNewLeadForm
{
    public string FirstName;
    public string LastName;
    public static IForm<CreateNewLeadForm> BuildForm()
    {

        return new FormBuilder<CreateNewLeadForm>()
            .Message("Lets create a New Lead")
            .Field(nameof(FirstName))
            .Field(nameof(LastName))
            .Build();

    }
};

And a simple Dialog,

public class GreetDialog : IDialog<object>
{        
    public async Task StartAsync(IDialogContext context)
    {

        context.Wait(MessageReceivedAsync);
    }
    public   async Task MessageReceivedAsync(IDialogContext context, IAwaitable<Message> argument)
    {
       context.Wait(MessageReceivedAsync);
    }  
}  

How do I call a Initiate a FormDialog from the main Dialog itself? In general how do we intiate new dialogs within a Dialog?

like image 689
Manikanta Dornala Avatar asked May 30 '16 09:05

Manikanta Dornala


1 Answers

In order to initiate a FormDialog you can just do:

var myform = new FormDialog<CreateNewLeadForm>(new CreateNewLeadForm(), CreateNewLeadForm.BuildForm, FormOptions.PromptInStart, null);

context.Call<CreateNewLeadForm>(myform, FormCompleteCallback);

Take a look to the PizzaBot for an example.

To initiate new dialogs within a Dialog you can do:

  • context.Call passing the instance of the new dialog and the completion callback (as in the form)
  • context.Forward where you can forward the message to the child dialog

    context.Forward(new MyChildDialog(), ResumeAfterChildDialog, message, CancellationToken.None);

like image 117
Ezequiel Jadib Avatar answered Sep 30 '22 01:09

Ezequiel Jadib