title: Sending messages with Telegram - APIs or CLI?
body: <p>I would like to be able to send a message to a group chat in Telegram. I want to run a python script (which makes some operations that already works) and then, if some parameters have some values the script should send a message to a group chat through Telegram. I am using Ubuntu, and Python 2.7</p>
  
  <p>I think, if I am not wrong, that I have two ways to do that: </p>
  
  <ul>
  <li><p>Way One: make the Python script connect to the Telegram APIs directly and send the message (<a href="https://core.telegram.org/api">https://core.telegram.org/api</a>). </p></li>
  <li><p>Way Two: make the Python script call the Telegram's CLI (<a href="https://github.com/vysheng/tg">https://github.com/vysheng/tg</a>), pass some values to this and then the message is sent by the Telegram's CLI. </p></li>
  </ul>
  
  <p>I think that the first way is longer, so a good idea might be using the Way Two. </p>
  
  <p>In this case I really don't know how to proceed. 
  I don't know lots about scripts in linux, but I tried to do this: </p>
  
  <pre><code>#!/bin/bash
  cd /home/username/tg
  echo "msg user#******** messagehere" | ./telegram
  sleep 10
  echo "quit" | ./telegram
  </code></pre>
  
  <p>this works at a half: it sends the message correctly, but then the process remains open. And second problem, I have no clue on how to call that from python and how to pass some value to this script. The value that I would like to pass to the script is the "messagehere" var: this would be a 100/200 characters message, defined from inside the python script. </p>
  
  <p>Does anyone has any clues on that? 
  Thanks for replies, I hope this might be useful for someone else.  </p>