Reputation: 7216
I have an intent that needs a user's phone number in order to search an API, it's basically an intent with a required "phoneNumber" parameter and a webhook for fulfillment. Everything works fine in the best case scenario, but sometimes the user pronounces their number wrong and we don't find any results.
How can I make it so that the intent says something like, "I wasn't able to find anything with that number, can you please repeat it?" or "I wasn't able to search using your number, can you please tell me your name?". Basically, I'd need to keep the user in a loop until we get all the information we need.
I've been playing around with contexts and follow-up intents but they don't seem to work.
Upvotes: 1
Views: 446
Reputation: 50741
Followup Intents are not what you want in this case. They are probably not what you want in most cases.
Contexts can help but may not even be necessary.
Most of all, remember that an Intent captures what the user has said, and not what you are going to do with what they've said or how you reply.
So the simplest answer to how you tell them that you don't have any results is... that your webhook execute code that says there are no results instead of the code that says what the results are.
If the user responds with a phone number, than the Intent you already have created to capture the phone number should be called again.
There are some examples about doing this in this StackOverflow answer, as well as this medium article which was based on the answer and the followup article which shows some details about the Intents.
Now, there are cases where working with a context might make sense. For example, you may wish to use a context to keep count of how many times in a row the Intent has been called since, after a while, it may be safest to stop the conversation or prompt in a different way. You can do this by setting a value in a parameter of the Context and checking or increasing this parameter.
Or it may make sense to use a context to help make sure that the input is treated as a phone number at this specific point in the conversation and not something more arbitrary. You could do this by setting the Input Context for Intents.
Upvotes: 2