3

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 telegram command line

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
2
  • 1
    For very simple cases, you may be able to pipe a command sequence via standard input, either using echo, printf (better), or a here-document using cat. For more complicated interactions, you will probably need to use something like expect Nov 22, 2016 at 23:09
  • Welcome 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!
    – Elder Geek
    Nov 22, 2016 at 23:31

1 Answer 1

6

To write a script to send messages over telegram-cli, you need to do the following:

  1. Move to the directory where telegram-cli is:

  2. Open telegram-cli with your key

  3. Load your contact list with -W

  4. 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

4
  • you sir, saved my day May 17, 2017 at 20:35
  • What 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. Sep 18, 2020 at 12:57
  • 1
    If 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/…
    – M. Becerra
    Sep 18, 2020 at 13:49
  • 1
    any better way to do this in 2022? Apr 12, 2022 at 10:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .