Telegram instant message gateway
Contents
Overview
Telegram is a cell phone app to send instant messages (Like WhatsApp app). Telegram is open, and allows to send instant messages by scripts. So we install telegram-cli on server to send notification directly to Tech team cell phones.
Solution building
Telegram-cli download and compilation
We download and compile the client.
apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev libpython-dev make git clone --recursive https://github.com/vysheng/tg.git && cd tg ./configure make
Installation as a daemon
We create the user telegram and copy execution files:
adduser telegramd mkdir /var/lib/telegram-daemon chown telegramd:telegramd /var/lib/telegram-daemon mkdir /usr/share/telegram-daemon mkdir /usr/share/telegram-daemon/bin cp bin/telegram-cli /usr/share/telegram-daemon/bin/ cp start-telegram-daemon /usr/share/telegram-daemon/bin mkdir /etc/telegram-daemon mkdir /var/log/telegram-daemon chown telegramd:telegramd /var/log/telegram-daemon mkdir /etc/telegram-cli cp server.pub /etc/telegram-cli/server.pub
Service init file /etc/init.d/telegram-daemon:
root@support:/etc/init.d# cat telegram-daemon #! /bin/sh ### BEGIN INIT INFO # Provides: telegram-daemon # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: telegram daemon # Description: telegram daemon ### END INIT INFO # Author: fizzzel # actions case "$1" in start) echo "Telegram daemon is starting..." /usr/share/telegram-daemon/bin/telegram-cli vvvvRC -k /etc/telegram-cli/server.pub -W -dL /dev/null -P 1234 & echo "...done" ;; stop) echo "stopping telegram daemon..." sudo pkill telegram echo "..done" ;; restart) echo "stopping telegram daemon..." pkill telegram sleep 1 pkill telegram echo "..done -- restarting..." /usr/share/telegram-daemon/bin/telegram-cli vvvvRC -k /etc/telegram-cli/server.pub -W -dL /dev/null -P 1234 & echo "...done" ;; esac exit 0
When daemon is started, we can send instant message with telegram-cli by telnet or nc to port 1234.
references
Daniel Simao (talk) 14:41, 20 July 2018 (EDT)