top of page
Writer's pictureBhavya Putta

Using Telegram Bot with Raspberry Pi - Sharing Text and Files

Updated: Sep 24


Illustration of Sharing texts and files
Sharing texts and files

The Internet of Things is a new era in computing technologies. IoT includes many machines and devices interacting with each other. It plays a major role in the automation and interconnection of numerous devices. Devices are interconnected over the internet to monitor a task or to communicate with each other. They interact and detect anomalies, send alerts, share files, switch on, or switch off a particular device, and can do numerous other tasks.


In this article, let's discuss how to connect a Raspberry Pi with a Telegram Bot to share text and files. #Telegram is a cloud-based application used for the instant exchange of text and files. The Telegram Bot API allows it to interact with machines as well. The Telegram app is used from one's mobile to send commands to the #RaspberryPi, thereby enabling us to communicate with it. The components required, details of the hardware used, configuring the Telegram Bot, and the #code to be executed are discussed here. Let's head towards the project and know how it works.





Hardware used


Image of All Components
All Components

The components used here are:

1) Raspberry Pi

2) USB Cable

3) SC Card

Let's know about them now.


Raspberry Pi


Image of Raspberry Pi 3 Model B+
Raspberry Pi 3 Model B+

It is a tiny single-board computer with so many uses that it's possibly the biggest British invasion since "The Beatles". It was originally developed to promote the teaching of Programming in schools of developing countries. It is also widely used in many DIY projects. The Raspberry Pi 3 Model B+ used here is the last version of the 3rd Gen single board computers. It has 1GB LPDDR2 SDRAM, 4 USB 2.0 ports, a Micro SD port for loading your operating system and storing data, a CSI camera port, a DSI display port, and a 5V/2.5A DC power input.





USB Cable


USB cable for power supply
USB cable for power supply

The Raspberry Pi should be powered via the micro USB port using a cable. The input rated voltage is 5V, and the current is 2.5A.


SD Card


Image of 16 GB SD card loaded with Raspbian OS
16 GB SD card loaded with Raspbian OS

The 16 GB SD card used is loaded with the Raspbian OS. The #Raspbian is a Debian #Linux based OS specially designed for the Raspberry Pi. It is a primary operating system for the family of single-board computers of the Raspberry Pi series. It is now a 64bit version with the name Raspberry Pi OS and doesn't use the Raspbian core.





the Telegram Bot


Image of Chat Bot Configuration
Chat Bot Configuration
  • Firstly, install the Telegram app from the play store.

  • Now search for BotFather and open it. This is where a new Bot can be created.

  • Type /start and you will get a menu. Then type /newbot, and you will be asked for a name and username for the new Bot.

  • The username must end with 'Bot'.

  • Now a congratulations message will be displayed, and an Auth Token will be provided, which is used in creating a channel between the Raspberry Pi and Telegram Bot.


Commands used
Commands Used
  • Then enter /set commands to enable commands for your bot.

  • Specify the name of your Bot and now enter the commands you require.

  • The commands used here are hi(To show the welcome message), time(To show current time), file(To share the specified file), image(To share the specified image).



setcommands Output
setcommands Output
  • Once the commands are set, you can find them as shown in the image. So you can just select the one you require and need not enter them every single time.


Download the complete code here.

Note: Please change the file format to .py(python file) format before you upload the code to the Raspberry Pi.



Working


Image of Hardware Unpowered
Hardware Unpowered
Image of Hardware Powered
Hardware Powered

The SD card is inserted into the Raspberry Pi and is powered up. It connects to the computer through Wi-Fi.


Image of Python IDE
Python IDE



The code is written in a notepad and is saved with an extension .py which specifies that it is a python code file.


SSN Terminal
SSN Terminal

Open the SSN(Secure Socket Shell) terminal and enter the name of the python code file saved. Now start sending your commands from the telegram Bot created. The Raspberry Pi executes your commands and gives the required response. This way, we can share text and files by using Telegram with Raspberry Pi.


Image of Bot Output
Bot Output

Thus, the Raspberry Pi answering the given commands is shown in the above image. The specified responses are achieved. The back end execution of the code at the SSN terminal is shown below.


Image of SSN Terminal Output
SSN Terminal Output

Watch the video attached for a more firm approach.


Video By - Sai Parimal

The open-source Linux operating system of Raspberry Pi makes it handier in many #IoT projects. It is now widely used in Home and industrial #automation and also in the manufacture of many commercial products. We hope this was fun and interesting. Changes can be made to the code to execute many new commands. Do try them and know what all you can do with this tiny interesting device - The Raspberry Pi.

 




SEE ALSO



Order Electronics Projects


Want us to guide you through your project or make the project for you? Click on the button below or reach out to us via Call/WhatsApp at (+91) - 7600948607


You can -


  • Order Basic Electronics Projects

  • Order Embedded Systems Projects

  • Order IoT Projects

  • Order FPGA Projects

  • Order VLSI Projects

  • Order Image Processing Projects

  • Order Matlab Projects

  • Order TinkerCAD Projects

  • Order Proteus Projects


Click on the button below to fill out the project inquiry form -





Create Various Projects


Check out our Free Arduino Projects Playlist - Arduino Projects 

Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects 

Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects 

Check out our Free IoT Projects Playlist - IoT Projects 

Check out our Free Home Automation Projects Playlist - Home Automation Projects 

Check out our Free NodeMCu Projects Playlist - NodeMCu Projects 


Follow us -


Please do follow us i.e. #learnelectronicsindia to get daily updates about new blogs, videos, courses, products, offers, competitions, quizzes, and Internship Opportunities.




1,664 views2 comments

2 comentarios


Anushka Gupta
Anushka Gupta
26 jul 2023

This blog is an absolute gem! Learn Electronics India has curated a well-structured and engaging piece on using Telegram Bots with Raspberry Pi. I followed every step, and within no time, I had my own functional Telegram Bot. Great content.

Me gusta

LearnElectronics India simplifies complex concepts beautifully. Thank you!

Me gusta
bottom of page