如何在Google Actions上使用Dialogflow Fulfillment Node.js实现二进制决策树?

huangapple go评论77阅读模式
英文:

How to implement a binary decision tree on google actions using dialogflow fulfillment node.js?

问题

Here's the translated content:

我想在欢迎意图中向用户提问一些问题,并根据他们的回答给出特定的回应。
我的问题是,一旦用户回答了第一个问题,代理程序就会退出我的欢迎意图,并尝试匹配下一个意图。
我认为我可以通过将其匹配回欢迎意图来解决这个问题。
理想情况下,应该是这样的:
'欢迎意图 -> 第一个问题 -> 用户回答 -> 欢迎意图 -> 第二个问题 -> 依此类推'
但实际上发生了这种情况:
'欢迎意图 -> 第一个问题 -> 用户回答 -> 欢迎意图 -> 第一个问题'
它会一直询问第一个问题。
为了解决这个问题,我开始为每个问题维护一个标志。
如果回答了问题1,我会将其标志设置为true,然后在第二次匹配欢迎意图时使用它来跳过第一个问题。
这是一种非常复杂的方法,可能远非最佳方法。
有人能指导我实施的正确方向吗?
谢谢。

编辑:我已经放弃了我的旧方法。让我解释一下我想要做什么,然后我可以获得关于如何实施的指导。
我有16个不同的输出,根据用户对4个问题的回答,我想向用户展示其中一个。每个问题只有两个答案选项,根据用户为每个问题选择的选项,我将选择其中一个16个输出并显示给用户。
如何在Dialogflow Node.js中实现这个目标?

英文:

I want to ask the users a few questions in my welcome intent and depending on their answers give them a particular output.
My problem is that, once the user answers the first question, the agent exits my welcome intent and tries to match with the next intent.
I thought I could solve this by matching it back to the welcome intent.
So ideally it should have gone like this :
Welcome intent -> 1st question -> user answer -> Welcome intent ->2nd question -> and so on
But actually this happens :
Welcome intent -> 1st question -> user answer ->Welcome intent -> 1st question
It will keep asking the first question.
To solve this , I started maintaining a flag for each question.
If question 1 was answered I would set its flag true and then use it to skip the first question when the welcome intent is matched for the second time.
This is a very convoluted way to do it and probably far from the best way to do it.
Can anyone point me in the right direction to implement it?
Thank you.

Edit : I have given up my old method. Let me explain what I want to do and then I can get guidance on the way I should implement it.
I have 16 different outputs and I would like to show one of them to the user depending on their answer to 4 questions. Each question will only have two answers as options and depending on the option chosen by the user for each question , I will pick one of the 16 outputs and display it to the user.
How do I accomplish this using diaglogflow node.js?

答案1

得分: 3

首先要记住,意图(Intent)捕获的是用户说或做的内容,而不是你对这些信息的处理方式或如何回应它。这部分最好由你的履行部分处理。虽然我们可以使用上下文(Contexts)来限制哪些意图将被考虑为用户的响应,但在这种情况下,它们可能最有用的是用于存储你的状态并跟踪已提出和已回答的问题。

根据这个方案,你的意图仍然负责捕获输入,而你的履行部分则检查这个输入,根据这个输入更改状态,并根据新状态发送回复(询问下一个问题所需的内容)。如果用户的回复大部分都相同(自由形式的回复或来自相同的短语集),甚至可以使用相同的意图来捕获这个输入,而履行部分会使用状态和输入来确定要执行的逻辑。如果你需要不同类型的输入,因此需要不同的意图,它们的处理程序仍然可以调用通用函数来进行处理并更改状态/回复。

这在Thinking for Code: Design conversations not logic中进一步讨论。

英文:

First of all remember that an Intent captures what the user says or does and not what you do with that information or how you reply to it. That part is best handled by your fulfillment. While we can use Contexts to limit which Intents will be considered for a user response they are probably most useful in this case to store your state and keep track of which questions have been asked and answered.

Under this scheme, your Intents remain responsible for capturing input and your fulfillment examines this input, changes state based on this input, and sends a reply based on the new state (what it needs to ask next). If the user's responses will be mostly the same (free form, or from the same set of phrases), you can even use the same Intent to capture this input and the fulfillment would use the state and input to determine what logic to execute. If you need different types of input, and thus different Intents, their handlers can still call common functions to do the processing and change the state/reply.

This is further discussed in Thinking for Code: Design conversations not logic

答案2

得分: 1

你可以在Dialogflow控制台中使用"后续意图"的概念来创建一系列问题和答案的链条。

以下是我的一系列问题和答案的示例:
如何在Google Actions上使用Dialogflow Fulfillment Node.js实现二进制决策树?

尽管我仍然强烈建议您也学习输入/输出上下文的工作原理,特别是如果您希望在最后一步的最终履行中收集所有用户回复参数,以避免将用户输入存储在与链条中的每个意图相关联的履行中。

英文:

You can use the concept of the follow-up intents in Dialogflow Console to create a chain of questions/answers.

Here is an example of my chain of questions/answers:
如何在Google Actions上使用Dialogflow Fulfillment Node.js实现二进制决策树?

Though I still strongly advise you to study also how input/output context works. Especially if you want to collect all user reply parameters in the one final fulfillment of the last step to avoid storing the user inputs in fulfillments attached to every intent of the chain.

huangapple
  • 本文由 发表于 2020年1月3日 17:33:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/59576072.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定