switch Flask to FastAPI for future async.
This commit is contained in:
+5
-8
@@ -1,5 +1,4 @@
|
|||||||
import shelve
|
import shelve
|
||||||
from flask import request, abort
|
|
||||||
|
|
||||||
from . import stan
|
from . import stan
|
||||||
from . import rules
|
from . import rules
|
||||||
@@ -384,13 +383,11 @@ def handle_msg(message: types.Message):
|
|||||||
""" [ WEBHOOK ] """
|
""" [ WEBHOOK ] """
|
||||||
|
|
||||||
|
|
||||||
@app.route(f"/bot{TOKEN}/", methods=["POST"])
|
@app.post(f"/bot{TOKEN}/")
|
||||||
def webhook():
|
def webhook(update: dict):
|
||||||
"""Parse POST requests from Telegram."""
|
"""Parse POST requests from Telegram."""
|
||||||
if request.headers.get("content-type") == "application/json":
|
if update:
|
||||||
json_string = request.get_data().decode("utf-8")
|
update = telebot.types.Update.de_json(update)
|
||||||
update = types.Update.de_json(json_string)
|
|
||||||
bot.process_new_updates([update])
|
bot.process_new_updates([update])
|
||||||
return ""
|
|
||||||
else:
|
else:
|
||||||
abort(403)
|
return
|
||||||
|
|||||||
+2
-2
@@ -3,7 +3,7 @@ import re
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import telebot.types
|
import telebot.types
|
||||||
from flask import Flask
|
from fastapi import FastAPI
|
||||||
from telebot import TeleBot, logger, types
|
from telebot import TeleBot, logger, types
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ bot = TeleBot(
|
|||||||
)
|
)
|
||||||
LOG_TEXT = "[%s] %s: %s"
|
LOG_TEXT = "[%s] %s: %s"
|
||||||
LOG_COMM = "[%s] [%s] %s: %s"
|
LOG_COMM = "[%s] [%s] %s: %s"
|
||||||
app = Flask(__name__)
|
app = FastAPI(docs=None, redoc_url=None)
|
||||||
|
|
||||||
DATA = "data/chat"
|
DATA = "data/chat"
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user