Skip to content

Instantly share code, notes, and snippets.

@gnumoksha
Last active December 5, 2021 14:24
Show Gist options
  • Save gnumoksha/a95f237d82733ce1f748 to your computer and use it in GitHub Desktop.
Save gnumoksha/a95f237d82733ce1f748 to your computer and use it in GitHub Desktop.
Telegram-cli example usage

Install the required packages

apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev make git -y

Compile

cd /usr/src
git clone --recursive https://github.com/vysheng/tg.git
cd tg
# The latest build seems broken
#git checkout -b tgviacron 01f5d9a3b671edc15a5cff285601115845489985
#git submodule update --init --recursive
./configure
make
mkdir viacron
cp bin/telegram-cli viacron/
cp tg-server.pub viacron/
cd viacron

Create config file /usr/src/tg/viacron/telegram.config

default_profile = "viacron";

viacron = {
    config_directory = "/usr/src/tg/viacron/";
};

Authorize:

./telegram-cli -k tg-server.pub -c telegram.config

Get the id

This guide send a message for user or group id because this decrease the errors.

for user

user_info User_Name_In_Contact_list
User User Name updated photo
User User Name updated name
User User Name @userFoo (#1234567):
        real name: User Name
        phone: 551122223333
        online (was online [2015/05/03 07:16:54])

1234567 in this case

for group

> chat_info Enterprise_Name_In_Contact_List
Chat Enterprise 123 updated admin
Chat Enterprise 123 updated members
Chat Enterprise 123 (id 1234567) members:
                Usuario Tal invited by Tobias Sette at [2015/05/14 02:48:45]
                Tobias Sette invited by Tobias Sette at [2015/05/14 02:48:45] admin
User Tobias Sette offline (was online [2015/05/14 02:53:59])

1234567 in this case

Create /usr/src/tg/viacron/telegram_standalone.sh

#!/bin/bash
# See
# https://github.com/gnumoksha/zabbix_utils/blob/master/gnu%2Blinux/alertscripts/

MAIN_DIRECTORY="/usr/src/tg/viacron/"
USER=$1
SUBJECT=$2
TEXT=$3

cd $MAIN_DIRECTORY
if [[ $? -ne 0 ]]; then
        echo "Error to enter in the main directory"
        exit 1
fi

./telegram-cli -k tg-server.pub -c telegram.config -WR -e "msg $USER $SUBJECT" || exit 1

exit 0

Note: is better to use parameter -U yourSystemUser in telegram-cli. Reduces the possibilities of error.

Change permissions:

chmod +x /usr/src/tg/viacron/telegram_standalone.sh
chown -R yourUser: /usr/src/tg/

Command line usage:

Use user# prefix for users, for groups use chat#.

/usr/src/tg/viacron/telegram_standalone.sh user#12345 "GNU is not unix"
Copy link

ghost commented Apr 17, 2018

Hi there.
It seems that there is a snappy package for tg-cli now, so there is no need to clone and compile repo, Tadaaaa! :D
https://www.omgubuntu.co.uk/2016/10/use-telegram-cli-in-terminal-ubuntu

@Madhava-mng
Copy link

hellow , how can I change the prompt interface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment