tawn33y / whatsapp-cloud-api

A Node.js library for creating bots and sending/receiving messages using the Whatsapp Cloud API.
https://www.npmjs.com/package/whatsapp-cloud-api
GNU General Public License v3.0
189 stars 51 forks source link

Not able to connect to webhook #19

Closed leonardodma closed 2 years ago

leonardodma commented 2 years ago

I followed all the steps in the tutorial section and I was able to send messages, but my webhook endpoint was not verified. I've tried many ways, and the only way that works is using Glitch, as recommended in the API documentation. Do you know any solution that could solve my issue?

tawn33y commented 2 years ago

Hi @leonardodma,

Two quick questions:

  1. Which version of the library are you using? Version 0.2.0 had some issues in verifying the webhook but this was resolved in version 0.2.1 and 0.2.5.
  2. Can you paste the full error you are getting? e.g. screenshots for the terminal, ngrok (if you're tried using this), etc. I personally haven't used Glitch but if you could share any error messages you are getting, that would be great!
leonardodma commented 2 years ago

Hello @tawn33y, thank you for answering so fast!

I'm using the 0.2.5 version of the library and Ngrok 3.0.6.

The server starts running on port 3000 and sends the "hello world" message, just like in the tutorial. Then, I run ngrok HTTP 3000 and it returns a forwarding URL such as https://xxxx-xxxx-xxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx.sa.ngrok.io. When I try to edit the webhook callbacks' URL, adding /webhook/whatsapp to the end of Ngrok's URL, it returns that it wasn't possible to complete, and the "Webhook Verified" log does not appear in the terminal.

tawn33y commented 2 years ago
leonardodma commented 2 years ago

It does appear "🚀 Server running on port 3000...". In my browser accessing my Ngrok's URL, GET / returns 404 Not Found, while GET /webhook/whatsapp returns 403 Forbidden.

tawn33y commented 2 years ago

This shows that it's running fully OK locally, and ngrok is working as well.

Can you share the url you're providing in the App dashboard? I hope it's something like https://xxx.ngrok.io/webhook/whatsapp

leonardodma commented 2 years ago

It is a little bit different (probably because of the Ngrok version): https://d0f2-2804-431-cff6-9331-241a-5639-ede4-a314.sa.ngrok.io. Anyway, I've tried to use Local Tunnel and it didn't work either.

tawn33y commented 2 years ago

Ah, seems like there is a new feature that ngrok has introduced to show a browser warning on visiting each page, requiring a user to confirm "Visit page" before loading the page: https://blog.ngrok.com/posts/fighting-abuse-on-the-ngrok-platform

I think what's happening is that Facebook is trying to hit your ngrok endpoint and gets served by html content requiring confirmation, which obviously means that Facebook will fail to verify your webhook.

I wasn't aware that ngrok introduced this. I'm personally using ngrok version 3.0.4 and it doesn't have this feature. Perhaps you can try downloading an earlier version instead? You can use docker: https://hub.docker.com/r/ngrok/ngrok

Something like: eg:

docker run -it ngrok/ngrok:3.0.3-debian http 3000

And then try to verify the webhook.

Curious to see if this works.

leonardodma commented 2 years ago

I think you got it! Make totally sense! I will try to run with the 3.0.4 version!

I tried to run docker run -it ngrok/ngrok:3.0.3-debian http 3000 but I got the following log (despite server is still running):

image

tawn33y commented 2 years ago

How about this:

docker run --net=host -it ngrok/ngrok:3.0.3-debian http 3000 
leonardodma commented 2 years ago

Running the following command, I was able to connect to the port, but the verification is still happening :(

docker run --net=host -it -e NGROK_AUTHTOKEN=[NGROK_TOKEN] ngrok/ngrok:3.0.3-debian http 3000
tawn33y commented 2 years ago

What url are you getting now? Can you share? Need to confirm if I'm seeing the "Verify site" browser warning page.

Also, what error are you getting now?

leonardodma commented 2 years ago

I'm getting this URL: https://7052-187-34-95-187.sa.ngrok.io. It returned the confirmation page firstly, but then got the same error failed to establish a connection to the upstream web service at [localhost:3000](http://localhost:3000/)

tawn33y commented 2 years ago

Quick question: can you try running this without supplying the auth token?

leonardodma commented 2 years ago

Sure! https://7652-187-34-95-187.sa.ngrok.io

tawn33y commented 2 years ago

I'm starting to feel that this might be quicker via a call. Feel free to send a calendar invite for tomorrow. I will respond accordingly if the time doesn't work for me.

tawn33y commented 2 years ago

Proposed Solutions

(for future reference) There are 4 solutions off the top of my mind for fixing this:

Using an older version of ngrok

Running ngrok via downloaded zip

Running ngrok via docker

Seems a person may need to pay for ngrok or localtunnel for now; at least until Facebook allows the use of custom headers in requests. Any other solutions are most welcome. Will mark this as closed for now.

guskuma commented 2 years ago

Hi there! I had no success trying with older version of ngrok (tried 3.0.1) and with ngrok alternatives that doesn't show 'verification page' (pagekite and localtonet). In both alternatives I was able to successfuly browse my local instance without verification page, but when trying to set this as my webhook in FB developers page my instance got untouched and, obviously, I could not set it as my webhook addres. This might be some FB thing. It's a shame I have to deploy my app to be able to test...

TGw44 commented 2 years ago

could you solve this ? @guskuma

guskuma commented 2 years ago

Hey @TGw44 I had no luck yet. Next weeks I'll try again and I'll let you know if it works.

TGw44 commented 2 years ago

I have good news @guskuma , i made it work without ngrok!

I used Heroku instead.

Here is great video step by step. https://www.youtube.com/watch?v=HY7Px7wWfq4

Note: i had to change startExpressServer.js line 100

const port = (options === null || options === void 0 ? void 0 : options.port) || 3000; to const port = (options === null || options === void 0 ? void 0 : options.port) || process.env.PORT || 3000;

Maybe we can add this alternative in the TUTORIAL @tawn33y

tawn33y commented 2 years ago

Sure thing, I'll create an issue for this for tracking

ernsk commented 1 year ago

Hello everyone, i have read all comments in this issue and i thought finally i found a solution for webhook with using heroku. But when i check the heroku page i see there is no free option anymore. So is there any progress about this situation? How we going to verify?

ernsk commented 1 year ago

Ok guys, we can use telebit.io instead of other tunnels. It's works now

AlexGonzalezInf commented 1 year ago

@ernsk How did u achive with telebit.io, im only watching the reverse form, from a page to a locahost Can u give me any advise

shirser121 commented 1 year ago

I success to do it with loophole.cloud