Home / API.AI / DialogFlow (API.AI) Push Notifications
API.AI

DialogFlow (API.AI) Push Notifications

This website contains affiliate links. See the disclosure page for more details. 

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 🙂

Live Webinar

The recently released Zoho SalesIQ v2 allows non-programmers to build chatbots using an easy-to-use code less bot builder. What is really unique about Zoho SalesIQ is the fact that you can also integrate AI into their code less bot builder. In my Zoho SalesIQ chatbots course, I explain how to use Zoho SalesIQ to add a chatbot to your website.

"The magic key I needed as a non-programmer"

The custom payload generator was the magic key I needed (as a non-programmer) to build a good demo with rich responses in DialogFlow Messenger. I've only used it for 30 minutes and am thrilled. I've spent hours trying to figure out some of the intricacies of DialogFlow on my own. Over and over, I kept coming back to Aravind's tutorials available on-line. I trust the other functionalities I learn to use in the app will save me additional time and heartburn.

- Kathleen R
Cofounder, gathrHealth

Similar Posts