Manikanta Reddy D Manikanta Reddy D - 2 months ago 20
C# Question

Calling Forms from Dialogs

I have a simple form,

class CreateNewLeadForm
public string FirstName;
public string LastName;
public static IForm<CreateNewLeadForm> BuildForm()

return new FormBuilder<CreateNewLeadForm>()
.Message("Lets create a New Lead")


And a simple Dialog,

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

public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<Message> argument)

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


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);