vysheng / tg

telegram-cli
GNU General Public License v2.0
6.44k stars 1.52k forks source link

How use a Lua script to notify me when one user is online? #1263

Open euphoria360 opened 7 years ago

euphoria360 commented 7 years ago

Hi. I want to write a Lua script to notify me when a user gets online or offline. these kinds of info appear in telegram-cli like this:

User John Doe offline (was online [2016/12/16 16:26:53])

Seems I need to use function on_user_update in lua to achieve this. By looking into some lua script examples in here and on the internet, this is how far I've got:


function on_msg_receive (msg)
    if msg.out then
        return
    end
    if (msg.text=='ping') then
       send_msg (msg.from.print_name, 'pong', ok_cb, false)
    end
    if (msg.text=='bot') then
        os.execute('/opt/myscripts/telegram-sendmsg.sh hiiii')
    end
end

function on_our_id (id)
end

function on_secret_chat_created (peer)
end

function on_user_update (user)
    if (user=='John_Doe') then
        os.execute('/opt/myscripts/telegram-sendmsg.sh iamonline')
    end
end

function on_chat_update (user)
end

function on_get_difference_end ()
end

function on_binlog_replay_end ()
end

Now when i send "bot" i get a hiiii but seems function on_user_update doesnt do anything here.

P.S the command /opt/myscripts/telegram-sendmsg.sh sends me anything i throw at it via telegram bot API

What am I doing wrong?

rihak commented 7 years ago

Same for me. It seems like the code inside on_user_update() is never called, at least when a contact changes his online status. I actually don't know if "on_user_update" means "on online status changed".

Anyone? :(