Telegram HTTP API With Python — Sending Messages Programatically

Liu Zuo Lin
CodeX
Published in
4 min readDec 5, 2021

--

Perhaps you’re training a machine learning model and wish to notify yourself through Telegram when it’s done training. Perhaps you have some sort of service and wish to notify yourself whenever someone makes a call to your service. In this article, we’ll run through how to send a message with a Telegram bot using Python from start to end.

1) Create A Telegram Bot Using BotFather

The very first thing we need to do would be to create a Telegram Bot, and we can do this using BotFather (Search “BotFather” in your search bar)

  1. Type /newbot to tell BotFather that you wish to create a new Telegram bot
  2. Choose a name and username for your Telegram bot
  3. A token will be generated for your newly created Telegram bot — We will need this in our code later

Note: please don’t share your Telegram bot token with anyone — anyone with your token can take over control of your Telegram bot.

2) Create A Chat Containing Your Bot

--

--