Update bot_telegram.py
Browse files- bot_telegram.py +12 -20
bot_telegram.py
CHANGED
|
@@ -205,7 +205,7 @@ class TelegramBot:
|
|
| 205 |
await update.message.reply_text("❌ Error: No job ID received from server")
|
| 206 |
return
|
| 207 |
|
| 208 |
-
await processing_msg.edit_text("✅ Excel file uploaded successfully!\n⏳ Processing questions...")
|
| 209 |
|
| 210 |
# Check status periodically
|
| 211 |
max_retries = 180 # 30 minutes maximum (with 10-second intervals)
|
|
@@ -220,19 +220,7 @@ class TelegramBot:
|
|
| 220 |
current_status = status_data.get('status')
|
| 221 |
|
| 222 |
if current_status == 'completed':
|
| 223 |
-
|
| 224 |
-
file_path = status_data.get('file_path')
|
| 225 |
-
if file_path and os.path.exists(file_path):
|
| 226 |
-
# Send the file to Telegram chat
|
| 227 |
-
await update.message.reply_document(
|
| 228 |
-
document=open(file_path, 'rb'),
|
| 229 |
-
filename="rfp_response.xlsx",
|
| 230 |
-
caption="✅ Here's your RFP response!"
|
| 231 |
-
)
|
| 232 |
-
# Clean up the file after sending
|
| 233 |
-
os.remove(file_path)
|
| 234 |
-
else:
|
| 235 |
-
await processing_msg.edit_text("❌ Could not find the generated file.")
|
| 236 |
break
|
| 237 |
elif current_status == 'failed':
|
| 238 |
error_msg = status_data.get('error', 'Unknown error')
|
|
@@ -242,20 +230,23 @@ class TelegramBot:
|
|
| 242 |
if retry_count % 18 == 0: # Update message every ~3 minutes
|
| 243 |
await processing_msg.edit_text(
|
| 244 |
"⏳ Still processing your questions...\n"
|
| 245 |
-
"This may take several minutes depending on the number of questions."
|
|
|
|
| 246 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
except Exception as e:
|
| 248 |
logging.error(f"Error checking status: {e}")
|
| 249 |
await processing_msg.edit_text("❌ Error while checking processing status.")
|
| 250 |
break
|
| 251 |
-
|
| 252 |
-
await asyncio.sleep(10)
|
| 253 |
-
retry_count += 1
|
| 254 |
|
| 255 |
if retry_count >= max_retries:
|
| 256 |
await processing_msg.edit_text(
|
| 257 |
-
"
|
| 258 |
-
"
|
|
|
|
| 259 |
)
|
| 260 |
|
| 261 |
elif response.status == 401:
|
|
@@ -294,3 +285,4 @@ if __name__ == "__main__":
|
|
| 294 |
password=API_PASSWORD
|
| 295 |
)
|
| 296 |
bot.run()
|
|
|
|
|
|
| 205 |
await update.message.reply_text("❌ Error: No job ID received from server")
|
| 206 |
return
|
| 207 |
|
| 208 |
+
await processing_msg.edit_text("✅ Excel file uploaded successfully!\n⏳ Processing questions and preparing email...")
|
| 209 |
|
| 210 |
# Check status periodically
|
| 211 |
max_retries = 180 # 30 minutes maximum (with 10-second intervals)
|
|
|
|
| 220 |
current_status = status_data.get('status')
|
| 221 |
|
| 222 |
if current_status == 'completed':
|
| 223 |
+
await processing_msg.edit_text("✅ Processing complete!\n📧 Email has been sent successfully! Please check your inbox.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
break
|
| 225 |
elif current_status == 'failed':
|
| 226 |
error_msg = status_data.get('error', 'Unknown error')
|
|
|
|
| 230 |
if retry_count % 18 == 0: # Update message every ~3 minutes
|
| 231 |
await processing_msg.edit_text(
|
| 232 |
"⏳ Still processing your questions...\n"
|
| 233 |
+
"This may take several minutes depending on the number of questions.\n"
|
| 234 |
+
"You'll receive an email when it's done."
|
| 235 |
)
|
| 236 |
+
elif status_response.status == 404:
|
| 237 |
+
await processing_msg.edit_text("❌ Job not found. Please try uploading again.")
|
| 238 |
+
break
|
| 239 |
+
|
| 240 |
except Exception as e:
|
| 241 |
logging.error(f"Error checking status: {e}")
|
| 242 |
await processing_msg.edit_text("❌ Error while checking processing status.")
|
| 243 |
break
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
if retry_count >= max_retries:
|
| 246 |
await processing_msg.edit_text(
|
| 247 |
+
"⏳ Your file is still being processed.\n"
|
| 248 |
+
"Don't worry - you'll receive an email when it's complete.\n"
|
| 249 |
+
"You can continue using the bot for other questions."
|
| 250 |
)
|
| 251 |
|
| 252 |
elif response.status == 401:
|
|
|
|
| 285 |
password=API_PASSWORD
|
| 286 |
)
|
| 287 |
bot.run()
|
| 288 |
+
|