首页 > 解决方案 > 后续意图未触发 intentMap.set 中的处理程序方法 - Dialogflow

问题描述

我有几个嵌套的后续意图,如下所示:

在此处输入图像描述

然后在履行功能的代码中,我有这个数字 70 正在触发giveChoice但其余的没有被触发。为什么?如何使用后续意图执行此操作?

let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);
  //Intent - 70
  intentMap.set('0068 - Intents - 70', giveChoice);
  intentMap.set('0068 - Intents - 70 - no', giveFirstNextQuestion);
  intentMap.set('0068 - Intents - 70 - no - no', giveSecondNextQuestion);
  intentMap.set('0068 - Intents - 70 - no - no - no', giveThirdNextQuestion);
  // intentMap.set('your intent name here', googleAssistantHandler);
  agent.handleRequest(intentMap);

标签: google-cloud-platformdialogflow-esdialogflow-es-fulfillment

解决方案


我设法重现您的问题并解决了它。我将总结以下几点:

  1. 为您要使用的所有意图和后续意图启用此意图的 webhook 调用(在履行部分中)。

  2. 您创建的要使用的函数“giveChoice”、“giveFirstNextQuestion”...应遵循以下结构:

  function givechoice(agent){
    agent.add(`Would you like this response to be recorded?`);
    agent.setContext({
      name: 'first-call',
      lifespan: 2,
    });
  }

  function afirmative(agent){
    agent.getContext('first-call');
    agent.add(`Thank you for accepting`);
  }
  1. 请注意,在上述情况下,我只做一个后续意图。例如,如果你做第三个,那么第二个函数必须有一个 getContext 和一个 setContext 才能正常工作。

  2. 最后一部分和你做的完全一样。就我而言:

  let intentMap = new Map();
  intentMap.set('0068 - Intents - 70',givechoice);
  intentMap.set('0068 - Intents - 70 - yes',afirmative);
  agent.handleRequest(intentMap);

推荐阅读