来自webhook的dialogflow触发事件

时间:2018-10-05 20:29:25

标签: dialogflow actions-on-google

我有一个具有动作x的意图I1和一个称为Webhook的意图I2。

是否有一种方法可以从I2 Webhook响应中触发x,以便在Webhook给出答案后将用户“重定向”到I1?

从dialogflow控制台可以做到这一点吗?

编辑: 添加了图表以进一步阐明。 处理“否”后续部分的正确方法是什么?

enter image description here

1 个答案:

答案 0 :(得分:7)

意图表示用户的输入(通常是他们说的话),而不是您在“做什么”。

尽管您可以从Webhook(例如您的I2处理程序)重定向到事件(可能由I1接收),但是您不能在Webhook回复之后“进行”操作。这将替代webhook的结果。 (而且,虽然可能,但通常不是解决问题的最佳方法。)

您也无法从Dialogflow配置中执行此操作。它必须通过网络挂接完成。

根据您的图表

更新

您的图表说明了为什么我们鼓励人们考虑对话,以及用户说什么而不是“我们做什么”。会话图与流程图并不完全相同。让我将其重组为一些脚本(稍后将进行注释)。

脚本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?

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

我们还看到“是”不会改变状态。不需要。

如果我们看一下脚本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?

实际上,如果您查看“匹配”和“逻辑”部分,就程序而言,它们是相同的对话。唯一的区别是用户使用的确切单词和我们答复的确切短语。从根本上讲,它们是完全相同的对话。

这在脚本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来基于此更改状态。