Search code examples
dialogflow-es

Google dialogflow how use dynamic response strings?


I'm trying to make a simple dialogflow conversation. I have made a simple conversation to ask a person who they are trying to call and then says if a person is available / unavailable, which is just a text reply. When a person is unavailable I have potentially 3 actions the user can do, leave a voicemail, redirect to a colleague or wait until the person is available.

The message I would return is

"I'm sorry nameOfPerson is not available, would you like to leave a voicemail message, redirect to a colleague or wait until nameOfPerson is available?"

Which works, but how can I make it so that lets say there is no voicemail the intent only response with, "I'm sorry nameOfPerson is not available, would you like to redirect to a colleague or wait until nameOfPerson is available?"

Currently the only way I see to fix this is making 7 intents with all different contexts like:

Intent1: voicemailContext
Intent2: redirectContext
Intent3: voicemailContext, redirectContext
Intent4: waitingContext
Intent5: WaitingContext, redirectContext
Intent6: waitingContext, voicemailContext
intent7: waitingContext,redirectContext, voicemailContext

All that work for just a small adjustment seems way to complicated. Also currently I'm sending those options in a call which I would much rather not since people could also just say those options and get a match


Solution

  • Dialogflow is very poor at handling logic. You can sorta do it, as you've seen, but this does lead to overly complicated models. One thing to remember that might help with this is that Intents are good at modeling what the user says, but that you're still responsible for what you do with that.

    Better in many cases is to put the logic in a fulfillment webhook. This lets your code determine what the best response is and send that response. Depending how you want to structure your replies, you have a few other options:

    • You can send a context back in the reply. This would limit which Intents can get triggered when the user replies.
    • Another approach is to only have one Intent for the reply, but to use Entities to represent what sorts of things they can do. Then have your fulfillment, again, determine if they have given you a valid or invalid reply and respond accordingly.