ForcePilot/backend/package/yuxi/channels/adapters/telegram/probe.py

41 lines
1.3 KiB
Python
Raw Normal View History

from __future__ import annotations
from typing import Any
from telegram import Bot
from telegram.error import TelegramError
from yuxi.utils.logging_config import logger
async def probe_bot(bot: Bot) -> dict[str, Any]:
try:
bot_info = await bot.get_me()
return {
"id": bot_info.id,
"username": bot_info.username,
"first_name": bot_info.first_name,
"last_name": bot_info.last_name,
"can_join_groups": bot_info.can_join_groups,
"can_read_all_group_messages": bot_info.can_read_all_group_messages,
"supports_inline_queries": bot_info.supports_inline_queries,
}
except TelegramError as e:
logger.error(f"[Telegram] Bot probe failed: {e}")
raise
async def probe_webhook(bot: Bot) -> dict[str, Any]:
try:
info = await bot.get_webhook_info()
return {
"url": info.url,
"has_custom_certificate": info.has_custom_certificate,
"pending_update_count": info.pending_update_count,
"last_error_date": info.last_error_date,
"last_error_message": info.last_error_message,
}
except TelegramError as e:
logger.error(f"[Telegram] Webhook probe failed: {e}")
raise