Create a Telegram Bot

How to Create a Telegram Bot

If you want to control your projects from your smartphone or receive current sensor data, a Telegram bot is a practical solution.

In this tutorial, you’ll learn how to set up a Telegram bot in just a few minutes and also find your UserID, which you’ll need for many projects.

Install Telegram

First, the easiest step: To interact with your project via Telegram, you obviously need to have Telegram on your smartphone. If you haven’t already, open the Play Store or App Store and install the app. Now open Telegram and create an account.

If you’re not familiar with Telegram: The app is free and essentially does the same thing as WhatsApp. However, here you have the option to create so-called bots.

You can interact with these bots – for example, you can both send data from your ESP8266 to your smartphone and receive commands from there to, say, turn on the light on your breadboard. Of course, you’re not limited to an ESP8266.

Create a Telegram Bot and Save Your Token

In Telegram, now select Chats. At the top of the screen, you’ll find a search field – search for Botfather here.

Search for Botfather in Telegram

Open the Botfather and tap on Start. After his greeting, you’ll receive instructions. You can read through these now, or just tap on /newbot. The Botfather will then ask you for a name for your bot and a username.

Telegram bot name and user name

After you’ve assigned the names, you’ll receive a message with your token. You’ll need this later in your sketch to connect your ESP8266 with your Telegram bot.

Receive and copy your token in Telegram

That was the first part of the preparations in Telegram. However, one piece of information is still missing: the UserID.

Find Your UserID

In Telegram, open Chats again and search for IDBot there.

    Now tap on IDBot and in the following chat window on /getid. You’ll immediately receive a message with your UserID:

    Get the Telegram userID

    And that’s it for the preparations in Telegram. Keep your token and UserID ready to enter them later in the respective sketch of the project. And above all, keep them secret so that no one else can use your bot.

    Learn how to send messages with Telegram and the ESP32 or ESP8266.