-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
33 lines (26 loc) · 1.03 KB
/
views.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
33
from flask import jsonify, render_template, request
from .business_logic import get_all_users,get_all_convs
from app.msgs.msg_receive import receive_message
import os
cellphone = os.environ.get('cellphone') or "51998249361"
def init_app(app):
@app.route('/')
def index():
registros = get_all_users()
conversations = get_all_convs()
return render_template('index.html', registros = registros, conversations = conversations)
@app.route('/webhook', methods=['GET', 'POST'])
def webhook():
if request.method == 'GET':
challenge = verify_token(request)
return challenge
elif request.method == 'POST':
response = receive_message(request)
return response
def verify_token(req):
token = req.args.get('hub.verify_token')
challenge = req.args.get('hub.challenge')
if challenge and token == 'token':
return challenge
else:
return jsonify({'error': 'Token Invalido'}), 401