1. 程式人生 > >How to use Context with Dialogflow to handle errors (Part 2: Knock Knock, It’s me)

How to use Context with Dialogflow to handle errors (Part 2: Knock Knock, It’s me)

How to use Contextual Fallback with Dialogflow to handle errors (Part 2: Knock Knock Jokes)

(This is Part 2 of a four-part series on how to use Context with Knock Knock jokes. You can find Part 1 here.)

In Part 1, I demonstrated how you can use Context in Dialogflow to build a simple Knock Knock joke. In Part 2, I will show you how to handle unexpected responses using contextual fallback.

Situation: User does not reply “Who’s There”

Some people will mistype. Other jokers may want to mess with your bot and not respond correctly.

So how do we deal with this?

  1. To trigger a prompt to say “who’s there”, create a fallback intent.

Top 3 Bot Tutorials

2. Add input context “knockknock”.

This means that this fallback will only be triggered if the bot does not understand the response AND

the user is within the context of a knock knock joke.

3. Add output context = knockknock with lifespan of 1. This maintains the context of the knock knock joke and is a necessary condition to trigger the “Who’s There” intent, if the user replies “who’s there” after being prompted.

4. Add your response.

As you can see from the image below, we need to have output context in order for the “who’s there” intent to trigger a response.

If I remove the output context, the knock knock context is lost, and “who’s there” will trigger the default Fallback.

Do note that this will only work for responses that the bot does not understand. If you say something that the bot is trained to answer (e.g. “hi”), it will trigger that intent instead. This is important as it allows the user to exit the flow of the knock knock joke whenever he wants.

Only when the bot does not understand will it trigger the contextual fallback instead of your default fallback.

In the next tutorial

In Part 3 of this Tutorial, we will cover situations where users try to be clever and spoil your punchline! Here’s a sneak peak!

You can find Part 3 here.

Download the Dialogflow agent

You can download the Dialogflow agent here!

Other Tutorials In this Series