12

I'm starting with Messenger Platform API. I want to make simple Messenger Chatbot. Here is tutorial I follow.

As you see, to start I need to set up webhook (step 2). So basically: web server that provides some REST API and posts some data back. The problem is: facebook requires me to provide some real, existing app URL that works currently in internet. So, do I need to upload my code to server each time I change something? Can I somehow test it locally (on my localhost)? How can I test behavior of my bot?

Piotrek
  • 10,919
  • 18
  • 73
  • 136
  • How would Facebook be able to ping your server that is offline? – WizKid Apr 18 '16 at 16:11
  • There is similar question, so you can find answer here: http://stackoverflow.com/questions/36674079/how-to-do-facebook-messenger-bot-development-locally – fritak Apr 18 '16 at 16:14
  • @WizKid It's not necessary for facebook to connect it by itself. I was thinking about some kind of emulator or fake, localhosted instance that would be available just for testing. – Piotrek Apr 18 '16 at 16:36

5 Answers5

29

There's a few services you can use to expose your webserver running on localhost to the public. Two options are localtunnel and ngrok.

An example (from localtunnel's quickstart) of how you might do this, given that your webserver is running at http://localhost:8000/ would look like this:

Install localtunnel from npm:

npm install -g localtunnel

Request a tunnel to your local server:

lt --port 8000

This will generate a link, of the form https://foo.localtunnel.me you can use to access your localhost from the web. One nice feature is that you automatically get https so Facebook won't give you a 'SSL certificate problem' error. Localtunnel or ngrok are also nice for sharing work running locally with others.

Note that the localtunnel url is only valid as long as the connection lives, so you will have to update the url Facebook has if the connection ends.

mguida
  • 858
  • 1
  • 10
  • 19
16

I created a library that tries to solve this exact problem! With fb-local-chat-bot you can easily test your bot offline. The library also makes testing much more simple. If you're interested, definitely check it out

https://github.com/spchuang/fb-local-chat-bot

Demo:

spchuang
  • 405
  • 6
  • 11
3

you may use ngrok to test the messenger bot in localhost. You may download it at: https://ngrok.com/download

on executing ngrok, it will generate secure link that can be used as a end point in webhook.

You can also check the detailed status of each request and response of ngrok through

http://localhost:4040/inspect/http

Later, once you are done, you may deploy your code to secure server.

You can find more info as to how to build a basic chat bot on the link below:

How to build a basic chat bot on facebook messenger

Sravan
  • 1,959
  • 2
  • 11
  • 16
1

You can deploy your backend services on heroku free of cost. It provide public DNS with RSA.

user3671657
  • 37
  • 1
  • 8
  • 7
    His main concern is not related to hosting but to upload the code whenever he makes any change to it. This consumes a lot of time while you make small changes which needs to be tested. – Aditya Chawla Nov 11 '16 at 16:00
0

If you can't use ngrok for some reason (like routing webhook to multiples dev machines). please try this emulator i have created for developing / debugging webhooks locally. this provides emulation of send api and a messenger ui

I have created an emulator for send api and messenger which i use for debugging web hooks locally

https://github.com/SonOfSardaar/facebook-send-api-emulator

I also came across this (i have not tried this one yet but looks good)

https://learn.microsoft.com/en-us/bot-framework/debug-bots-emulator

Gurpreet
  • 1,382
  • 11
  • 24