How to write a script to send messages over telegram-cli?
12,873
To write a script to send messages over telegram-cli, you need to do the following:
Move to the directory where telegram-cli is:
Open telegram-cli with your key
Load your contact list with
-W
Send the message to anyone on your contact list previously loaded
To achieve that:
cd /path/to/tg && bin/telegram-cli -W server.pub -e "msg contact message"
or
cd /path/to/tg && (sleep 1; echo "contact_list"; sleep 1; echo "msg contact message") | bin/telegram-cli -W -k server.pub
More info here: https://github.com/vysheng/tg
Related videos on Youtube
Author by
LuigiCali
Updated on September 18, 2022Comments
-
LuigiCali over 1 year
I don't know how to explain myself but I need to send scheduled messages via telegram so I downloaded the telegram client to send messages via terminal. I wrote a bash script that opens the client, everything here is going according to plan then it opens the telegram command line and my script doesn't run accordingly. How can I make work?
This is the script, nothing difficult:
#!/bin/bash cd /home/ospite/tg bin/telegram-cli -k tg-server.pub //opening telegram client sleep 30 chat_with_peer Antonio //it doesn't work because it's not the debian shell anymore done
-
steeldriver over 7 yearsFor very simple cases, you may be able to pipe a command sequence via standard input, either using
echo
,printf
(better), or a here-document usingcat
. For more complicated interactions, you will probably need to use something like expect -
Elder Geek over 7 yearsWelcome to askubuntu!Please open a terminal and issue the command
lsb_release -a
and edit the output into your post. Thank you for helping us help you!
-
-
Juggernaut almost 7 yearsyou sir, saved my day
-
Alex van Es over 3 yearsWhat if I want to make the actually message a variable that is passed along? I tried /telegram-cli -W server.pub -e 'msg @user $1' But the only message sent then is $1.. not the actual text.
-
M. Becerra over 3 yearsIf you use single quotes, $1 is interpreted literaly, meaning, it is not interpreted as a reference to a variable. Use double quotes instead. See gnu.org/software/bash/manual/html_node/…
-
user2180794 about 2 yearsany better way to do this in 2022?