urstark commited on
Commit
620a711
·
1 Parent(s): ee36243

Enhance MTProto vaulting with peer resolution and retry logic

Browse files
Files changed (1) hide show
  1. app.py +38 -17
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
- if request.type == 'video':
94
- msg = await bot.send_video(
95
- chat_id=CHAT_ID,
96
- video=file_path,
97
- caption=caption,
98
- file_name=f"{request.title}.mp4"
99
- )
100
- file_id = msg.video.file_id
101
- else:
102
- msg = await bot.send_audio(
103
- chat_id=CHAT_ID,
104
- audio=file_path,
105
- caption=caption,
106
- title=request.title,
107
- file_name=f"{request.title}.mp3"
108
- )
109
- file_id = msg.audio.file_id
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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