【问题标题】:How to use text prompt in bot framework 4?如何在机器人框架 4 中使用文本提示?
【发布时间】: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); 

其中contextIDialogContext 类型,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


    【解决方案1】:

    首先,如果您还没有,我会看一下 Migrating from V3 to V4 上的文档。

    有很多不同的方法可以实现你想要的,所以我很难提供一个准确的答案。一般来说,我会说瀑布对话框是要走的路。

    如果你使用瀑布对话框,听起来你需要处理中断,所以如果:

    1. 用户问“我正在寻找 XY”
    2. 机器人启动瀑布对话框并提示“部门名称是什么?”
    3. 用户忽略提示并询问“我正在搜索 ABC”

    ...它需要能够中断对话。为此,我会查看Core Bot Sample。它通过Cancel and Help Dialog 处理中断。基本上,所有用户输入首先进入此对话框。如果用户说“取消”或“帮助”,它会中断当前对话并处理这些意图。你可能会做一些与MyIntent 类似的事情,而不是取消和帮助。 请注意,但是此示例不为此使用 LUIS。您需要让 LUIS 查找意图,然后根据这些意图中断

    如果您正在寻找更灵活的东西,您可能需要考虑Adaptive Dialogs。瀑布对话框非常程序化; if user says "X" in this circumstance, do "Y"。自适应对话框更加灵活,因为用户当前在做什么并不重要——如果他们说出具有匹配意图的内容,它就会启动相应的对话框。我认为这更符合您的要求,但我们没有针对它的迁移文档。 Here mare several Adaptive Dialog samples

    Composer,一个基于 GUI 的机器人构建器,基于自适应对话框,您甚至可能更喜欢它。

    【讨论】:

      猜你喜欢
      • 2020-12-07
      • 2018-10-06
      • 1970-01-01
      • 1970-01-01
      • 2014-08-21
      • 1970-01-01
      • 2021-07-18
      • 2021-04-09
      • 2018-04-01
      相关资源
      最近更新 更多