mirror of
https://github.com/Balshgit/mosgortrans.git
synced 2026-02-03 11:20:56 +03:00
app with uvicorn
This commit is contained in:
@@ -5,7 +5,6 @@ from aiogram.contrib.middlewares.logging import LoggingMiddleware
|
||||
from aiogram.dispatcher import Dispatcher
|
||||
from aiogram.dispatcher.webhook import SendMessage
|
||||
from aiogram.utils.callback_data import CallbackData
|
||||
from app.core.logger import logger
|
||||
from app.core.parse_web import (
|
||||
configure_firefox_driver,
|
||||
download_gecko_driver,
|
||||
@@ -71,7 +70,6 @@ async def office_home(
|
||||
|
||||
@dispatcher.message_handler(commands=['chatid'])
|
||||
async def chat_id(message: types.Message) -> SendMessage:
|
||||
logger.info('Hello World')
|
||||
return SendMessage(message.chat.id, message.chat.id)
|
||||
|
||||
|
||||
|
||||
20
app/main.py
20
app/main.py
@@ -57,7 +57,7 @@ def bot_webhook() -> None:
|
||||
)
|
||||
|
||||
|
||||
async def index(request: web.Request) -> web.Response:
|
||||
async def webhook(request: web.Request) -> web.Response:
|
||||
data = await request.json()
|
||||
Bot.set_current(dispatcher.bot)
|
||||
Dispatcher.set_current(dispatcher)
|
||||
@@ -66,17 +66,19 @@ async def index(request: web.Request) -> web.Response:
|
||||
return web.Response(status=HTTPStatus.OK)
|
||||
|
||||
|
||||
async def create_app() -> web.Application:
|
||||
app = web.Application()
|
||||
app.router.add_post('/', index)
|
||||
return app
|
||||
def create_app() -> web.Application:
|
||||
application = web.Application()
|
||||
application.router.add_post('/', webhook)
|
||||
return application
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import uvicorn
|
||||
|
||||
if START_WITH_WEBHOOK:
|
||||
bot_webhook()
|
||||
else:
|
||||
# bot_polling() # type: ignore
|
||||
# bot_webhook() # type: ignore
|
||||
app = create_app()
|
||||
web.run_app(app=app, host='localhost', port=8084)
|
||||
uvicorn.run(app=app, host=WEBAPP_HOST, port=WEBAPP_PORT)
|
||||
else:
|
||||
bot_polling()
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ WEBHOOK_PATH = config('WEBHOOK_PATH', default='')
|
||||
WEBHOOK_URL = f"{WEBHOOK_HOST}{WEBHOOK_PATH}"
|
||||
|
||||
# webserver settings
|
||||
WEBAPP_HOST = config('WEBAPP_HOST', default='localhost') # or ip
|
||||
WEBAPP_HOST = config('WEBAPP_HOST', default='127.0.0.1') # or ip
|
||||
WEBAPP_PORT = config('WEBAPP_PORT', cast=int, default=8084)
|
||||
|
||||
START_WITH_WEBHOOK = config('START_WITH_WEBHOOK', cast=bool, default=False)
|
||||
|
||||
Reference in New Issue
Block a user