April 7, 2022

Chatbot's Diary: Webhooks on Localhost

Chatbot's Diary: Webhooks on Localhost

There was one thing that always annoyed me when developing chatbots. It was webhooks. Messengers like Facebook, Viber or us (Amio) intent to push messages to your endpoint. However, the messengers can't reach your app when you specify the webhook URL as localhost.


Of course, you can test your code on a remote machine. But you have to deploy the app to an internet facing server every time you make a change in the code. That's very time-consuming, especially when you only make a tiny change. Fortunately, there is a way how to let others reach your local machine.

Localhost tunneling

To test webhooks on the local machine, you need to tunnel localhost so that it gets a public URL. You can do it by yourself but it ain't that simple. With my favorite tools ngrok or localtunnel (I use just as a backup) you're ready in a minute and you can start receiving the events.


Ngrok setup

  1. Run your app on a port of your choice, for example 8080.
  2. Setup ngrok.
  3. In command line, execute ngrok http 8080. Ngrok will create a public facing url and tunnel it to your localhost. You'll see a similar screen:


Time to test

After configuring the localhost tunneling, you surely want to try it out. The simplest way is to open your browser and paste the tunneled URL (http://529081d6.ngrok.io in our case). Then go to ngrok web interface and observe what happened. The best thing for development is that you can explore the content of a request. You'll probably see a similar picture:



You've just made your programming life simpler. If you're developing a chatbot or a messaging app, Amio will speed up your project. Give it a try! It's free.

Happy coding! ;-)

Honza Donátek
Honza Donátek