我是编程facebook机器人的新手。我在c#中使用了microsoft bot框架。
当用户从快速回复中选择一个选项时,我想启动对话框或表单流。
当我尝试使用此代码时,我没有得到任何响应...或我得到错误
在我的Rootdialog.cs中使用此代码:
private async Task OnOptionSelected(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var message = await result;
//if you choose start parking
if (message.Text == Resources.RootDialog_Welcome_Start)
{
this.order = new Models.Order();
var promptOptions = new PromptOptions<string>(
"Please select the city where you want to park:",
options: new[] { "a", "b", "c" },
promptStyler: new ());
PromptDialog.Choice(context, this.ResumeAfterSelection, promptOptions);
}
private async Task ResumeAfterSelection(IDialogContext context, IAwaitable<string> result)
{
try
{
var cityRange = await result;
if (cityRange == "Brussels")
{
context.Call(FormDialog.FromForm<Enquiry>(Enquiry.BuildEnquiryForm, FormOptions.PromptInStart), async (ctx, formResult) => ctx.Wait(this.MessageReceivedAsync));
//var myform = new FormDialog<Enquiry>(new Enquiry(), Enquiry.BuildEnquiryForm, FormOptions.PromptInStart, null);
Enquiry.cs是
[Serializable]
public class Enquiry : LuisDialog<StartParking>
{
private Func<IForm<Enquiry>> buildEnquiryForm;
public Enquiry(Func<IForm<Enquiry>> buildEnquiryForm)
{
this.buildEnquiryForm = buildEnquiryForm;
}
public Enquiry()
{
}
[Prompt("What time")]
public DateTime Time { get; set; }
[Prompt("Placenumber?")]
public string PlaceNumber { get; set; }
[Prompt("Platenumber?")]
public string Platenumber { get; set; }
public IEnumerable<EntityRecommendation> Entities { get; internal set; }
public static IForm<Enquiry> BuildEnquiryForm()
{
return new FormBuilder<Enquiry>()
.AddRemainingFields()
.Build();
}
}
}
答案 0 :(得分:0)
我认为context.Call
需要IDialog
,因此请尝试使用Chain.From
从FormDialog.FromForm
构建一个:
internal static IDialog<Enquiry> MakeRoot()
{
return Chain.From(() => FormDialog.FromForm<Enquiry>(Enquiry.BuildEnquiryForm, FormOptions.PromptInStart));
}
然后使用:
调用它context.Call(MakeRoot, async (ctx, formResult) => ctx.Wait(this.MessageReceivedAsync));