Learn how to use Telegram on a Raspberry Pi to send and receive messages, videos, and photos.
Telegram is an instant messaging service available on Android, iOS, and Windows phones.
It is also available on desktop systems including Windows, macOS, and Linux. Users can send messages, photos, videos, audio files, documents and stickers using Telegram.
With Telegram, users can send messages, photos, videos, audio files, documents, and stickers.
Telegram on Raspberry Pi
Since Telegram can be used on Linux, we can use it on Raspberry Pi and can send/receive messages, videos, photos, etc. Let's walk through how to set this system up.
Step 1: Open the Raspberry Pi Terminal
Open the terminal of Raspberry Pi and execute the following commands in the terminal:
- Sudo apt-get update
- Sudo apt-get upgrade
- Sudo apt-get install libreadline-dev
- Sudo apt-get install libconfig-dev
- Sudo apt-get install libssl-dev lua5.2 liblua5.2-dev libevent0dev make
Step 2: Clone Github Repository
Now clone a Github repository to proceed further:
- git clone --recursive https://github.com/vysheng/tg.git && cd tg
- ./configure
- Make
Now wait for a while and let the installer do the necessary things.
- cd tg
- bin/telegram-cli –k tg-server.pub –W
Step 3: Hook Up Your Phone
Now it will start by asking for your phone number. On entering the phone number, it will send a message to your phone with a confirmation code. Enter the confirmation code in the terminal to proceed.
Step 4: Send a Message
Now to send message, in terminal execute this command:
- msg Name_Lastname My message from Raspberry
The possibilities are endless. If you want to send any photo, you can try the following command:
- send_photo Name_LastName test.png
The point of installing Telegram on Raspberry Pi is that Telegram has good support for bots that can automate your work. For example, if you want to turn your home’s lights on or off using your smartphone, you can configure Telegram in such a way that it should turn lights on or off when you send a message on Telegram installed on a Raspberry Pi hooked up to your home system.
There are numerous commands that can be used with Telegram few of them are mentioned below.
What’s Next?
So starting with this simple Telegram setup, we can do a lot of things.
Suppose you're out and about and you want to check whether you left your gas stove on at home.
One option is to put some gas/temperature sensors in your kitchen and connect them with a microcontroller. Then connect the microcontroller to a Wi-Fi module to get internet connectivity. Then you'd need to write a full program for your microcontroller. You'd also need a dedicated app built for this purpose. This seems like a hard and time-consuming thing to do.
Why not go for a simple solution and use Telegram with Raspberry Pi? Your Raspberry Pi 3 has built in Wi-Fi—you just need to setup Telegram and, after connecting a gas sensor (easy to do with a Raspberry Pi), you're good to go. You can also get a gas sensor shield for Raspberry Pi since there are numerous shields available on the market.
So, there are endless possibilities and scenarios in which you can use Telegram on Raspberry Pi.
For messaging, however, here are the commands you'll need:
Messaging
- msg Text: Sends message to this peer
- chat_with_peer: Starts a one-on-one chat session with this peer. (/exit or /quit to end this mode)
- fwd: Forwards message to user. You can see message numbers starting client with -N.
- mark_read:Marks all received messages with peer as read rename_contact: Tries to rename contact. (If you have another device, it will be a fight.)
- add_contact: Tries to add contact to contact-list by phone delete_msg: Deletes message (not completely, though)
- restore_msg: Restores deleted message. (This is impossible for secret chats. It's also only possible for a short time after deletion—one hour, I think.)
Multimedia
- send_text: Sends text file as plain messages
- send_photo: Sends photo to peer
- send_video: Sends video to peerload_photo/load_video/load_video_thumb/load_audio/load_document/load_document_thumb: Loads photo/video/audio/document to download dir
- fwd_media: Sends media in your message. Use this to prevent sharing info about author of media (Though it's possible to determine user_id from the media, itself, it's not possible get access_hash of this user.)view_photo/view_video/view_video_thumb/view_audio/view_document/view_document_thumb - loads photo/video: Downloads dir and starts system default viewer
- set_profile_photo : Sets userpic. The photo should be square or the server will cut biggest central square part.
Group chat options
- chat_info: Prints info about chat
- chat_del_user: Removes user from chat
- chat_add_user: Adds user to chat
- rename_chat: Renames chat
- chat_set_photo: Sets group chat photo. Same limits as for profile photos.
- create_group_chat ...: Creates a groupchat with users. Use chat_add_user to add more users.
Search
- search pattern: Searches for pattern in messages with pee
- global_search pattern: Searches for pattern in all messages
Secret Chats
create_secret_chat : Creates secret chat with this user
set_ttl : Sets ttl to secret chat. Though client does ignore it, client on other end can make use of it
visualize_key: Prints visualization of encryption key. You should compare it to your partner's encryption key.
accept_secret_chat: Manually accept secret chat (only useful when starting with -E key)