bot http fix
This commit is contained in:
@ -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:
|
||||
asyncio.run(auth_service.verify_code(username, code, message.chat.id))
|
||||
bot.reply_to(message, "✅ Аккаунт подтвержден!")
|
||||
else:
|
||||
bot.reply_to(message, f"❌ Ошибка: {r.json().get('detail')}")
|
||||
except Exception as e:
|
||||
bot.reply_to(message, "⚠️ Сервер недоступен. Детальная информация: " + str(e))
|
||||
bot.reply_to(message, "❌ Ошибка: " + str(e))
|
||||
|
||||
user_states.pop(message.chat.id, None)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user