Ethan
Ethan

Reputation: 45

is there a way to activate a dialogflow intent dynamically?

I wonder if there's a way to activate dinamically an intent, a sort of "it this condition is met, than goto intent XX". I try to explain what I'd like to do: when the user says a specific word, the intent looks up in the database what are the tasks to be done according to a priority algoritm. If for example task 1 is selected as topmost priority, then I should be able to activate "at runtime" task 1 intent, without asking the user to say "please say 001 to activate task 1" . Thanks in advance

Upvotes: 0

Views: 509

Answers (1)

jacobytes
jacobytes

Reputation: 3281

I've implemented your request for "if condition is met, got to X intent" in my webhook by moving my responses to different functions. In the case below, I want a different response and different output context based on an if condition. This way I can trigger different intents dynamically based on user input.

const game = SessionsService.getGame(userId);

if(game) {
  logger.info("Found a gamein progress..")
  const response = gameInProgress();
  conv.contexts.set("_defaultwelcomeintent-followup", 1);

  return conv.ask(response);
} else {
  logger.info("No game in progress found..")
  const response = welcome();
  conv.contexts.set("_introduction", 1);
  conv.contexts.set("_setup", 1);

  return conv.ask(response);
};

An example of a response function:

function gameInProgress() {

  const text = messages.gameInProgressText();
  const ssml = messages.gameInProgressSsml();

  const response = new BasicResponse(text, ssml);

  return response;
};

Instead of the boardService, you could implement your priority algorithm.

Upvotes: 1

Related Questions