-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
37 lines (25 loc) · 801 Bytes
/
server.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
35
36
from flask import Flask, request
from flask_migrate import Migrate
import telebot
from config import Config
from database import db
migrate = Migrate()
def create_server(config=Config):
app = Flask(__name__)
app.config.from_object(config)
db.init_app(app)
migrate.init_app(app, db)
return app
server = create_server()
bot = telebot.TeleBot(server.config['TOKEN'])
@server.route('/')
def webhook():
bot.remove_webhook()
# TODO: use server.config['SERVER_NAME']
bot.set_webhook(url='https://{}/{}'.format(Config.HOST, TOKEN))
return 'ok'
@server.route('/' + server.config['TOKEN'], methods=['POST'])
def update():
# TODO: understand this line
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode())])
return 'ok'