Oracle Cloud Infrastructure Documentation

C Navigation with keepTurn and transition

Use different combinations of the keepTurn and transition functions to define how the conversation continues once the component has finished processing.
invoke: (conversation, done) ==> {
   ...
   conversation.keepTurn(true);
   conversation.transition ("success"); 
   done();
    }
Use Case Values Set for keepTurn and transition

A custom component’s reply that doesn’t require any user interaction.

  • Set keepTurn to true: conversation.keepTurn(true).

  • Set transition with a supportedActions string(conversation.transition("success")) or with no arguments (conversation.transition()).

For example, a custom component updates a context variable with a list of values that is then displayed by a System.List component that’s defined for the next state in the dialog flow definition.
invoke: (conversation, done) => {
    const listVariableName = conversation.properties().variableName;
  ...
 
  //
write list of options to a context variable 
   conversation.variable(listVariableName, list);

   //navigate to next state. No user interaction.
   conversation.keepTurn(true);
   conversation.transition();
   done();
 }
When component doesn’t transition to the next state, it needs to track its own state by creating a runtime variable using the conversation.variable (“name”, variable) method.
A sequential user conversation in which the user provides input, the bot replies, and so on.
  • Set keepTurn to false.

  • Set transition with a supportActions string

For example:
conversation.keepTurn(false);
conversation.transition("success");
The bot to passes control back to the user without navigating to the next dialog state. This allows the component to process the user input. Here are a couple of examples:
  • A component passes the user input to query a backend search engine. If the chatbot can only accommodate a single result, but the query instead returns multiple hits, the component can then prompt the user more input to filter the results. In this case, the custom component continues to handle the user input; it holds the conversation until the search engine returns a single hit. When the backend system is satisfied, the component calls conversation.transition() to move on to the next state as defined in the dialog flow definition.

  • A questionnaire, wherein a custom component handles all of the questions and only transitions to the next state when each of them gets answered.

  • Do not call transition.

  • Set keepTurn to false.

For example:
conversation.reply("text");
conversation.keepTurn(false);
done();

The custom component goes into a loop, which can’t be stopped by user input. For example, a component pings a remote service for the status of an order until the status is returned as accepted or when the component times out. If the accepted status is not returned after the fifth ping, then the component transitions to a failedOrder state, which is defined in the dialog flow.
  • Do not call transition.

  • Set keepTurn to true: conversation.keepTurn(true).

For example:
conversation.reply("text");
conversation.keepTurn(true);
done();
Always call keepTurn after reply and not before, because reply implicitly sets keepTurn to false.