-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
32 lines (26 loc) · 942 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-
from sanic import Sanic
from sanic.request import RequestParameters
from sanic.response import json
app = Sanic(__name__)
@app.route('/', methods=['GET'])
async def verify(request):
""" Verify Token.
when the endpoint is registered as a webhook, it must echo back
the 'hub.challenge' value it receives in the query arguments
"""
query_params = RequestParameters()
if not query_params:
return json({'response': 'hacer > hablar'})
if query_params.get('hub.verify_token') == 'hacker':
return json({
query_params.get('hub.challenge'),
})
return json({'Err, Token Invalid'})
@app.route('/', methods=['POST'])
async def webhook(request):
messages = json(request.body)
for entry in messages['entry']:
for message in entry['messaging']:
return json({'response': '{} o/'.format(message)})
return json({'response': 'o/'})