A tutorial for making your own Uber cab assistant using Facebook Messenger Platform, AWS API Gateway and Lambda and Uber API.
This repository contains code accompanying this blog post.
-
Install required libraries using pip. You need to install these libraries at a level of the function main.py.
pip install requests pytz -t functions/process_chat
- # for AWS, if you haven't already
- You need AWS credentials to access its services like API Gateway and Lambda. We will do it using IAM (Identity and Access Management) user.
- Follow this guide to setup your IAM user, its permissions and get its credentials
- Also use the above guide to build and test an example API and create your own API endpoint.
- Follow this quick start guide to create a Facebook app and page
- For step 2 in the guide, use the API endpoint created above as the callback url
- In step 2, you will be asked to enter a verify token. Enter any string you want to and use the same string for the variable
FB_VERIFY_TOKEN
in main.py - Before you can verify and save, you need to deploy your code to AWS Lambda
- We will use Apex to deploy the code. This page also has instructions to get started.
- Install Apex
- Add the AWS credentials to your environment and IAM role to project.json
- Now deploy the code with by running
apex deploy
in the terminal - Your code should now be deployed to Lambda
- Now use the API gateway dashboard to integrate your API endpoint with the newly created lambda function
- Now complete steps 2 & 3 of the Messenger quick start guide.
- Get the page access token and assign it to the variable
FB_PAGE_ACCESS_TOKEN
in main.py - Re-deploy the code
- Complete step 5 of the quick start guide
- For testing purposes change the code in main.py to echo back your chat messages
- Once you do this you can move on the Uber's API
- You will have to # with your Uber account and register an application with them here.
- You will be asked to enter a
redirect uri
. You can enterhttp://localhost:8000
- You will be provided with a
client_id
,secret
, andserver_token
. - Assign the
server_token
to the variableUBER_SERVER_TOKEN
in main.py - Now you need your own access token to book rides via the API
- Follow the authentication guide to get your access token
- Make sure you authorize your self for all scopes. More on scopes here
- Once you get the access token assign it to
UBER_ACCESS_TOKEN
in main.py
You are now ready to go.
You can reach me on Twitter if you have any questions.