JS_Diver
JS_Diver

Reputation: 786

A follow-up intent not firing a handler method in intentMap.set - Dialogflow

I have an intent with several nested follow-up intents like this:

enter image description here

And then in the code of the fulfillment function I have this where the number 70 is firing the giveChoice but the rest is not fired. Why? How do I do this with followup intents?

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);

Upvotes: 0

Views: 272

Answers (1)

aemon4
aemon4

Reputation: 1102

I managed to recreate your issue and solve it. I will summarize the points to follow:

  1. Enable webhook call for this intent (in the fulfillment section) for all the intents and follow-up intents you want to use.

  2. The functions you create to use, "giveChoice", "giveFirstNextQuestion",... should follow the structure:

  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. Pay attention that in the case above I only do one follow-up intent. If you do a third, for instance, then the second function has to have a getContext and a setContext to work properly.

  2. The final part is exactly as you did it. In my case:

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

Upvotes: 1

Related Questions