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

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 🙂

<— End of article —>

This website contains affiliate links. See the disclosure page for more details. 
"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
"Much clearer than the official documentation to be honest"

Thanks a lot for the advice (of buying and following your videos)! They helped a lot indeed. Everything is very clear when you explain, much clearer than the official documentation to be honest 🙂

Neuraz T
Review for Learn Dialogflow CX
"I will strongly recommend this course because even I can learn how to design chatbot (no programming background)"

I think Aravind really did a great job to introduce dialogflow to people like me, without programming background. He organizes his course in very clear manner since I have been a college professor for 20 years. It is very easy for me to recognize how great Aravind’s course is! Very use-friend and very easy to follow. He doesn’t have any strong accent when he gives the lectures. It is so easy for me to understand. Really appreciate it.

Yes, I will strongly recommend this course because even I can learn how to design chatbot (no programming background) after studying Avarind’s course, you definitely can!

Ann Cai
Review for Learn Dialogflow ES

Similar Posts