从对话框调用表单

时间:2016-05-30 09:34:16

标签: c# botframework

我有一个简单的表格,

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

    }
};

一个简单的对话框,

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

如何从主Dialog本身调用Initiate a FormDialog?一般来说,我们如何在Dialog中开始新的对话框?

1 个答案:

答案 0 :(得分:7)

为了启动FormDialog,你可以这样做:

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

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

查看PizzaBot的示例。

要在对话框中启动新对话框,您可以执行以下操作:

  • context.Call传递新对话框的实例和完成回调(如表格中所示)
  • context.Forward,您可以消息转发到子对话框

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