Yoctol/bottender

Dialogflow x Twilio Too Many Requests Error

preetjdp opened this issue · 1 comments

Describe the bug
Sending multiple responses from Dialogflow causes an error. It sends a 429 TOO MANY REQUESTS Error.

Error

Response -
  429 TOO MANY REQUESTS

Response Data -
  {
    "code": 20429,
    "message": "Too Many Requests",
    "more_info": "https://www.twilio.com/docs/errors/20429",
    "status": 429
  }

To Reproduce
Steps to reproduce the behavior:

  1. Send Multiple Responses From Dialogflow

Expected behavior
The Expected Behaviour would be that the multiple responses from Dialogflow get sent to the client app.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional Context
I'm using the Free Tier of Twilio.

Possible Solution
Did a bit of digging the problem seems to be the way Promise.all() works.
It's calling all the context.sendText functions at once and causing that's causing the crash.

The solution that I had to implement is to use for await .. of

for await (let fulfillment of fulfillments) {
   await context.sendText(fulfillment)
}

Mozilla Explainer on For Await ..of

Hi, you may want to try the new released @bottender/dialogflow - v1.4.11
https://github.com/Yoctol/bottender/releases/tag/v1.4.11