有没有一种方法可以在填充dialogflow所需的插槽时触发不同的查询 [英] Is there a way to trigger different query while filling the required slots in dialogflow

查看:48
本文介绍了有没有一种方法可以在填充dialogflow所需的插槽时触发不同的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个意向的订单比萨饼和实体为@pizzaOptions @pizzaSize @qty

I have an intent orderPizza and entities as @pizzaOptions @pizzaSize @qty

幸福的道路(工作正常)

happy path (working fine)

user: order 2 pizza
bot: which pizza you want?
user: pepperoni
bot: and pizza size?
user: large
bot: okay! your order for 2 large pepperoni pizza has been placed.

CASE_2

user: order 2 pizza
bot: which pizza you want?
user: which pizza options do you have?
bot: which pizza you want?

在情况2中,当用户要求提供披萨选项时,机器人会再次提示相同的问题

so in case 2 when user ask for the pizza Options then bot re-prompt the same question

我希望漫游器回答用户查询,或者漫游器可以显示选项(不同的重新提示),而不是相同的重新提示

I want bot to answer the user query or bot can present the options (different re-prompt) instead of same re-prompt

有没有办法处理这个用例

is there a way to handle this use case

推荐答案

最好的设置是具有2个意图.

The best setup for this would be to have 2 intents.

  1. 订购披萨意向(订购x披萨")
  2. 获取披萨选项意图(您有哪些披萨选项?")

之所以这样,是因为用户试图从您的机器人中获得两个完全不同的结果.当用户要求输入披萨类型时,他们并不总是在订购披萨,他们可能只是对您可用的类型感兴趣.

The reason for this is, because the user is trying to get two completely different results from you bot. When the user asks for Pizza type, they aren't always ordering a pizza, they could just be interested in your available types.

  • 获取披萨选项的意图只是返回一个响应为用户提供可用披萨类型的示例.
  • 如果您确保这两个意图都不需要任何输入上下文,您应该能够实现您要使用的用例

如果使用此设置并确保未按要求设置参数,则应该可以在插槽填充期间在这两种意图之间进行切换.在您提供的示例中,您可以看到在Case2中,您的机器人不断询问用户有关披萨类型的信息,这是因为它希望输入披萨类型的实体.

If you use this setup and make sure that the parameters aren't set as required, you should be able to switch between these two intents during the slot filling. In the example you gave you can see that you bot in Case2 keeps asking the user about the pizza type, this is because it expects a pizza type entity as input.

一些示例对话为:

User: I want to order a pizza.
Bot: Sure, which Pizza do you want? // Order Pizza Intent

User: I don't know, which pizzas do you have?
Bot: We currently sell Pepperoni Pizza and Vegan Pizza, what else can I Help you with?  // Get Pizza Option Intent

User: I'd like to order 2 large Pepperoni Pizzas
Bot: Okay! your order for 2 large pepperoni pizza has been placed. // Order Pizza Intent

User: Hey, what types of pizza do you have? // Order Pizza Intent
Bot: We currently sell Pepperoni Pizza and Vegan Pizza, what else can I help you with? // Get Pizza Option Intent

User: Hhm, I'm looking for something else, I'll go look somewhere else.
Bot: Sorry to hear that, I hope you have a nice day. 

插槽中的Webhook填充

由于我们选择不设置必需参数,因此我们现在保存并检查了所有参数.每次用户提及订单时,我们都应检查其是否完整.

Because we chose to not make the parameters required, we now have save and check all the paramters ourself. Each time the user mentions an order, we should check if it is complete.


function orderIntent(conv) {

const pizzaOption = conv.paramters.pizzaOption;
const pizzaSize = conv.parameters.pizzaSize;
const quantity = conv.parameters.qty;

if (!pizzaOption) {
  return conv.ask("Which pizza do you want?");
}

if (!pizzaSize) {
  return conv.ask("Which size pizza do you want?");
}

if (!quantity) {
  return conv.ask("How many pizzas do you want?");
};

现在,这将使我们能够提示用户,直到他们提供完成订单的所有信息为止.如果您使用此代码,则漫游器将一直循环运行,直到用户提及一个包含PizzaType,pizzaSize和数量的单个短语实体.

This will now allow us to prompt the user until they provide all the information to complete the order, if you would use this code, the bot would keep looping until the user mentions a single phrase that includes a pizzaType, pizzaSize and quantity entity.

由于用户不太可能执行此操作,因此我们需要扩展代码以允许将订单分为多个步骤并了解我们所处的步骤.我们将通过添加上下文并遵循以下步骤来进行操作:意图.

Because it is unlikely that the user will ever do this, we need to expand the code to allow the order to be split up in multiple steps and understand which step we are in. We will do this by adding context and follow-up intents.

记住用户订单

首先,让我们添加后续意图.因为我们希望能够拆分预留,所以我们应该为每个步骤添加后续意图.我用来测试的dialogflow代理如下所示:

Firstly, lets add the follow-up intent. Because we want to be able to split up the reservation, we should add a follow-up intent for each step. My dialogflow agent that I used to test this looks like this:

每个跟踪意图都将其中一个实体作为示例短语:

Each follow-up intent takes one of the entities as a example phrase:

  • 缺少PizzaTypes,@ PizzaOption实体作为受训短语
  • 缺少PizzaSize,@ PizzaSize实体作为训练短语
  • 缺少数量,@ system.integer作为训练短语

设置完这些之后,您需要为这些后续操作启用履行功能,并将它们添加到与订单意图相同的处理程序中.现在已经设置好意图,我们需要添加保留上下文并保存任何有效数据.

After setting these up, you need to enable fulfillment for these follow-ups and add them to the same handler as with the order intent. Now that the intents are setup, we need to add the reservation context and save any valid data.

// All the order follow-ups and the order intent use the same handler.
    app.intent(
      ["Order Intent", "Complete Order - Missing PizzaType", "Complete Order - Missing Pizza Amount", "Complete Order - Missing PizzaSize"],
      (conv) => {

        // Check if any reservation info is available.
        const order = conv.contexts.get("reservation");

        // If the user has already mentioned pizza info, use context, otherwise take it from the user input.
        const pizzaType = order?.parameters.pizzaType ?? conv.parameters.pizzaType;
        const pizzaSize = order?.parameters.pizzaSize ?? conv.parameters.pizzaSize;
        const pizzaAmount = order?.parameters.pizzaAmount ?? conv.parameters.pizzaAmount;

        // Allow the fallback intents to be triggered
        conv.contexts.set("OrderIntent-followup", 2);

        // Validate the input
        if (!pizzaAmount) {
          return conv.ask("How many pizza's would you like to order?");
        }

        // Save input if valid
        conv.contexts.set("reservation", 5, { pizzaAmount });

        if (!pizzaType) {
          return conv.ask("Which pizza would you like?");
        }

        conv.contexts.set("reservation", 5, { pizzaAmount, pizzaType });

        if (!pizzaSize) {
          return conv.ask("What size should your pizza be?");
        }

        return conv.ask(`Alright, your order has been completed: ${pizzaAmount} ${pizzaSize} ${pizzaType}`);
      },
    );

最终结果

这篇关于有没有一种方法可以在填充dialogflow所需的插槽时触发不同的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆