我目前正忙着搜索用户周围区域的机器人。用户可以增加搜索半径。这是我用来处理用户输入的代码,到目前为止,"是"代码的一部分工作,但我不知道如何重新触发搜索。
搜索最初是由luis意图触发的,所以我认为这可能是导航到机器人中不同任务的最简单方法。但是,我不确定如何以编程方式向机器人发送消息/从代码中触发luis意图。
[LuisIntent("Stores")]
public async Task Stores(IDialogContext context, LuisResult result)
{
var reply = context.MakeMessage();
reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
reply.Attachments = new List<Attachment>();
List<CardImage> images = new List<CardImage>();
InfoClass IC = new InfoClass();
latitude = "-29.794618";
longitude = "30.823497";
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¢er=" + 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<CardImage> { images[z] },
Buttons = new List<CardAction>()
};
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);
}
async Task promtDecision(IDialogContext context, IAwaitable<string> userInput)
{
string inputText = await userInput;
if (inputText.Equals("yes") || inputText.Equals("y"))
{
RadiusPromt(context);
}
else
{
StartUp(context, null).Start();
}
}
void RadiusPromt(IDialogContext context)
{
PromptDialog.Number(context, AfterPromptMethod, "Please Enter Search Radius (In Kilometers)", attempts: 100);
}
async Task AfterPromptMethod(IDialogContext context, IAwaitable<long> userInput)
{
int Radius = Convert.ToInt32(await userInput);
await context.PostAsync("Store Locations");
}
}
答案 0 :(得分:1)
根据我对您的问题的理解,这是一个实现,使用SearchInArea
参数调用我调用int
的方法。
此方法从2个地方调用:
当您的LuisIntent Stores
被识别时
当您返回avec更改半径值
代码:
[LuisIntent("Stores")]
public async Task Stores(IDialogContext context, LuisResult result)
{
var defaultRadius = 10;
await SearchInArea(context, defaultRadius);
}
private async Task SearchInArea(IDialogContext context, int radius)
{
var reply = context.MakeMessage();
reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
reply.Attachments = new List<Attachment>();
List<CardImage> images = new List<CardImage>();
InfoClass IC = new InfoClass();
latitude = "-29.794618";
longitude = "30.823497";
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¢er=" + 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<CardImage> { images[z] },
Buttons = new List<CardAction>()
};
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, PromptDecision, "Would You Like To Change The Search Radius ?", attempts: 100);
}
private async Task PromptDecision(IDialogContext context, IAwaitable<bool> userInput)
{
var userBoolChoice = await userInput;
if (userBoolChoice)
{
RadiusPromt(context);
}
else
{
StartUp(context, null).Start();
}
}
private void RadiusPromt(IDialogContext context)
{
PromptDialog.Number(context, AfterPromptMethod, "Please Enter Search Radius (In Kilometers)", attempts: 100);
}
private async Task AfterPromptMethod(IDialogContext context, IAwaitable<long> userInput)
{
int radius = Convert.ToInt32(await userInput);
await SearchInArea(context, radius);
}