来自 webhook 的 dialogflow 触发事件

dialogflow trigger event from webhook

我有一个带有操作 x 的意图 I1 和一个调用 webhook 的意图 I2。

有没有办法从 I2 webhook 响应中触发 x,以便 "redirect" 用户在 webhook 给出答案后转到 I1?

有没有办法从 dialogflow 控制台执行此操作?

编辑: 添加图表以进一步说明。 处理 "no" 后续部分的正确方法是什么?

意图代表用户的输入(通常是他们说的),而不是您的身份 "doing"。

虽然您可以从 webhook(例如您的 I2 处理程序)重定向到事件(可能由 I1 拾取),但您不能这样做 "after"webhook 回复。这将替换 webhook 的结果。 (而且,虽然可能,但它通常不是解决问题的最佳方法。)

您也无法通过 Dialogflow 配置执行此操作。必须通过 webhook 完成。

根据您的图表更新

您的图表说明了为什么我们鼓励人们考虑 对话 以及用户 而不是 "what do we do" 的内容。对话图与流程图并不完全相同。让我将其重组为几个脚本(稍后我们将对其进行注释)。

脚本 1:

User:  Talk to number or letter
Agent: Welcome! Would you like to hear a number or letter? 
User:  How about a number
Agent: 1 is the loneliest number. Would you like another?
User:  Yes
Agent: 2 is the only even prime. Care for another?
User:  No
Agent: Ok, would you like to hear a number or letter?

脚本 2:

User:  Talk to number or letter
Agent: Welcome! Would you like to hear a number or a letter?
User:  Number, please
Agent: 42 is the answer Another one, so to speak?
User:  sure
Agent: 21 is blackjack. Care for another?
User:  nope
Agent: Ok, care for a letter or a number?

脚本 3:

User:  Talk to number or letter
Agent: Howdy! Would you like a letter or a number?
User:  Let's go for a number
Agent: A googol is 10 to the 100th power. Ready for another?
User:  How about a letter this time
Agent: The letter "A" is one of only two letters that are also words. Want another?

这里有几点值得借鉴:

  • 当被问及问题时,人们会以多种不同的方式做出回应。意图使用许多示例短语以及一些 ML 算法来匹配用户所说的内容和他们的回复方式。
  • 在真实对话中,用户可以向任何方向进行对话。因此,尽管我们问的是是或否的问题,他们可能会尝试将对话引向一个完全不同的方向。
  • 我们如何回复取决于两件事:
    1. 我们处于什么状态
    2. 用户怎么说
  • 上面第 (1) 点的结果是我们应该跟踪用户的状态以确定我们说了什么,因此新状态成为回复的一部分,即使用户没有看到。

有了这个,让我们添加更多信息以查看匹配的 Intent 以及我们的 webhook 将执行的操作 - 无论是状态集还是发送的回复。

脚本 1:

User:  Talk to number or letter
Match: intent.welcome
Logic: Set replyState to "prompt"
       Pick a response for the current replyState ("prompt")
       and the intent that was matched ("intent.welcome")
Agent: Welcome! Would you like to hear a number or letter? 

User:  How about a number
Match: intent.number
Logic: Set replyState to "number"
       Pick a response for the current replyState ("number")
Agent: 1 is the loneliest number. Would you like another?

User:  Yes
Match: intent.yes
Logic: Pick a response for the current replyState ("number")
Agent: 2 is the only even prime. Care for another?

User:  No
Match: intent.no
Logic: Set replyState to "prompt"
       Pick a response for the current replyState ("prompt")
       and the intent that was matched (not "intent.welcome")
Agent: Ok, would you like to hear a number or letter?

有了这个,我们可以看到我们的回复是基于当前状态和用户意图的组合。 (我们的状态可能会更复杂,以跟踪用户听到了什么,他们访问了多少次等等。这是非常简化的。)

我们还看到 "yes" 没有改变状态。不需要。

如果我们查看脚本 2,我们会发现它的播放结果相同:

User:  Talk to number or letter
Match: intent.welcome
Logic: Set replyState to "prompt"
       Pick a response for the current replyState ("prompt")
       and the intent that was matched ("intent.welcome")
Agent: Welcome! Would you like to hear a number or a letter?

User:  Number, please
Match: intent.number
Logic: Set replyState to "number"
       Pick a response for the current replyState ("number")
Agent: 42 is the answer Another one, so to speak?

User:  sure
Match: intent.yes
Logic: Pick a response for the current replyState ("number")
Agent: 21 is blackjack. Care for another?

User:  nope
Match: intent.no
Logic: Set replyState to "prompt"
       Pick a response for the current replyState ("prompt")
       and the intent that was matched (not "intent.welcome")
Agent: Ok, care for a letter or a number?

事实上,如果您查看 "Match" 和 "Logic" 部分,就程序而言,它们是相同的对话。唯一的区别是用户使用的确切单词和我们回复的确切短语。从根本上说,它们是完全相同的对话。

这在脚本 3 中表现如何?

User:  Talk to number or letter
Match: intent.welcome
Logic: Set replyState to "prompt"
       Pick a response for the current replyState ("prompt")
       and the intent that was matched ("intent.welcome")
Agent: Howdy! Would you like a letter or a number?

User:  Let's go for a number
Match: intent.number
Logic: Set replyState to "number"
       Pick a response for the current replyState ("number")
Agent: A googol is 10 to the 100th power. Ready for another?

User:  How about a letter this time
Match: intent.letter
Logic: Set replyState to "letter"
       Pick a response for the current replyState ("letter")
Agent: The letter "A" is one of only two letters that are also words. Want another?

在这里,用户突然要求我们跳转到一个完全不同的状态。但这不是问题 - Dialogflow 只是看到了这一点,就像他们从提示问题中请求该状态一样,并且该处理程序的反应方式相同。

因此,我们不必构建许多后续意图,而是旨在捕获用户所说的内容,然后使用我们的 webhook 基于此更改状态。