Ngrok also provides a neat web interface at 127.0.0.1:4040 to look at all the requests that are coming in! This should open up a terminal panel that looks like this. Ngrok gives web accessible URLs and tunnels all traffic from that URL to our localhost! Easy, peasy! Go to Ngrok's download page, download the zip file, unzip and simply run the command. Also, Facebook requires the endpoint to run over https! Ngrok to the rescue!įor development purposes, we will use Ngrok that sets up secure tunnels to our localhost i.e. Since we are working locally, Facebook cannot reach us. However, Facebook can only access web URLs. Next, we have to tell Facebook about our webhook and specify the URL. ![]() Now when you go to the following URL, you should see "Hello World!". To ensure everything is working well, update our views.py file to look like this # yomamabot/fb_yomamabot/views.pyįrom import HttpResponse ![]() Lets define our webhook URL in urls.py file and create a view to handle it # yomamabot/fb_yomamabot/urls.py Generate a long random sequence for our url. Keep in mind that we want this URL to be secret, unless you want intruders to know where we hook up! Later, we can write code to handle these incoming requests. The first part is to decide exactly "where" our app and Facebook should "hook up"! Lets create a URL and tell Facebook about it so it can send updates there. whenever someone sends our page a message. In this case, Facebook provides our app with real-time information i.e. "A webhook is a way for an app to provide other applications with real-time information". Webhook - time for your app and Facebook to hook up! # yomamabot/fb_yomamabot/urls.pyįrom import include, urlģ. So lets create a urls.py file in our fb_yomamabot app directory and leave it empty for now. This means, when a request like 127.0.0.1:8000/fb_yomamabot/ comes to the server, it strips away 127.0.0.1:8000/fb_yomamabot/ and forwards to the urls.py file in the fb_yomamabot app directory to handle it. Url(r'^fb_yomamabot/', include('fb_yomamabot.urls')), # yomamabot/yomamabot/urls.pyįrom import url, include Go to the settings.py file and add this app by appending the app name 'fb_yomamabot' into the INSTALLED_APPS variable. This must now create an app in the project directory with the relevant files. So lets create an app for our Facebook messenger bot by running $ django-admin.py startapp fb_yomamabot Django projects are made up of small apps that perform specific functions. ![]() Go to the URL and you must see the "It worked!" page. Now you must have your django server running at 127.0.0.1:8000. Lets create a new virtual environment, install Django, create a new project and run the development server. This can be replaced by any other framework. This tutorial shows you how to use Django as the backend server.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |