kin: BATON-008-backend_dev
This commit is contained in:
parent
e21bcb1eb4
commit
4c9fec17de
11 changed files with 651 additions and 4 deletions
|
|
@ -55,6 +55,68 @@ async def send_message(text: str) -> None:
|
|||
logger.error("Telegram send_message: all 3 attempts failed, message dropped")
|
||||
|
||||
|
||||
async def send_registration_notification(
|
||||
reg_id: int, login: str, email: str, created_at: str
|
||||
) -> None:
|
||||
"""Send registration request notification to admin with approve/reject inline buttons.
|
||||
Swallows all errors — never raises."""
|
||||
url = _TELEGRAM_API.format(token=config.BOT_TOKEN, method="sendMessage")
|
||||
text = (
|
||||
f"📋 Новая заявка на регистрацию\n\n"
|
||||
f"Login: {login}\nEmail: {email}\nДата: {created_at}"
|
||||
)
|
||||
reply_markup = {
|
||||
"inline_keyboard": [[
|
||||
{"text": "✅ Одобрить", "callback_data": f"approve:{reg_id}"},
|
||||
{"text": "❌ Отклонить", "callback_data": f"reject:{reg_id}"},
|
||||
]]
|
||||
}
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
resp = await client.post(
|
||||
url,
|
||||
json={
|
||||
"chat_id": config.ADMIN_CHAT_ID,
|
||||
"text": text,
|
||||
"reply_markup": reply_markup,
|
||||
},
|
||||
)
|
||||
if resp.status_code != 200:
|
||||
logger.error(
|
||||
"send_registration_notification failed %s: %s",
|
||||
resp.status_code,
|
||||
resp.text,
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.error("send_registration_notification error: %s", exc)
|
||||
|
||||
|
||||
async def answer_callback_query(callback_query_id: str) -> None:
|
||||
"""Answer a Telegram callback query. Swallows all errors."""
|
||||
url = _TELEGRAM_API.format(token=config.BOT_TOKEN, method="answerCallbackQuery")
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
resp = await client.post(url, json={"callback_query_id": callback_query_id})
|
||||
if resp.status_code != 200:
|
||||
logger.error("answerCallbackQuery failed %s: %s", resp.status_code, resp.text)
|
||||
except Exception as exc:
|
||||
logger.error("answerCallbackQuery error: %s", exc)
|
||||
|
||||
|
||||
async def edit_message_text(chat_id: str | int, message_id: int, text: str) -> None:
|
||||
"""Edit a Telegram message text. Swallows all errors."""
|
||||
url = _TELEGRAM_API.format(token=config.BOT_TOKEN, method="editMessageText")
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
resp = await client.post(
|
||||
url, json={"chat_id": chat_id, "message_id": message_id, "text": text}
|
||||
)
|
||||
if resp.status_code != 200:
|
||||
logger.error("editMessageText failed %s: %s", resp.status_code, resp.text)
|
||||
except Exception as exc:
|
||||
logger.error("editMessageText error: %s", exc)
|
||||
|
||||
|
||||
async def set_webhook(url: str, secret: str) -> None:
|
||||
api_url = _TELEGRAM_API.format(token=config.BOT_TOKEN, method="setWebhook")
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue