Facebook Messenger bot that puts googly eyes on human faces
Demo video:
It's a Python HTTP Google Cloud function, that listens to Facebook Messenger Webhooks, detects human faces on photos using OpenCV library, draws googly eyes on them and saves results to Google Cloud Storage. It uses async request handling in order to be able to process webhook calls within required time.
Preconditions:
- Python 3, Virtualenv and pip
- Google Cloud Platform project
- Google Cloud SDK
virtualenv -p python3 venv
. venv/bin/activate
pip install -r requirements.txt
gcloud init
gsutil mb gs://ggly
gsutil mb gs://ggly-tasks-fb
gcloud functions deploy ggly --entry-point handle_url --runtime python37 --trigger-http --region europe-west1
You can test it with the following call:
curl https://europe-west1-<PROJECT_NAME>.cloudfunctions.net/ggly?url=<IMAGE_URL>
gcloud functions deploy ggly_fb --entry-point handle_fb_webhook --runtime python37 --trigger-http --region europe-west1
Add FB_ACCESS_TOKEN and FB_VERIFY_TOKEN environment variables to the function
gcloud functions deploy ggly_fb_worker --entry-point handle_fb_gcs_event --runtime python37 --trigger-resource ggly-tasks-fb --trigger-event google.storage.object.finalize --region europe-west1
Add FB_ACCESS_TOKEN and FB_VERIFY_TOKEN environment variables to the function
-
Create a new gcloud service account and grant it the following roles:
- roles/logging.logWriter
- roles/storage.objectCreator
-
Open permission settings for your GCS bucket and add
Storage Legacy Bucket Reader
for the service account -
Download service account credentials file and save it to
.credentials
folder
FLASK_APP=local_http.py GOOGLE_APPLICATION_CREDENTIALS=.credentials/ggly-local-dev.json flask run
curl -X GET "localhost:5000/ggly?url=<IMAGE_URL>"
PYTHONPATH=.:./venv/bin/python python ggly/local/camera.py
Demo video: