How to make doc to pdf bot in telegram using python

This Python code is for a Telegram bot that can convert documents to PDF format. Here’s a simple summary:

1. The code imports necessary libraries for the Telegram bot, handling document conversions, and working with Excel and PowerPoint files.
2. You need to replace 'YOUR_API_KEY' with your actual Telegram bot API key.
3. The bot responds to the /start command by sending a greeting message.
4. When the user sends a document (e.g., Word, Excel, PowerPoint) to the bot, it triggers the handle_document function.
5. The bot downloads the document, saves it with the original file name, and determines its file extension.
6. Depending on the file type (.docx, .xls, .xlsx, .ppt, .pptx), the bot uses the appropriate library to convert the document to PDF.
7. The converted PDF is sent back to the user.
8. The bot cleans up by deleting the downloaded and converted files after sending the PDF.
9. If any error occurs during the process, the bot sends an error message to the user.

To use this code, you should have the required libraries installed and a valid Telegram bot API key. The bot should work as long as the code is running and the API key is valid.

Now the bot should handle Word, Excel, and PowerPoint files and convert them to PDF accordingly. Please replace 'YOUR_API_KEY' with your actual API key to make it work.


Leave a Comment