如何在Bot Framework 4中使用文本提示?

问题描述

我将在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();
       }
    }
}

我不知道如何实现用例。我认为瀑布对话对我来说不是正确的对话。 任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)