I have a problem about file messages in python telegram bot. How can I receive file and read that file ? Or save it.
I have a problem about file messages in python telegram bot. How can I receive file and read that file ? Or save it.
You can:
DocumentFile object from the update (inside the listener using get_file).download() to download the documentHere a sample code to get you started:
from telegram.ext import Updater, MessageHandler, Filters
BOT_TOKEN = ' ... '
def downloader(update, context):
context.bot.get_file(update.message.document).download()
# writing to a custom file
with open("custom/file.doc", 'wb') as f:
context.bot.get_file(update.message.document).download(out=f)
updater = Updater(BOT_TOKEN, use_context=True)
updater.dispatcher.add_handler(MessageHandler(Filters.document, downloader))
updater.start_polling()
updater.idle()