Source

Telegram Bot

Paramjeet Singh
Chatbots Life
Published in
4 min readJun 13, 2020

--

Telegram is a messaging application which is used to send text, images or video messages free of cost. It also allows using other API to create programs to integrate Telegram in their applications. There are special bots which do not need phone number to set up and can be interfaced with any embedded or software application to trigger some event using telegram text messages.

It is a multi-platform messaging service founded by Russian entrepreneur Pavel Durov. It rolled out for Android in Alpha on October 20, 2013, and now has an estimated 200 million monthly users.

Telegram’s user base tends to increase whenever a privacy scandal hits one of its larger competitors.

We can use telegram as a bot also with some lines of code in ESP8266/ESP32/ESP01 by arduino IDE which is designed to code in C language.

Step-1 (Creating Bot)

Install “Telegram” app on your smartphone from your play store or apple store. Sign Up if you are going to use it for the first time with your country code and mobile number. It will ask for OTP code for verification.

Trending Chatbot Articles:

1. Knowledge graphs and Chatbots — An analytical approach.

2. Blender Vs Rasa open source chatbots

3. Picture my voice

4. Chat bots — A Conversational AI

After successfully sign up, search for BotFather and open it. Open BotFather and click on RESTART for creating your bot as shown in screenshot below. It will show set of codes which can be used to create and edit bots. Type “/newbot” in the text section for creating new bot.

Step-2 (Installing Telegram Library in Arduino IDE)

To integrate telegram in Arduino code, there is a library for that, to install it open Arduino IDE and Go to Sketch -> Include Library -> Manage Libraries

Search for “Telegram” in the Library Manager and install UniversalTelegramBot by Brian Lough.

Step-3 (Installing JSON Library in Arduino IDE)

On the same Library Manager sear for “json“. Install ArduinoJson by Benoit Blanchon. Select Version 5.13.5 DO NOT select any higher version (6.x.x ). Higher versions have compatibility issues and the code will not respond. This library is used for parsing json from the API responses.

How it Works?

First we create a telegram bot. Telegram has this good feature which allows to create custom bots and connect it using API’s. The bot provides a bot token which is added in the code. After saving we will upload the code in NodeMCU. Once the nodemcu gets connected with internet, then it is ready to take inputs from telegram app.

As per the code /start will start the bot. The bot will send below response for the first time.

Welcome to Universal Arduino Telegram Bot,
/ledon : to switch the Led ON
/ledoff : to switch the Led OFF
/status : Returns current status of LED

You can tap on /ledon and it will turn on the LED and /ledoff for switching off LED.

Download code from github.

Note:

All versions of ESP8266 are working for telegram in IDE.

Thank You

Don’t forget to give us your 👏 !

--

--