bot http fix
This commit is contained in:
@ -1,16 +1,18 @@
|
|||||||
import os
|
import os
|
||||||
from fastapi import APIRouter, Request, HTTPException
|
from fastapi import APIRouter, Request, HTTPException
|
||||||
|
from app.services.auth import AuthService
|
||||||
from telebot import TeleBot, types
|
from telebot import TeleBot, types
|
||||||
|
import asyncio
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
auth_service = AuthService()
|
||||||
|
|
||||||
|
|
||||||
BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
|
BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
|
||||||
WEBHOOK_SECRET = os.getenv("TELEGRAM_WEBHOOK_SECRET", "") # опционально
|
WEBHOOK_SECRET = os.getenv("TELEGRAM_WEBHOOK_SECRET", "") # опционально
|
||||||
bot = TeleBot(BOT_TOKEN, threaded=False) # threaded=False обычно проще в async-сервисах
|
bot = TeleBot(BOT_TOKEN, threaded=False) # threaded=False обычно проще в async-сервисах
|
||||||
|
|
||||||
# ====== ВАШИ ХЕНДЛЕРЫ (почти без изменений) ======
|
|
||||||
import httpx
|
|
||||||
|
|
||||||
API_URL = os.getenv("API_URL")
|
API_URL = os.getenv("API_URL")
|
||||||
user_states = {} # ⚠️ см. примечание ниже про хранение
|
user_states = {} # ⚠️ см. примечание ниже про хранение
|
||||||
|
|
||||||
@ -34,16 +36,10 @@ def verify_code(message):
|
|||||||
code = message.text.strip()
|
code = message.text.strip()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = httpx.post(
|
asyncio.run(auth_service.verify_code(username, code, message.chat.id))
|
||||||
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, "✅ Аккаунт подтвержден!")
|
bot.reply_to(message, "✅ Аккаунт подтвержден!")
|
||||||
else:
|
|
||||||
bot.reply_to(message, f"❌ Ошибка: {r.json().get('detail')}")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
bot.reply_to(message, "⚠️ Сервер недоступен. Детальная информация: " + str(e))
|
bot.reply_to(message, "❌ Ошибка: " + str(e))
|
||||||
|
|
||||||
user_states.pop(message.chat.id, None)
|
user_states.pop(message.chat.id, None)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user