I want to send a message from a Python script via Telegram. I have tried to do that via telegram-cli, both the original version from vysheng and the patched version from luckydonald. With both of them I could successfully send messages to my phone. My problem is that:
- pytg2 didn't install cleanly (import DictObject fails, apparently author has this on pypi separately, but I stopped at that point), required Python 3 (unlike the rest of my project, but semi-acceptable) and can do a lot more than I need.
- I cannot get input into the tg console environment that is then executed there. Inputting via
<<EOF ... EOF
as in this SO question failed; the program opens on console, but doesn't output anything. Opening a port via -P option worked. I could then operate from nc environment (similar to tg wiki), but I'm not sure if it is wise to implement all these calls in my Python script.
I also found another script that echoes commands into tg (forgot source), but it didn't work either (similar behavior to
<<EOF
above)#!/bin/bash to=Matthias_SG msg="test message" tgpath=/home/matthias/dvl/tg cd ${tgpath} (echo "add_contact +xxx Matthias SG"; echo "msg $to $msg") | ${tgpath}/bin/telegram-cli -k tg-server.pub
So my question is: Should I go back to the older pytg? Can I fix the shell scripts or amend them to Python by inputting a stringIO from subprocess.call or popen? Is anyone out there using this in a robust fashion?
Background
- http://www.instructables.com/id/Raspberry-remote-control-with-Telegram/ showing how to reply to a 'ping' message with a 'pong' message using a Lua script. Worked for me.
- http://technofaq.org/posts/2014/06/chat-with-telegram-buddies-the-geeky-way-with-telegram-cli/