-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
34 lines (26 loc) · 775 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
33
34
import json
import logging
from src.bot import Bot
from config.settings import *
from flask import Flask, request, abort, jsonify
app = Flask(__name__)
logging.basicConfig(filename='salam-bot.log', level=logging.DEBUG, format='%(asctime)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
@app.route('/', methods=['POST'])
def entry():
try:
if request.args.get(SALAM_BOT_TOKEN_KEY) != SALAM_BOT_TOKEN_VALUE:
raise Exception('BAD_TOKEN')
bot = Bot(
json.loads(
request.get_data()
)
)
bot.run()
return jsonify({
'success': 'true'
})
except Exception as e:
logging.error(e, exc_info=True)
abort(404)
if __name__ == '__main__':
app.run()