我正在设计一个查询数据库的机器人,但是遇到了麻烦。
[LuisIntent("ProjectInfo")]
public async Task projectInfo(IDialogContext context, LuisResult result)
{
PromptDialog.Text(context,AfterPromptMethod,"Please enter your project name", attempts: 100);
}
async Task AfterPromptMethod(IDialogContext context, IAwaitable<string> userInput)
{
var InputText = await userInput;
string projectName = InputText.ToString();
if (projectName!= null)
{
TestInfo MI = new TestInfo();
if (MI.FindProject(projectName) == 0)
{
await context.PostAsync($"Project Found. What do you want to know ?");
}
else
{
//PromptDialog.Text(context,AfterPromptMethod,"Pleaase check your product name and try again", attempts: 100);
await context.PostAsync($"Project Not Found. Check your project name and try again.");
}
}
context.Wait(MessageReceived);
}
这是我想放入循环的地方,projectInfo的名称很好,但是当到达找不到项目的if语句时,它什么也不做。我试图插入“ context.Wait(projectInfo)”,但没有帮助。我还尝试使用提示对话框,如果是,则返回到主菜单。但是,我还没办法解决这种问题。
有人有任何建议或更好的方法吗?
最佳答案
如果您想要再次进入projectInfo方法,则只需调用它即可:)
我更新了您的代码
[LuisIntent("ProjectInfo")]
public async Task projectInfo(IDialogContext context, LuisResult result)
{
PromptDialog.Text(context,AfterPromptMethod,"Please enter your project name", attempts: 100);
}
async Task AfterPromptMethod(IDialogContext context, IAwaitable<string> userInput)
{
var InputText = await userInput;
string projectName = InputText.ToString();
if (projectName!= null)
{
TestInfo MI = new TestInfo();
if (MI.FindProject(projectName) == 0)
{
await context.PostAsync($"Project Found. What do you want to know ?");
context.Wait(MessageReceived);
}
else
{
await context.PostAsync($"Project Not Found. Check your project name and try again.");
await this.projectInfo(context, null);
}
}
}