Getting freedesktop notifications from Telegram CLI


NOTE: In the comments section, AleixDev proposes a simpler solution, calling an external process. Take a look at it if you don’t want to build cdbus and l2dbus by yourself.

Lately, Telegram is gaining a lot of traction as an alternative to WhatsApp. From my point of view, that’s quite cool for a variety of reasons, specially for features like secret chats, but also due to the (reasonably) open nature of its protocol.

This openness will surely lead to a widespread adoption of the protocol, specially on Free Software IM clients (something that WhatsApp has stupidly rejected from its very beginnings, which is something that, IMHO, will hurt their business in the long term), making it available on multiple devices and Operating Systems, effectively ending vendor dictated restrictions and the pain of being forced to use a mobile touchscreen even when you’re in front of a computer with a full size physical keyboard.

In my particular case, until the protocol is implemented in Kopete (I’d like to do this work myself, but I don’t the time right now), I’m using the CLI client created by Vitaly Valtman. Using a command line program for messaging may look awkward to some people, but I’m quite comfortable with it. The only thing I was missing is being notified when a message arrives, so I’ve decided to do something about this.

It was clear to me that the better approach would be to create a DBUS connection for sending a notification through it, something that both KDE and GNOME desktops would know how to interpret and show. My initial intention was to modify the source code to implement this function, but since tg-cli supports Lua, a language I’ve head a lot about but I’ve never actually used, I’ve decided to give it a try, which also saves me from patching the source code.

Installing Telegram CLI with notifications

  1. Clone and build CDBUS: [](
  2. Clone and build L2DBUS: [](
  3. Clone and build Telegram CLI: [](
  4. Clone: [](
  5. **(Optional)** Grab a cool icon (you can download the [official app logo]( from its repo), place it somewhere, and update the "icon_file" variable in _notify.lua_ to point to it (use full path, not relative).
  6. Run Telegram CLI with notify.lua: `./telegram -s notify.lua`

Have fun!