This is a Python Api.ai webhook. More info could be found here: Api.ai Webhook
This service communicate with an Api.ai agent related to Jarvis. The service packs the result in the Api.ai webhook-compatible response JSON and returns it to Api.ai.
This webhook is automatically deployed on Heroku when pushing to master
.
To test a feature before deploying it, here's how to do:
-
Create a new Api.ai agent and import the content from the production-ready one.
-
Install ngrok on your machine.
-
Run
ngrok
. It will create a tunnel from your localhost to a specific IP address../ngrok http 5000
-
Link your Api.ai agent to your specific IP. Go to the "Fulfillment" tab on the Api.ai interface and copy your IP + "/webhook". For example:
https://123456789.ngrok.io/webhook
-
Run the webhook on your localhost:
python app.py
-
Make sure step '3' and '4' of previous chapter have been done properly.
-
From your test application in your Facebook developer page, click on 'Messenger' or add new product -> Messenger if not present yet.
-
In 'Token Generation', select the Facebook page you want to link with your local run.
-
Copy the Page Access Token
-
In your API.ai agent, in 'Integrations', chose 'Facebook Messenger', and paste the page access token in the corresponding area
-
Use "api_token" as verify token
-
Copy the Callback URL of your agent
-
Back on your Facebook developer page, select Messenger, and under Webhooks, subscribe webhooks to your page.
-
Add product 'Webhooks' if not present yet. Select 'Webhooks' and edit the subscription of the 'Page'.
-
Use the Api.ai agent's Callback URL, and "api_token" as verify token
Create a virtual environment with Python 3.5 (or 3.6)
virtualenv -p /usr/bin/python3.5 venv
Enter the virtual environment
source venv/bin/activate
Install dependencies
pip install -r requirements.txt
Copy .env.dist
to .env
and fill in the variables with real values. Then export the environment variables
export $(cat .env)
Now you can run the webhook with python app.py
. When you want to exit the virtualenv, just type:
deactivate
Following the PEP8 coding conventions is a good practice. Use a linter to help you (eg. Flake8), via CLI or as a plugin to your code editor).