Telegram Bot with MicroPython

Create TG bot

  1. Open Telegram
  2. Search for @botfather
  3. Start chat
  4. Send /newbot
  5. Pick a name
  6. Pick a username (must be unique)
  7. Receive credentials

Chat with your bot

Now you can search for your bot’s name and send a message

Python test Program

Telegram has a nice python package which you can pip install

pip install python-telegram-bot --upgrade
import telegram

bot = telegram.Bot(token='<your_token>')

if __name__ == '__main__':
    bot.send_message(chat_id="<your_chat_id>", text="Post ist da")

This program is just to used to test the connectivity of your bot.

Because we don’t have access to the telegram package inside the ESP / MicroPython environment we use urequests.


Sending messages

import urequests