From 3aac4263643d383a7c29a2ac356a8f0c8205d4bf Mon Sep 17 00:00:00 2001 From: DIKER0K Date: Fri, 12 Dec 2025 20:40:47 +0500 Subject: [PATCH] bot http fix --- app/webhooks/telegram.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/app/webhooks/telegram.py b/app/webhooks/telegram.py index bbe3565..991f45c 100644 --- a/app/webhooks/telegram.py +++ b/app/webhooks/telegram.py @@ -1,16 +1,18 @@ import os from fastapi import APIRouter, Request, HTTPException +from app.services.auth import AuthService from telebot import TeleBot, types +import asyncio router = APIRouter() +auth_service = AuthService() + + BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN") WEBHOOK_SECRET = os.getenv("TELEGRAM_WEBHOOK_SECRET", "") # опционально bot = TeleBot(BOT_TOKEN, threaded=False) # threaded=False обычно проще в async-сервисах -# ====== ВАШИ ХЕНДЛЕРЫ (почти без изменений) ====== -import httpx - API_URL = os.getenv("API_URL") user_states = {} # ⚠️ см. примечание ниже про хранение @@ -34,16 +36,10 @@ def verify_code(message): code = message.text.strip() try: - r = httpx.post( - f"{API_URL}/auth/verify_code", - json={"username": username, "code": code, "telegram_chat_id": message.chat.id}, - ) - if r.status_code == 200: - bot.reply_to(message, "✅ Аккаунт подтвержден!") - else: - bot.reply_to(message, f"❌ Ошибка: {r.json().get('detail')}") + asyncio.run(auth_service.verify_code(username, code, message.chat.id)) + bot.reply_to(message, "✅ Аккаунт подтвержден!") except Exception as e: - bot.reply_to(message, "⚠️ Сервер недоступен. Детальная информация: " + str(e)) + bot.reply_to(message, "❌ Ошибка: " + str(e)) user_states.pop(message.chat.id, None)