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

如何解决如何在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();
       }
    }
}

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

解决方法

首先,如果您还没有的话,我来看看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的机器人构建器,它基于Adaptive Dialogs,您甚至可能更喜欢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-