Messenger bot中出现PromptDialog错误

我的messenger机器人中有一个PromptDialog问题,每当它到达提示对话框时它会抛出“Bot Code有错误”。 我已经尝试在代码中移动它但它仍然抛出它无论我把它放在哪里,我已经尝试将它放入自己的方法并简单地调用方法并将上下文传递给它但是它再次没有帮助。

我认为它可能是LocationReceivedAsync中的东西但是我不确定是什么。

[LuisIntent("Stores")] public async Task Stores(IDialogContext context, LuisResult result) { await StoreSearch(context); } private async Task StoreSearch(IDialogContext context) { var reply = context.MakeMessage(); reply.ChannelData = new FacebookMessage ( text: "Please share your location with me.", quickReplies: new List { new FacebookQuickReply( contentType: FacebookQuickReply.ContentTypes.Location, title: default(string), payload: default(string) ) } ); await context.PostAsync(reply); context.Wait(LocationReceivedAsync); } public virtual async Task LocationReceivedAsync(IDialogContext context, IAwaitable argument) { var reply = context.MakeMessage(); reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; reply.Attachments = new List(); List images = new List(); InfoClass IC = new InfoClass(); var msg = await argument; var location = msg.Entities?.FirstOrDefault(e => e.Type == "Place"); if (location != null) { latitude = location.Properties["geo"]?["latitude"]?.ToString(); longitude = location.Properties["geo"]?["longitude"]?.ToString(); LocationObject[] StoreLocations = IC.NearBy(latitude, longitude, Radius, context); int count = StoreLocations.Length; for (int z = 0; z < count; z++) { CardImage Ci = new CardImage("https://maps.googleapis.com/maps/api/staticmap?size=764x400&center=" + StoreLocations[z].Latitude + "," + StoreLocations[z].Longitude + "&zoom=15&markers=" + StoreLocations[z].Latitude + "," + StoreLocations[z].Longitude); images.Add(Ci); HeroCard hc = new HeroCard() { Title = StoreLocations[z].StoreName, Subtitle = StoreLocations[z].Subtitle, Images = new List { images[z] }, Buttons = new List() }; CardAction ca = new CardAction() { Title = "Show Me", Type = "openUrl", Value = "https://www.google.co.za/maps/search/" + StoreLocations[z].Latitude + "," + StoreLocations[z].Longitude }; hc.Buttons.Add(ca); reply.Attachments.Add(hc.ToAttachment()); } await context.PostAsync(reply); PromptDialog.Confirm(context, promtDecision, "Would You Like To Change The Search Radius ?", attempts: 100); } context.Done(location); } async Task promtDecision(IDialogContext context, IAwaitable userInput) { bool inputText = await userInput; if (inputText) { RadiusPromt(context); } else { await mainMenu(context); } } 

您的LocationReceivedAsync实现中存在错误:当您获得位置时,不应将context.Done(location)放在方法的末尾。 它应该在另一个声明中。

这个context.Done正在尝试完成当前对话框,而您仍在尝试执行操作(在您的情况下要求半径更改)。

更正:

 private async Task LocationReceivedAsync(IDialogContext context, IAwaitable argument) { var reply = context.MakeMessage(); reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; reply.Attachments = new List(); List images = new List(); InfoClass IC = new InfoClass(); var msg = await argument; var location = msg.Entities?.FirstOrDefault(e => e.Type == "Place"); if (location != null) { latitude = location.Properties["geo"]?["latitude"]?.ToString(); longitude = location.Properties["geo"]?["longitude"]?.ToString(); LocationObject[] StoreLocations = IC.NearBy(latitude, longitude, Radius, context); int count = StoreLocations.Length; for (int z = 0; z < count; z++) { CardImage Ci = new CardImage("https://maps.googleapis.com/maps/api/staticmap?size=764x400&center=" + StoreLocations[z].Latitude + "," + StoreLocations[z].Longitude + "&zoom=15&markers=" + StoreLocations[z].Latitude + "," + StoreLocations[z].Longitude); images.Add(Ci); HeroCard hc = new HeroCard() { Title = StoreLocations[z].StoreName, Subtitle = StoreLocations[z].Subtitle, Images = new List { images[z] }, Buttons = new List() }; CardAction ca = new CardAction() { Title = "Show Me", Type = "openUrl", Value = "https://www.google.co.za/maps/search/" + StoreLocations[z].Latitude + "," + StoreLocations[z].Longitude }; hc.Buttons.Add(ca); reply.Attachments.Add(hc.ToAttachment()); } await context.PostAsync(reply); PromptDialog.Confirm(context, PromtDecision, "Would You Like To Change The Search Radius ?", attempts: 100); } // Change is here else { context.Done(location); } } 

编辑:关于您的实施还有一点。 我不明白为什么你的“搜索和结果显示”代码(在LocationObject[] StoreLocations = IC.NearBy(latitude, longitude, Radius, context); …)的回调来自Facebook提示( LocationReceivedAsync ),如果你想要在RadiusPrompt之后重用它(实现在这里不可见,但我想这是你想做的不是吗?)。

也许您应该在此方法中保持latitudelongitude设置,然后调用也可以从RadiusPrompt调用的新方法