botframework - 需要一些关于如何正确使用机器人框架 SDK 的指导

标签 botframework bots azure-language-understanding adaptive-cards

我正在构建一个机器人,到目前为止,这段经历对我来说充满挑战。这很可能是因为我来自 v1 并且我正在尝试以 v4 风格重建我的机器人,这似乎是一个完全不同的框架。
我发现那里有很多文档,但它被分为理论和实践,可能是由于您可以使用不同的开发框架(即 Node、C#)。但是不得不在这些文章之间来回切换无济于事,
经过一番折腾,我到了事情开始变得更体面的地步,但我仍然觉得还有很多改进的空间。我目前无法分享整个项目,但我在这里创建了最重要代码的要点:https://gist.github.com/jsiegmund/831d5337b1a438133991070daba8a27e
所以我对这段代码的问题/问题如下:

  • 添加对话框的方式以及主要需要添加检索答案的提示令人困惑。我明白了,但不是内部运作。例如:我现在有以相应对话框步骤的相同方法名称命名的提示,这是它应该工作的方式吗?按照惯例,似乎有一些神奇的代码将所有东西连接在一起?当瀑布步骤也包括提示时,对我来说会更有意义。
  • 为对话提供信息以便它可以跳过步骤的正确方法是什么?我在主对话框中设置了 LUIS 意图,然后打开此对话框进行小时预订。假设我的用户说“我想为客户 X 预订 8 小时”,我希望对话框将金额预填充为 8,并将客户预填充到 X。
  • 客户/项目解决在这里可能是一个不太标准的要求。这些来自第三方应用程序,通过 API/SDK 检索。因此,基于登录用户,我需要转到该应用程序并检索该用户的数据。这以键/值对的形式返回,其中键是 GUID。我不希望用户输入 GUID,所以我创建了这些带有客户姓名的操作按钮,但是为了将 ID 值输入到下一步,它现在在聊天中“写入”GUID 而不是客户姓名。使用这个名字很棘手,因为我不能完全依赖那些是独一无二的。此外,为了选择项目,我需要客户 GUID 并保存最终条目,我还需要 ID。但我不希望用户看到这些。
  • 我现在制作卡片的方式对我来说也很奇怪。我首先需要为卡片添加一个对话框,稍后在调用 stepContext.PromptAsync 时我还需要提供卡片作为附件。对我来说感觉重复,但删除其中一个步骤失败。正常的样式提示对我不起作用,因为它不处理键/值而只处理字符串(参见数字 3)。

  • 好的,所以这些是我正在努力解决的一些问题。我正在到达那里并且它现在有效,但正如所说,我无法摆脱我做得不对的感觉。如果有人能对此有所启发,将不胜感激。

    最佳答案

    是的,从版本到版本有很多变化。你真的是说v1吗?! 😲 还是v3?

    1. The way to add dialogs and mainly the need to add prompts for retrieving the answers is confusing. I get the idea, but not really the inner workings. For instance: I now have the prompts named after the same method names of the corresponding dialog step, is that the way it's supposed to work? There seems to be some magic code linking everything together, by convention? It would make much more sense to me when the waterfall steps would also include the prompts.

    本质上。瀑布数组中列出的步骤是您创建的方法名称的名称。基本上,这是您给出机器人应执行的步骤顺序的地方。提示是用于检索数据的类,并使用 AddDialog() 填充到(“主”)对话框中。并以唯一名称存储在对话状态中,以便可以正确检索它们。我明白您的观点,即在一个“调用”或声明中设置所有内容可能很简单,并且可能还有其他方法来实现这一点;但这就是我们得到的。
    1. What's the right way of feeding the dialog with information so it can skip steps? I've got LUIS intents set-up in a main dialog which then open up this dialog for hour booking. Suppose my user says "I'd like to book 8 hours on customer X", I'd like the dialog to pre-populate the amount to 8 and the customer to X.

    通常,步骤使用先前的步骤值来回复、操作或继续。在简单的场景中,可以通过检查这些值的状态来跳过步骤。在 multiturn sample ,如果用户不想提供他们的年龄,它会继续下一步,然后检查值并跳过这一步(它真的没有跳过它,它报告没有给出年龄,但你可以继续没有任何回复)。假设事情的 LUIS 方面是正确的并获得正确的意图 + 实体(假设“预订”意图和实体 [“时间”和“客户”]),那么这应该是可行的。您将为这两个实体填充状态信息,然后后面的步骤(例如提示客户步骤)将跳过/绕过。
    但是,您真正想做的是查看自适应对话框。它们是新的,使这种类型的场景更加动态和灵活。看这里:
  • https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-adaptive-dialog-introduction?view=azure-bot-service-4.0
  • https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-dialogs-adaptive?view=azure-bot-service-4.0&tabs=csharp
  • https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/csharp_dotnetcore/adaptive-dialog

    1. The customer / project resolving is maybe a not-so-standard requirement here. These come from a third party application, retrieved through API/SDK. So based on the logged in user I need to go out to that application and retrieve the data for this user. This comes back in key/value pairs, where the key is a GUID. Obviously I don't want the user to type in GUIDs, so I have created these action buttons with the names of the customers, but to get the ID value into the next step it now 'writes' the GUID in the chat instead of the customer name. Using the name is tricky as I can't fully rely on those being unique.

    我对这部分不是 100% 确定。让我调查一下然后再回复你。

    Also, for selecting the project I need the customer GUID and saving the final entry I also need the ID's. But I don't want the user to see those.


    状态(对话|用户|等)将是管理这个的好地方。
    1. The way I now have the cards built is also weird to me. I first need to add a dialog for the card, and later when calling stepContext.PromptAsync I need to supply the card as an attachment as well. Feels duplicate to me, but removing either one of the steps ends in failure. The normal style prompt doesn't work for me as that doesn't handle key/value but just strings (see number 3).

    不,那是正确的。我知道这感觉很奇怪,但这就是这样做的方式。基本上,除了简单文本之外的任何内容都将成为附件。卡片是 JSON,因此是一个附件,您需要将其发送给用户/客户端。
    你做的都是对的。再次;我建议查看自适应对话框,因为这是更新的技术和前进的方向。然而在其他方面;你走在正确的道路上!

    关于botframework - 需要一些关于如何正确使用机器人框架 SDK 的指导,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63352812/

    相关文章:

    c# - 在 BotFramework 上启动从机器人到用户的消息

    c# - 如何在 Bot Framework C# 中对包含附件或更多对象的对话框进行单元测试

    Java - 如何从网站(非源)检索文本

    javascript - 我正在尝试制作一个discord.js头像命令,并且提到的部分无法正常工作

    node.js - 在 Microsoft Luis 中,如何对实体数组建模?

    azure - Teams 中的 Microsoft Bot Framework 是否可以免费使用我自己的端点?

    c# - BOT 框架中 qnA 和 Luis 之间的 Intent Score 映射

    azure - 尝试在 Azure 中部署 Echobot 时如何解决“访问被拒绝”错误?

    azure-language-understanding - 在没有 Bot Framework 的情况下使用 LUIS 进行对话机器人

    java - 是否可以使用 API 创建聊天机器人模型,将意图、对话从 Java 传递到 AZURE 机器人服务