ForcePilot/backend/package/yuxi/channels/adapters/telegram/probe.py
Kris 71fec609bb feat(telegram-adapter): 实现完整的Telegram适配器基础代码
新增了Telegram适配器的全套基础模块,包括:
1.  核心适配器入口与会话工具
2.  账号管理、认证与配置系统
3.  连接相关的轮询、Webhook、更新偏移管理
4.  话题路由、管理与缓存系统
5.  消息反抖动、超时配置与工具类
6.  响应式UI与命令交互系统
7.  反应表情与通知系统
8.  审批与安全审计模块
9.  健康检查与状态监控
10. 贴纸缓存与视觉工具
11. 流式响应与协作功能
12. 群组迁移与目标归一化处理
2026-05-12 00:49:52 +08:00

41 lines
1.3 KiB
Python

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