Reputation: 2361
Working with the WhatsApp API I have a very simple Flask app running on 2 servers, the app just accepts a post request at the root address and prints what it received. On one host it is behind Traefik and on the other I run it directly so Flask's built-in development server is exposed directly. The first host is referenced as http://sub.domain.com/incoming/
and for the second I use an IP http://12.34.56.78
.
On the latter everything works as expected: I receive Twilio's callbacks, and I can call the API myself as well and get a clean response (HTTP 200, <Response></Response>
as body). On the former, if I call the API myself it works fine and I get the same output. But when Twilio sends its callbacks I consistently get a 11200 HTTP retrieval failure on Twilio's debugger.
I find this difference in behavior a little bit strange, but there is one more detail that I really find a bit bizarre - the Twilio debugger has an option to "Replay Request" in which case its callback gets re-sent. On the host where I get the retrieval failures, if I replay the failing requests they consistently succeed!
On the server where everything is working, I have stored a raw Twilio request (HTTP with headers etc), and I've tried sending this request to the failing server manually using netcat (after updating the Host header field). When I do this the server responds without any issues so the structure of the request does not seem to be the problem.
I am really at a loss, I've run out of ideas regarding where I can look for the cause of this issue. Any suggestions what could be going on?
Upvotes: 0
Views: 328
Reputation: 3889
Heyooo. Twilio Developer Evangelist here. đź‘‹
For completeness: Twilio doesn’t accept underscores in the domain or subdomain for the webhook URL “when a message comes in” for SMS sent to your Twilio number. If you try to save the phone number configuration page with an underscore in the domain or subdomain of the URL, you’ll see an error in console “URL is not valid”.
However, the configuration for the webhook for Twilio Whatsapp has a bug and doesn’t reject the URL, even though it’s invalid for Twilio! So although the URL is accepted, the requests will fail.
We created a ticket for it and the engineering team is now aware of this issue.
Thank you for raising this issue. :)
Upvotes: 1
Reputation: 2361
After some back and forth with Twilio's developer support it seems this was a problem on their end. The issue was that the subdomain part of my URL contained an underscore. For some reason Twilio's webhook system does not accept this, even though their "Replay Request" functionality has no issues with it (seems like those go through different subsystems). I've fixed the issue by replacing the underscore by a dash, everything works as expected now.
Upvotes: 1