代码之家  ›  专栏  ›  技术社区  ›  Stormsson

来自webhook的dialogflow触发器事件

  •  1
  • Stormsson  · 技术社区  · 7 年前

    我有一个带有动作x的intent I1和一个调用webhook的intent I2。

    有没有办法从i2webhook响应触发x,以便在webhook给出答案后将用户“重定向”到I1?

    编辑: 增加了进一步澄清的图表。

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  10
  •   Prisoner    7 年前

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

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

    根据你的图表。

    你的图表说明了为什么我们鼓励人们思考

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

    从中可以学到几点:

    • 在真实的对话中,用户可以从任何方向进行对话。因此,尽管我们问了一个“是”或“否”的问题,但他们可能会试图将谈话转向一个完全不同的方向。
      1. 我们当时处于什么状态
    • 上面第(1)点的一个结果是,我们应该跟踪用户的状态,以确定我们所说的内容,因此新状态成为回复的一部分,即使用户看不到。

    有了这些,让我们添加更多的信息,看看什么意图会得到匹配,然后我们的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根据这些内容更改状态。

    推荐文章