DialogFlow (API.AI) Push Notifications

What should I do when my DialogFlow webhook takes too long (more than 5 seconds) to respond?

I have seen this question on the DialogFlow forum appear in a few different forms. Ultimately, this is the goal:

You want to send an unprompted, “out-of-band” message to the end user from your DialogFlow webhook

What is an “out-of-band” message?

One example is a webhook which takes too long to respond. You want to send a quick “OK, working on it…” type response. And then you want to do some kind of async processing, and then send a message back to the end user when the results are available.

Another example is where you are trying to send a “reminder” to the user. For example, you wish to remind a user on FB Messenger about an alarm they set on your service using your DialogFlow agent.

Push notifications don’t work

As it turns out, such “push” notifications are not possible in DialogFlow. What I mean by a push notification is:

DialogFlow figures out, based on the sessionID, what channel is being used (web, FB, Slack etc), and when a message is “generated” programmatically (say by sending a request to the /query endpoint), DialogFlow will take the responsibility to deliver the message to the appropriate channel.

The Request-Response mechanism

So this means everything in DialogFlow follows a “Request-Response” mechanism. For example, notice this comment (I think this is the best comment about this problem I have seen):

What about sending a message to the user when a web chat loads

Maybe you are wondering how I have created bots which interact before the user sends a message. Isn’t this like a push notification?

But even here, I do honor the “request-response” mechanism. That is, my website chatbot has some backend code which first makes a request to the REST API, gets the response, and then renders a suitable message in the chat window based on the response.

How to handle this scenario?

So now that we understand the limitation, we can think of ways to mitigate the problem. I will recap what I wrote in my comment on a related thread:

If your webhook cannot send the info back in 5 seconds, you should

  1. Either redesign the code so it can send the response in 5 seconds
  2. Or Use the repeated followupEvent approach suggested here: Fulfilment using webhook – takes time to get the data by @prabhasgupte
  3. Or use the callback URL approach suggested here: Fulfilment using webhook – takes time to get the data and here: Fulfilment using webhook – takes time to get the data by @Michael_Natkin
  4. or choose another bot building framework which doesn’t impose this onerous constraint 🙂

About this website

BotFlo1 was created by Aravind Mohanoor as a website which provided training and tools for non-programmers who were2 building Dialogflow chatbots.

This website has now expanded into other topics in Natural Language Processing, including the recent Large Language Models (GPT etc.) with a special focus on helping non-programmers identify and use the right tool for their specific NLP task.

1 BotFlo was previously called MiningBusinessData. That is why you see that name in many videos

2 And still are building Dialogflow chatbots. Dialogflow ES first evolved into Dialogflow CX, and Dialogflow CX itself evolved to add Generative AI features in mid-2023