0
votes

I am trying to get my telegram bot to download a pdf document that is on google drive, but I can't get it to work. I made the following code to be able to get it to work but there was no case in this:

url = bot.get_File(link='link of google drive') down = url.download() bot.sendDocument(chat_id=ChatId, document=open(down,'rb'), filename="Lista de precios.pdf")

I don't put the google drive link for privacy reasons, but obviously it would go there. I don't know if it is possible to download a file from drive just like that.

1

1 Answers

0
votes

Looks like you are using the wrong method, get_file is used to download a file from Telegram.
When sending a file via Telegram bot you can use the full URL if this points to a file (ie file.pdf)

bot.send_document(chat_id=Chat_id, document='https://github.com/user/project/raw/master/data/pdf/07-03-2020.pdf'

In case of Google Drive you have a URL that streams the file so you need to 1) download and save the file locally 2) open the local file and send it as file type

r = requests.get('googleDriveUrl', allow_redirects=True)
open('file.ppt', 'wb').write(r.content)

bot.send_document(chat_id=Chat_id, document=open('file.ppt', 'rb'), filename="file.pptx")