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: https://github.com/xs-embedded-llc/cdbus
  2. Clone and build L2DBUS: https://github.com/xs-embedded-llc/l2dbus
  3. Clone and build Telegram CLI: https://github.com/vysheng/tg
  4. Clone: https://github.com/slp/tg-notify
  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!

4 thoughts on “Getting freedesktop notifications from Telegram CLI

  1. Hola Sergio, antes que nada felicidades por el blog y gracias por hacer la versión FOSS del Telegram para Android, va de maravilla!
    Sobre las notificaciones para la versión de escritorio, me ha gustado la idea pero no tenia ganas de compilar las dos librerías que requería el script así que he hecho un fork (apenas quatro líneas) de este, puedes verlo aquí.
    Saludos.

    1. Me alegro de que te hayan sido de utilidad.

      Efectivamente, me empeñé en evitar el llamar a otros procesos vía popen, y a cambio metí dos librerías que no vienen “de serie” en las distros. Como dices, tu solución resulta más fácil de instalar.

      Gracias por el aporte!

  2. Buenos dias,
    Disculpa mi ignorancia, he seguido atentamente tus post sobre Telegram y he entendido todo
    lo que en ellos querias poner de manifiesto, pero la verdad es que no tengo ni la menor idea de como implementar el secure_delete que has sacado para conseguir que los mensajes no se almacenen en el unalocated de la base de datos de telegram en el propio movil.
    Me he bajado de tu repositorio los dos zips, tu version de Telegram y el addon secure_delete (permiteme que use esta terminologia) pero no se que pasos he de dar para poder instalar esta version mas segura de Telegram en mi movil.
    CUando puedas te agradeceria que me dieras unas pauta para poder realizarlo.
    Gracias de antemano por tu ayuda y por tu labor de divulgacion. Un slaudo !!

  3. I just wanted to say thanks here for providing the community with the FOSS-friendly version of Telegram in F-Droid. ❤

Leave a Reply

Your email address will not be published. Required fields are marked *