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:

  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

Share:
12,873

Related videos on Youtube

LuigiCali
Author by

LuigiCali

Updated on September 18, 2022

Comments

  • LuigiCali
    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 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
    
    • steeldriver
      steeldriver over 7 years
      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
    • Elder Geek
      Elder Geek over 7 years
      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!
  • Juggernaut
    Juggernaut almost 7 years
    you sir, saved my day
  • Alex van Es
    Alex van Es over 3 years
    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.
  • M. Becerra
    M. Becerra over 3 years
    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/…
  • user2180794
    user2180794 about 2 years
    any better way to do this in 2022?