Skip to content

Instantly share code, notes, and snippets.

@JavyMB
Created June 11, 2018 15:40
Show Gist options
  • Save JavyMB/a0dcf6d01bd2d840dd21cadca959da07 to your computer and use it in GitHub Desktop.
Save JavyMB/a0dcf6d01bd2d840dd21cadca959da07 to your computer and use it in GitHub Desktop.
Facebook webhook
import json
import os
import sys
here = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(here, "./vendored"))
VERIFY_TOKEN = os.environ['VERIFY_TOKEN'] #reemplace
from utils.facebookhandler import FacebookHandler
def webhook(event, context):
try:
response = {
"statusCode": 200,
"body":"",
}
if event['method'] == 'GET':
if 'hub.verify_token' in event['query'] and event['query']['hub.verify_token'] == VERIFY_TOKEN:
print("succefully verified")
response['body'] = event['query']['hub.challenge']
return response
else:
print("Wrong verification token!")
response = {
"statusCode": 400,
"body": "Wrong validation token"
}
return response
elif event['method'] == 'POST':
if 'entry' in event['body']:
FacebookHandler.entries(event['body']['entry'])
else:
print(event['body'])#Something we dont handle yet and we want to take a look ...
return response
else:
response = {
"statusCode": 400,
"body": "No POST or GET detected sorry"
}
return response
except Exception as e:
print(e)
return e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment