vysheng / tg

telegram-cli
GNU General Public License v2.0
6.45k stars 1.53k forks source link

how does the daemon work #255

Open politieman opened 10 years ago

politieman commented 10 years ago

can i run the daemon and for example send and receive messages through a script?

vysheng commented 10 years ago

I am adding listening socket to client right now. Probably it will be done in a couple of days.

Right now client only can work with commands from stdin. Also you can write lua script, that will check some file peridically and make actions depending of file contents.

vysheng commented 10 years ago

Try -P option for opening listening socket. It is untested though.

trifox83 commented 10 years ago

I tried to run the daemon mode as well with the -P option, it says user telegramd cannot be found. I'm able to do sending and safe_quit via stdin, but when it comes to reading the reply and getting read receipt, I'm still clueless, so I'm hoping the daemon mode is able to, somehow give me that option.

vysheng commented 10 years ago

Telegram-cli tries to setuid if is run as root. If there is no -u option it tries to use user telegramd.

politieman commented 10 years ago

thanks for the fast reply, not sure yet how to use the daemon but i supose i should look into linux sockets?

vysheng commented 10 years ago

I've written small page about how I run it as daemon. Not sure if it is suitable for you, but at least you can look there

https://github.com/vysheng/tg/wiki/Running-as-daemon

Abuarif commented 9 years ago

Hi,

Alternatively, I am using Screen using the following steps:

yum install screen

upon successful installation, type cmd

screen -S Telegram ./bin/telegram-cli

change_user_group: can't find the user telegramd to switch to Telegram-cli version 1.0.5, Copyright (C) 2013-2014 Vitaly Valtman Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type show_license'. This is free software, and you are welcome to redistribute it under certain conditions; typeshow_license' for details.

The prompt '>' is only appears after Telegram registration.

You can verify your screen is running by

screen -ls

Test sending a message to your screen using

screen -S Telegram -X stuff "msg " screen -S Telegram -X stuff "$(printf \r)"

Good luck.

ImTheDeveloper commented 9 years ago

It is useful to also note that if you use screen you can use the logfile and logflush commands to write all contents of the screen session to a log file. I use this to run an irc telegram bot. The logflush is quite happy running at a 0 settings which is "realtime logging". I then parse out any sent/returned messages via regex. Works extremely well!

ImTheDeveloper commented 9 years ago

Just noticed since the latest commits the log file is dumping a lot of > in the file every time the screen session flushes. It didn't used to do this with the code I had been using a few months ago. Has something been changed? Is the timed lua scripts causing this? It suggests something is firing every few seconds @vysheng any ideas?

vysheng commented 9 years ago

I'll see. Probably prompt update. You can use '-R' key that disables readline. It would alse diable promt

ImTheDeveloper commented 9 years ago

@vysheng thanks for getting back to me, I'll give the -R key a test tonight. I'm currently running from an old git version which seems to work fine back in April (prior to the big lua changes) but it would be good to use the latest git version with the new features also.

ImTheDeveloper commented 9 years ago

@vysheng Thanks for the fix the -R key solves the issue for me perfectly. Do you have any examples (maybe in the wiki) of sending messages via telnet or other means to the port and receiving messages back? If I can complete this last bit I can completely ditch my screen logging option :+1:

vysheng commented 9 years ago

It is just text protocol. You can use telnet to try. Commands are just the same as from terminal.

kreuzebek commented 9 years ago

Run telegram-cli as daemon: bin/telegram-cli -vvvvRC -k tg-server.pub -W -dL tg.log -P 1234 &

Command Line to access Send msg: echo -e 'msg Firstname_Lastname Hello World\r\n' | nc.traditional -w 1 127.0.0.1 1234 Get history: echo -e 'history Firstname_Lastname\r\n' | nc.traditional -w 1 127.0.0.1 1234

<<< or >>> unread ««« or »»» read

vysheng commented 9 years ago

\r is not necessary.