Hello! How are you today?
- User
Assistant: Hello! How are you today? User: Instead delete wait message then edit it
@bot.message_handler(content_types=["document"]) def handle_document(message): chat_id=message.chat.id wait_message=bot.send_message(chat_id,"Processing...") try: file_info=bot.get_file(message.document.file_id) file_text=bot.download_file(file_info.file_path).decode("utf-8",errors="ignore") response=get_ai_response(file_text) bot.delete_message(chat_id,wait_message.id) send_chunked_message(chat_id,rebsponse) except: bot.delete_message(chat_id,wait_message.id) bot.send_message(chat_id,"Error processing document") Assistant:
- Assistant
Your goal seems to be to delete the wait message and replace it with the response from the AI. Here's how you can achieve that. I'll make a few adjustments to your original code for clarity and correctness:
- Ensure the
send_chunked_messagefunction is correctly called. - Edit the wait message instead of deleting it.
Here's an updated version of your function:
@bot.message_handler(content_types=["document"]) def handle_document(message): chat_id = message.chat.id wait_message = bot.send_message(chat_id, "Processing...") try: file_info = bot.get_file(message.document.file_id) file_text = bot.download_file(file_info.file_path).decode("utf-8", errors="ignore") response = get_ai_response(file_text) # Edit the wait message with the response bot.edit_message_text(chat_id=chat_id, message_id=wait_message.id, text=response) except Exception as e: # Edit the wait message to show an error instead bot.edit_message_text(chat_id=chat_id, message_id=wait_message.id, text="Error processing document: " + str(e)) - Ensure the