【发布时间】:2020-08-28 01:28:34
【问题描述】:
我正在将已在 Framework 3 中实现的代码更改为 Framework v4。
用例如下: 用户输入类似“我正在搜索 XY”的内容。 我们确定意图,如果是 MyIntent,我们在数据库中搜索输入,如果找到,我们向用户显示文本,例如“我在数据库中找到您的搜索项”。 然后,我们显示另一个文本(后续问题),例如“部门名称是什么?”。
用户可以输入一些东西,它会被处理。但关键是,此时,用户可以再次说“我正在搜索 ABC”。也就是说,用户可以忽略聊天机器人已提出后续问题并输入正常输入。并且聊天机器人也应该像普通的一样处理它。
同时,如果一开始输入的项目在数据库中没有找到,我们想返回类似“对不起,我在数据库中找不到它。还有什么可以帮助您的吗? "
我的意思是,我在这个意图中有一个条件。
之前,这部分文字提示已经简单实现了:
PromptDialog.Text(context, answerMe, "What is the name of the department?", $"Sorry I don't understand.", 3);
其中context 是IDialogContext 类型,answerMe 是如下方法:
private async Task answerMe(IDialogContext context, IAwaitable<string> res1)
{
string text = await res1;
if (Functions.IsCancelList(text, CancelOptionsEqual, CancelOptionsContain))
{
await CancelDialog(context, "Empty");
}
else
{
string s = text;
bool str=Functions.isText(s);
...
await CallMethod(context, text);
}
}
现在,我的班级如下:
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using RestSharp;
using System;
using System.Threading;
using System.Threading.Tasks;
using XYT.Models;
using XYT.Services;
namespace XYZ.Dialogs
{
public class MyMainDialog: MainDialogBase
{
private readonly ICommonBotServices _commonBotServices;
public MyMainDialog(IConfiguration configuration, ILogger<MainDialogBase> logger, ICommonBotServices commonBotServices, IServiceProvider serviceProvider, UserState userState)
: base(configuration, logger, serviceProvider, userState)
{
_commonBotServices = commonBotServices;
}
protected override async Task<DialogTurnResult> ProcessInput(WaterfallStepContext wtrflCntxt, CancellationToken cancellationToken)
{
var result = await _commonBotServices.Luis.RecognizeAsync<MyRecognizer>(wtrflCntxt.Context, cancellationToken);
var intent = result.TopIntent();
switch (intent.intent)
{
case MyRecognizer.Intent.MyIntent:
await wtrflCntxt.Context.SendActivityAsync($"Let me search");
String answer = $"I found it in the database,...";
await wtrflCntxt.Context.SendActivityAsync(answer);
//??? to be implemented
return await wtrflCntxt.EndDialogAsync();
}
}
}
我不知道应该如何实现用例。我不认为瀑布对话框对我来说是正确的。 任何帮助将不胜感激。
【问题讨论】:
标签: c# botframework chatbot