I want to send the automatic reply messages in Telegram-CLI using modified lua script as below:
function ok_cb(extra, success, result)
end
function wait(seconds)
local start = os.time()
repeat until os.time() > start + seconds
end
function on_msg_receive (msg)
if msg.out then
return
end
if (string.find(msg.text, 'Hi there!')) then
wait(1)
send_msg (msg.from.print_name, 'Hello', ok_cb, false)
else
--do nothing
end
end
When I ran script above, if I got a message "Hi there!", the script will wait 1 second, then it will send reply with "Hello" message.
The script works fine when I set only one reply message. However, when I modified the script to add another reply message as below, the result is not as what I expected.
function ok_cb(extra, success, result)
end
function wait(seconds)
local start = os.time()
repeat until os.time() > start + seconds
end
function on_msg_receive (msg)
if msg.out then
return
end
if (string.find(msg.text, 'Hi there!')) then
wait(1)
send_msg (msg.from.print_name, 'Hello', ok_cb, false)
wait(3) --new command
send_msg (msg.from.print_name, 'World!', ok_cb, false) --new command
else
--do nothing
end
end
What I expect from the modified script is, when I received "Hi there!" message, the script will wait 1 second, then send "Hello" message, wait another 3 seconds, finally send "World!" message.
What actual happended is the script will wait 3 seconds, then send both "Hello" and "World!" at the same time.
Does anyone has any clues about this? thanks in advance