node.js - 当用户在对话框流中从另一个意图键入列表项时如何触发列表
问题描述
我有一个显示 3 个项目的列表,但是当我从列表(intent1)中选择一个项目时,它会起作用并触发意图 2,但是在几个意图之后,如果我再次输入项目名称,那么意图 2 不会触发并给出回退的响应意图。
这是我的代码
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
如何得到这个,代码中是否缺少任何东西。
解决方案
我认为你的对话设计有点混乱,这可能会让你更难做你想做的事。
您SELECTED_ITEM_INTENT
的触发仅基于与列表的交互,并且您正在提示他们说些什么。由于列表不再处于活动状态,并且您没有设置任何意图来处理任何短语,因此没有任何匹配项。
您可能希望将其更多地作为语音对话来处理,而不是依赖视觉列表(这不适用于所有智能助理平台)。在此模型下,您可以描绘如下所示的对话:
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
...
由此,我们可能会认为用户会以以下三种方式之一进行回复:
- 用“书籍”、“游戏”、“语言详细信息”、“我的意思是游戏”、“添加更多语言”、“另一本书”等短语来表明他们想要的类别。
- 这表明对于用户可能说的短语,每个类别都可能是一个很好的实体。
- 随着他们正在更新的任何东西的价值
- 这可以通过使用上下文来知道我们何时要求特定的东西来很好地处理。正如你所做的那样。
- 用诸如“我能做什么?”之类的短语寻求帮助。或“我不明白”。
这些中的每一个都将使用带有短语和为这些短语调整的输入上下文的意图来完成。在输出中,我们可能会在适当的地方使用 Suggestion Chips 来提示我们对第一个 Intent 期望的可能类别。
但是我们没有考虑用户可能说过的其他一些事情。例如,如果我们有
Agent: Rock, paper, scissors has been set as your favorite game. What would you like to update next?
User: Add another one
用户知道他们只是设置了一个游戏,并且他们想要设置另一个游戏。但他们并没有专门使用“游戏”这个词。我们将需要跟踪他们最后在 Context 中更新的类别,并有另一个 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,它们同时指定类别和信息。
推荐阅读
- excel - 我可以在 Python 中运行 VBA 函数吗?
- c++ - 为什么此代码在实际 BCM2837(pi 3)上运行时会挂起,但在 qemu 上运行良好
- python - 如何在python中可视化决策树?
- ios - 选项卡视图中的分段控件加载问题
- list - 何时选择容器/列表而不是切片
- java - 创建新项目时的弹簧缓存
- java - 如何检查属性文件路径是否设置正确
- terraform - CPU 和内存的 Terraform Openstack 输出参数
- javascript - 我想更改显示的 HTML 文本:#shadow root (user-agent)
- java - 大气websocket返回多个对象