feat: log raw telegram updates in development
This commit is contained in:
1 parent
926031713d
commit
ff09b74f03
7 files changed
+249
-3
No files matched your search
@@ -30,6 +30,7 @@ from aiogram.types import (
|
||||
|
||||
import payments
|
||||
import user_store
|
||||
from raw_updates import RawUpdateMiddleware, init_raw_updates_db
|
||||
|
||||
from apinex_client import APINEX_STT_URL, POST_HISTORY_CHAR_LIMIT, POST_HISTORY_LIMIT, classify_intent, classify_prompt_injection, create_tone_profile, current_operation_id, diagnostic_operation, extract_posts_from_images, extract_transcript, generate_ideas, generate_posts, generate_posts_from_images, transcribe_audio
|
||||
from help_message import WELCOME_RICH_HTML, help_plain_view, help_view, rich_to_plain
|
||||
@@ -189,6 +190,13 @@ def is_development_environment() -> bool:
|
||||
return DEPLOY_ENV == "development"
|
||||
|
||||
|
||||
def configure_raw_update_logging(dispatcher: Dispatcher) -> bool:
|
||||
if not is_development_environment():
|
||||
return False
|
||||
dispatcher.update.outer_middleware(RawUpdateMiddleware())
|
||||
return True
|
||||
|
||||
|
||||
def _read_version() -> str:
|
||||
version_path = Path(__file__).with_name("VERSION")
|
||||
return version_path.read_text(encoding="utf-8").strip()
|
||||
@@ -1251,6 +1259,8 @@ async def set_main_menu(bot: Bot) -> None:
|
||||
async def main() -> None:
|
||||
init_db()
|
||||
payments.init_payments_table()
|
||||
if is_development_environment():
|
||||
await asyncio.to_thread(init_raw_updates_db)
|
||||
token = os.environ.get("BOT_TOKEN", "").strip()
|
||||
if not token:
|
||||
raise RuntimeError("BOT_TOKEN is required")
|
||||
@@ -1260,6 +1270,7 @@ async def main() -> None:
|
||||
bot = Bot(token=token, session=session)
|
||||
await notify_development_deploy(bot)
|
||||
dp = Dispatcher(storage=MemoryStorage())
|
||||
configure_raw_update_logging(dp)
|
||||
dp.include_router(payments.router)
|
||||
dp.include_router(router)
|
||||
# Ставим меню один раз при старте, чтобы оно было у всех, кто писал боту.
|
||||
|
||||
Reference in new issue
Block a user