我已经在我们的机器人中实现了多轮QnA,并使用了这个类Microsoft.Bot.Builder.AI.QnA.Dialogs.QnAMakerDialog。
现在,我想扩展它的功能,以便在多轮对话后,机器人可以询问用户对话是否有帮助?如果不是,那么机器人将要求与帮助台记录一个工单。
我可以通过覆盖Dialog.EndDialogAsync方法来捕捉多轮对话的结束,但不能从那里启动另一个对话框。请帮帮忙。
public class QnAMultiTurnBase : QnAMakerDialog
{
// Dialog Options parameters
public readonly string DefaultNoAnswer = Configuration.Messages("Troubleshoot", "NoAnswer");//"No QnAMaker answers found.";
public readonly string DefaultCardTitle = Configuration.Messages("Troubleshoot", "DidYouMean");//"Did you mean:";
public readonly string DefaultCardNoMatchText = Configuration.Messages("Troubleshoot", "NoneOfTheAbove");//"None of the above.";
public readonly string DefaultCardNoMatchResponse = Configuration.Messages("Troubleshoot", "Feedback");//"Thanks for the feedback.";
private readonly BotServices _services;
private readonly IConfiguration _configuration;
//private readonly IStatePropertyAccessor<Dictionary<string, string>> troubleshootQuery;
private readonly Dictionary<string, string> qnaPair = new Dictionary<string, string>();
private readonly string qnAMakerServiceName;
/// <summary>
/// Initializes a new instance of the <see cref="QnAMakerBaseDialog"/> class.
/// Dialog helper to generate dialogs.
/// </summary>
/// <param name="services">Bot Services.</param>
public QnAMultiTurnBase(BotServices services, IConfiguration configuration, string qnAMakerServiceName) : base()
{
this._services = services;
this._configuration = configuration;
this.qnAMakerServiceName = qnAMakerServiceName;
}
protected async override Task<IQnAMakerClient> GetQnAMakerClientAsync(DialogContext dc)
{
return this._services?.QnAServices[qnAMakerServiceName];
}
protected override Task<QnAMakerOptions> GetQnAMakerOptionsAsync(DialogContext dc)
{
return Task.FromResult(new QnAMakerOptions
{
ScoreThreshold = DefaultThreshold,
Top = DefaultTopN,
QnAId = 0,
RankerType = "Default",
IsTest = false
});
}
protected async override Task<QnADialogResponseOptions> GetQnAResponseOptionsAsync(DialogContext dc)
{
var noAnswer = (Activity)Activity.CreateMessageActivity();
noAnswer.Text = this._configuration["DefaultAnswer"] ?? DefaultNoAnswer;
var cardNoMatchResponse = MessageFactory.Text(DefaultCardNoMatchResponse);
var responseOptions = new QnADialogResponseOptions
{
ActiveLearningCardTitle = DefaultCardTitle,
CardNoMatchText = DefaultCardNoMatchText,
NoAnswer = noAnswer,
CardNoMatchResponse = cardNoMatchResponse,
};
return responseOptions;
}
public override Task EndDialogAsync(ITurnContext turnContext, DialogInstance instance, DialogReason reason, CancellationToken cancellationToken = default(CancellationToken))
{
try
{
// end of multi turn convversation
// ask if conversation helped the user or not
}
catch (Exception)
{
turnContext.SendActivityAsync(MessageFactory.Text(Configuration.Messages("UnknownError"))).Wait();
throw;
}
return base.EndDialogAsync(turnContext, instance, reason, cancellationToken);
}
}发布于 2020-10-05 13:49:38
添加一个新对话框,并启动使用BeginDialogAsync添加的对话框:
AddDialog(new MoreHelp());
return await stepContext.BeginDialogAsync(nameof(MoreHelp), UserInfo, cancellationToken);
发布于 2020-10-01 18:07:29
您可以参考this文档,其中指定了如何创建自己的提示来收集用户输入。机器人和用户之间的对话通常涉及向用户询问(提示)信息,解析用户的响应,然后根据该信息采取行动。
对话框操作-能够控制对话框、BeginDialog、RepeatDialog、GotoDialog、EndDialog等。
请按照下面的步骤进行多轮转弯。
https://stackoverflow.com/questions/64100174
复制相似问题