Spaces:
Runtime error
Runtime error
Enhance MTProto vaulting with peer resolution and retry logic
Browse files
app.py
CHANGED
|
@@ -90,23 +90,44 @@ async def process_vault(request: VaultRequest):
|
|
| 90 |
print(f"[MTProto] Starting upload to chat {CHAT_ID} (Type: {request.type})")
|
| 91 |
caption = f"{request.title}\nID: {request.videoId}"
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
print(f"[MTProto] Upload success! Message ID: {msg.id}")
|
| 112 |
|
|
|
|
| 90 |
print(f"[MTProto] Starting upload to chat {CHAT_ID} (Type: {request.type})")
|
| 91 |
caption = f"{request.title}\nID: {request.videoId}"
|
| 92 |
|
| 93 |
+
try:
|
| 94 |
+
if request.type == 'video':
|
| 95 |
+
msg = await bot.send_video(
|
| 96 |
+
chat_id=CHAT_ID,
|
| 97 |
+
video=file_path,
|
| 98 |
+
caption=caption,
|
| 99 |
+
file_name=f"{request.title}.mp4"
|
| 100 |
+
)
|
| 101 |
+
file_id = msg.video.file_id
|
| 102 |
+
else:
|
| 103 |
+
msg = await bot.send_audio(
|
| 104 |
+
chat_id=CHAT_ID,
|
| 105 |
+
audio=file_path,
|
| 106 |
+
caption=caption,
|
| 107 |
+
title=request.title,
|
| 108 |
+
file_name=f"{request.title}.mp3"
|
| 109 |
+
)
|
| 110 |
+
file_id = msg.audio.file_id
|
| 111 |
+
except Exception as upload_err:
|
| 112 |
+
print(f"[MTProto] Upload failed for {CHAT_ID}: {str(upload_err)}")
|
| 113 |
+
# Try to resolve peer if it's a common 'Peer id invalid' issue
|
| 114 |
+
if "Peer id invalid" in str(upload_err) or "CHANNEL_INVALID" in str(upload_err):
|
| 115 |
+
print(f"[MTProto] Attempting to resolve chat {CHAT_ID}...")
|
| 116 |
+
try:
|
| 117 |
+
chat = await bot.get_chat(CHAT_ID)
|
| 118 |
+
print(f"[MTProto] Resolved chat: {chat.title}. Retrying upload...")
|
| 119 |
+
# Retry once after resolution
|
| 120 |
+
if request.type == 'video':
|
| 121 |
+
msg = await bot.send_video(chat_id=CHAT_ID, video=file_path, caption=caption)
|
| 122 |
+
file_id = msg.video.file_id
|
| 123 |
+
else:
|
| 124 |
+
msg = await bot.send_audio(chat_id=CHAT_ID, audio=file_path, caption=caption, title=request.title)
|
| 125 |
+
file_id = msg.audio.file_id
|
| 126 |
+
except Exception as retry_err:
|
| 127 |
+
print(f"[MTProto] Retry failed: {str(retry_err)}")
|
| 128 |
+
raise upload_err
|
| 129 |
+
else:
|
| 130 |
+
raise upload_err
|
| 131 |
|
| 132 |
print(f"[MTProto] Upload success! Message ID: {msg.id}")
|
| 133 |
|