Ashrith
Ashrith

Reputation: 39

How to loop back to a previous intent depending on users input?

I have an intent which asks a yes/no question. If the users say "no", they are taken through a series of questions, the last of which is again a yes/no question. On answering "No", I want the loop to start again. I already tried the solution provided here, it didn't work.

Upvotes: 4

Views: 1901

Answers (1)

dedman
dedman

Reputation: 908

The context trick given on that link should work, you just have to handle the contexts and responses correctly, consider the below example series of intents

- intent that asks yes/no question (say 'question X')    <--[set the output context (say 'loop-back')]
|
|--- intent that accepts 'no' as user input    <--[set 'loop-back' context as input context for this]
   |
   |--- chain of questions...
      |
      |--- last yes/no question
         |
         |--- intent that accepts 'no' as user input    <--[set the output context 'loop-back']
              [response from agent should be the same yes/no question 'questionX']
            |
            |--- [if user replies 'no' the loop continues...]

Make sure to set the lifespan of context 'loop-back' properly (may be 1/2) so it doesn't get stored for much longer.

Here we start from 'questionX' and at the last intent give response as 'questionX'. Actually the starting (yes/no questionX) intent is never fired again but the intent after that which accepts 'no' gets fired due to contexts, which creates proper loop :)


See if this example helps,

- [start intent fires]
  {intent A}
  Agent("are you afraid to talk to me ?")    <--[set the output context (say 'loop-back')]
|
|{intent B}
|--- User("no")
     Agent("What are you afraid of then ?")    <--[set 'loop-back' context as input context for this]
   |
   |{intent C}
   |--- User("nothing")
        Agent("more questions")
      |
      |{intent D}
      |--- User("more answers")
           Agent("are you afraid to talk to daemons ?")
         |
         |{intent E}
         |--- User("no")
              Agent("and are you afraid to talk to me ?")    <--[set the output context 'loop-back']
            |
            |{intent B}
            |--- User("no")
                 Agent("What are you afraid of then ?")
                 [and the loop continues...]

Have look at the two [set output context] (intent A & E) lines, both have same Agent response which creates a loop...

Upvotes: 2

Related Questions