Delivery Notification
Charly's Column – Telegram API
Our columnist Charly K¸hnast doesn't want to be out when a package delivery service is standing at his front door with some goodies. When the courier rings, he can have the Telegram API send a notification to his mobile phone.
I mainly find notifications on my mobile phone annoying and have disabled most of them. But things are different when something requires my attention at home. The classic example is the doorbell: I want to know when a delivery person is standing at my front door even if I'm flooding my noise-killing headset with electric guitar music. I already solved this problem back in 2016 with a Raspberry Pi and described the setup in this column [1].
With my earlier solution, notifications reached me as Twitter direct messages, mainly because I didn't want to install a notification app just for this purpose. Twitter is already installed on my phone and provides a useful programming interface. However, Twitter is increasingly setting up hurdles for access to the API. For example, you now need to describe in a small, free text essay the purpose of your proposed use of the API. This may be understandable from the supplier's point of view, but I would prefer things to be a little simpler.
This explains why I now use the Telegram API [2]. Among other things, I can create bots that can be used to do many funny things. On top of this, I can get the bot to send me messages. You can create a bot by starting a chat with BotFather in the Telegram app (Figure 1).
Start with the /newbot
command. BotFather asks you for a name and a username for your bot. In return, you are sent a numeric ID and an access token – that is, a string that you have to pass to the API to identify yourself. It could look like this, for example:
919445171: AAFt4RTVEcI919fAI_5YGHX0A8QyQnY_fBA
The first few digits are your bot's numeric ID, followed by a colon and the access token. Now you have to start a chat with your bot in the app or the web interface [3]. This chat also has a numeric ID, which you need to discover. The curl
command from Listing 1 does the trick.
Listing 1
Start Telegram Chat
$ curl -X POST https://api.telegram.org/bot919445171:AAFt4RTVEcI919fAI_5YGHX0A8QyQnY_fBA/getUpdates
Note that you need to prefix your bot's numeric ID with the bot
keyword. For the most part, the long answer is unimportant for the purposes of this article, but it does contain a string reading "id":930313820
– this is the chat ID. Now you have all the information you need.
If you now want to automatically send a message to the bot chat, using a Bash script for example, the curl
call from Listing 2 is all it takes. The phone vibrates and a message appears on the display (Figure 2). Now, I'll never miss my deliveries again.
Listing 2
Sending a Message to the Bot Chat
$ curl -X POST 'https://api.telegram.org/bot919445171:AAFt4RTVEcI919fAI_5YGHX0A8QyQnY_fBA/sendMessage?chat_id=930313820&text="Hello world!"'
Infos
- "The sys admin's daily grind: Charly's doorbell Pi" by Charly Kühnast, Linux Magazine , issue 186, May 2016, p. 62, http://www.linux-magazine.com/Issues/2016/186/Charly-s-Column-Doorbell-Pi/(language)/eng-US
- Telegram API: https://core.telegram.org/api
- Telegram web interface: https://web.telegram.org
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Linux Kernel 6.13 Offers Improvements for AMD/Apple Users
The latest Linux kernel is now available, and it includes plenty of improvements, especially for those who use AMD or Apple-based systems.
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.