当用户从对话框流中的另一个意图键入列表项时如何触发列表

问题描述 投票:0回答:1

我有一个显示3个项目的列表,但是当我从列表(intent1)中选择一个项目时,它可以工作并触发intent2,但是如果经过几次intent,如果我再次输入项目名称,那么intent2不会触发并给出响应后备意图。

这是我的代码

const ItemList = {
    title: "Select to update.",
    items: {
      "Games": {
        title: "Games",
        description: "Click here to update Games details.",
        image: new Image({
          url: 'https://img.icons8.com/plasticine/2x/name.png',
          alt: 'p1',
        }),
      },
      "Books": {
        title: "Books",
        description: "Click here to update Books details.",
        image: new Image({
          url: 'https://img.icons8.com/plasticine/2x/name.png',
          alt: 'p2',
        }),
      },
      "Language": {
        title: "Language",
        description: "Click here to update Language details.",
        image: new Image({
          url: 'https://img.icons8.com/plasticine/2x/name.png',
          alt: 'p3',
        }),
      },
    },
  }


app.intent(SHOW_LIST_INTENT, (conv) => {
  conv.ask("Here's the list.");
  conv.ask(new List(ItemList));
});

app.intent(SELECTED_ITEM_INTENT, (conv, input, option) => {
    conv.contexts.set(AppContexts.AWAITING_ITEM, 1, {item: option});

    if (option === 'Games'){
      conv.ask(`Which is your favorite Game?`); 
    } else if (option === 'Language'){
      conv.ask(`Which ${option} do you know?`);
    } else if (option === 'Books'){
      conv.ask(`Your favorite ${option} name?`);
    }
});

app.intent(HANDLER_INTENT, (conv, parameters) => {
  const context = conv.contexts.get(AppContexts.AWAITING_ITEM);
  const selectedItem = context.parameters.item;


    if (selectedItem === 'Games'){
      conv.ask(`${parameters} is updated as your favorite Game. ` + `Your next preference?`);
      conv.ask(new Suggestions([`Add More Games`, `Show List`]));
    } else if (selectedItem === 'Books'){
      conv.ask(`${parameters} is updated as your favorite Book. ` + `Your next preference?`);
      conv.ask(new Suggestions([`Add More Books`, `Show List`]));
    } else if (selectedItem === 'Language'){
      conv.ask(`${parameters} is updated as your Language. ` + `Your next preference?`);
      conv.ask(new Suggestions([`Add More Language`, `Show List`]));
    }
});

exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

当用户说添加更多游戏时,我想触发SELECTED_ITEM_INTENT

如何获得此代码,代码中是否缺少任何内容。

ShowListIntentSelectedItemIntentHandlerIntent

node.js actions-on-google chatbot dialogflow-fulfillment
1个回答
0
投票

我认为您的对话设计有些混乱,这可能会使准确地执行您想要的事情变得更加困难。

您的SELECTED_ITEM_INTENT仅基于与列表的交互而触发,您正在提示他们说些什么。由于该列表不再有效,并且您没有设置用于处理任何短语的Intent,因此没有匹配项。

您可能不希望依赖可视列表(在所有Assistant平台上都无法正常运行),而可以将其更多地用作语音对话。在此模型下,您可以为看起来类似以下内容的对话添加图片:

Agent: Would you like to update the Games, Books, or Language details?
User:  Games
Agent: What is your favorite game?
User:  Rock, paper, scissors
Agent: Rock, paper, scissors has been set as your favorite game. What would you like to update next?
User:  Another game
...

或者对话可能会发生类似的事情

Agent: Would you like to update the Games, Books, or Language details?
User:  Game details
Agent: What is your favorite game?
User:  Rock, paper, scissors
Agent: Rock, paper, scissors has been set as your favorite game. What would you like to update next?
User:  Another game
...

但是如果他们说这样的话怎么办?

Agent: Would you like to update the Games, Books, or Language details?
User:  Books
Agent: What is your favorite book?
User:  I meant game
Agent: What is your favorite game?
User:  Rock, paper, scissors
Agent: Rock, paper, scissors has been set as your favorite game. What would you like to update next?
User:  I don't know
...

因此,我们可能认为用户会以以下三种方式之一进行回复:

  1. [用诸如“书”,“游戏”,“语言详细信息”,“我的意思是游戏”,“添加更多语言”,“另一本书”等短语表示他们想要的类别。
    • 这表明对于用户可能说的短语,每个类别可能都是一个很好的实体。
  2. 具有他们正在更新的内容的价值
    • 这可以通过使用上下文来很好地处理,以了解我们何时需要特定的内容。完成后。
  3. [使用诸如“我该怎么办?”之类的短语寻求帮助。或“我听不懂”。

其中的每一个都可以使用带有短语的Intent和针对这些短语调整的输入上下文来完成。在输出中,我们可能会在适当的地方使用建议芯片,以提示我们期望的第一个Intent。]

但是我们还没有考虑用户可能说过的其他事情。例如,如果我们有

Agent: Rock, paper, scissors has been set as your favorite game. What would you like to update next?
User:  Add another one

用户知道他们只是设置了一个游戏,并且想要设置另一个游戏。但是他们没有专门使用“游戏”一词。我们将需要跟踪它们在上下文中最后更新的类别,并具有另一个Intent,该Intent可以处理诸如“添加另一个”或“同一件事”之类的短语。

但是,如果我们的用户开始大量这样做并且我们进行了诸如]的交互,该怎么办?

Agent: Rock, paper, scissors has been set as your favorite game. What would you like to update next?
User:  Add a book named Dungeon Masters Guide

[这里,它们已经结合到我们认为是单独的Intent的事物上。因此,我们可能需要添加一个Intent来处理诸如此类的短语,其中它们同时指定类别和信息。

© www.soinside.com 2019 - 2024. All rights reserved.