Bibek
Bibek

Reputation: 784

How to reach back to previous intent in dialogflow from current intent?

I have been doing a project on dialogflow. I am building a chatbot where user is required to insert a series of information and at last the informations are sent to webhook. I have been building a series of followup intent for that purpose. AS like

User Name intent (Main intent)

Phone number intent ( follow up intent for username, appears after user inserts username)

I want to do is change username after receiving username and reaching phone number follow up.

For intance:

Bot: Hello Insert your username. User: David Bot: You entered david as your name. type -1 to change your name. Enter your phone number. user:-1 Bot:Hello Insert your username (Reaches to same intent)

I need a proper solution for solving it. I tried with previous selection on followup but couldn't get solution.

Thank you in advance.

Upvotes: 1

Views: 3160

Answers (1)

havokles
havokles

Reputation: 316

Add an event to your enter-name intent so you can call upon it from a fulfillment function if the user typed -1.

Enable webhook call for your followup intent where you prompt the user for a phone number. and in your fulfillment function do something like:

function getPhone(agent) {
   const phoneNumber = agent.parameters.phonenumber;
   if (phoneNumber == -1) {
      agent.add(`Okey, going back`); // This won't print as the followup intent will trigger instanty but you still need to add a response to your agent.
      return agent.setFollowupEvent('change_username');
   } else {
      return agent.add(`You entered ${phoneNumber} as your phone number.`); 
   }
}

let intentMap = new Map();
intentMap.set('enter-phonenumber', getPhone); // where 'enter-phonenumber' is the name of your intent which gathers phonenumbers
agent.handleRequest(intentMap);

enter image description here

Enable webhook with: https://cloud.google.com/dialogflow/docs/tutorials/build-an-agent/create-fulfillment-using-webhook


You would probably want to look at something like this otherwise: https://www.youtube.com/watch?v=xxSa9g3ripQ

Where you simply move on and gather the required information and have an intent with an active context ready if the user suddenly types by the way, my name is Eric and catch that in there instead.

Upvotes: 3

Related Questions