-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebhooks.py
More file actions
31 lines (21 loc) · 859 Bytes
/
webhooks.py
File metadata and controls
31 lines (21 loc) · 859 Bytes
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
# -*- coding: utf-8 -*-
import json
from flask import Flask, request
from app_config import FB_VERIFY_TOKEN
from chat_processor import process_message
app = Flask(__name__)
@app.route('/telegram', methods=['POST'])
def telegram():
process_message.delay({'source': 'telegram', 'data': json.loads(request.data.decode())})
return ('', 204)
@app.route('/facebook', methods=['GET', 'POST'])
def facebook():
if request.method == 'POST':
process_message.delay({'source': 'facebook', 'data': json.loads(request.data.decode())})
return ('', 204)
elif request.method == 'GET': # Para a verificação inicial
if request.args.get('hub.verify_token') == FB_VERIFY_TOKEN:
return request.args.get('hub.challenge')
return "Wrong Verify Token"
if __name__ == '__main__':
app.run(debug=True, port=5001)