diff --git a/telegram_bot.py b/telegram_bot.py
index f00e62b..2e84739 100644
--- a/telegram_bot.py
+++ b/telegram_bot.py
@@ -67,12 +67,20 @@ def admin_only(func):
async def wrapper(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
user_id = update.effective_user.id
if user_id not in TELEGRAM_ADMIN_CHAT_IDS:
- await update.message.reply_text("⛔ 无权限,你的 ID 不在管理员列表中")
+ # 兼容 message 和 callback_query
+ message = update.message or (update.callback_query.message if update.callback_query else None)
+ if message:
+ await message.reply_text("⛔ 无权限,你的 ID 不在管理员列表中")
return
return await func(self, update, context)
return wrapper
+def get_message(update: Update):
+ """获取可用于回复的 message 对象,兼容普通消息和 callback_query"""
+ return update.message or (update.callback_query.message if update.callback_query else None)
+
+
class ProvisionerBot:
"""OpenAI Team Provisioner Telegram Bot"""
@@ -2362,8 +2370,12 @@ class ProvisionerBot:
@admin_only
async def cmd_gptmail_add(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
"""添加 GPTMail API Key (支持批量导入)"""
+ message = get_message(update)
+ if not message:
+ return
+
if not context.args:
- await update.message.reply_text(
+ await message.reply_text(
"📧 添加 GPTMail API Key\n\n"
"单个添加:\n"
"/gptmail_add gpt-xxx\n\n"
@@ -2385,7 +2397,7 @@ class ProvisionerBot:
keys.append(key)
if not keys:
- await update.message.reply_text("❌ Key 不能为空")
+ await message.reply_text("❌ Key 不能为空")
return
# 获取现有 keys
@@ -2396,7 +2408,7 @@ class ProvisionerBot:
skipped = []
invalid = []
- await update.message.reply_text(f"⏳ 正在验证 {len(keys)} 个 Key...")
+ await message.reply_text(f"⏳ 正在验证 {len(keys)} 个 Key...")
for key in keys:
# 检查是否已存在
@@ -2405,7 +2417,7 @@ class ProvisionerBot:
continue
# 测试 Key 是否有效
- success, message = gptmail_service.test_api_key(key)
+ success, msg = gptmail_service.test_api_key(key)
if not success:
invalid.append(key)
@@ -2438,7 +2450,7 @@ class ProvisionerBot:
lines.append(f"\n当前 Key 总数: {len(get_gptmail_keys())}")
- await update.message.reply_text("\n".join(lines), parse_mode="HTML")
+ await message.reply_text("\n".join(lines), parse_mode="HTML")
@admin_only
async def cmd_gptmail_del(self, update: Update, context: ContextTypes.DEFAULT_TYPE):