Member-only story

How To Send Excel Files With Python Telegram Bot (Or Any Other Binary File)

Liu Zuo Lin
3 min readMay 18, 2022

--

I spent way more time googling for the solution and trying to figure this out than I would have liked, so hopefully this saves you the frustration of doing so if you happen to be attempting the same thing.

Installing The Relevant Library

pip install python-telegram-bot

Replace pip with pip3 if you’re using MacOS

Some Basic Python Telegram Bot Code

from telegram.ext import *TOKEN = "TELEGRAM BOT TOKEN FROM BOTFATHER"def route(update, context):
text = update.message.text
update.message.reply_text(text)
updater = Updater(TOKEN, use_context=True)
updater.dispatcher.add_handler(MessageHandler(Filters.text, route))
updater.start_polling()
print()
print("Your telegram bot is running!")
print()
updater.idle()

When we run this chunk of code, we get this output:

And when we send stuff to our bot, our bot replies with whatever we send it (the update.message.reply_text method in the route function).

Making Our Bot Reply With An Excel File

--

--

Liu Zuo Lin
Liu Zuo Lin

Written by Liu Zuo Lin

SWE @ Meta | [Ebook] 101 Things I Never Knew About Python: https://payhip.com/b/vywcf

No responses yet