I am expanding on the following example to communicate with my Raspberry Pi using Telegram:
http://www.instructables.com/id/Raspberry-remote-control-with-Telegram/
I use the following bit of code:
#!/usr/local/bin/lua
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)
elseif (msg.text=='Photo') then
os.execute[["scriptToTakePhoto]]
send_photo (msg.from.print_name, '/pathToPhoto.jpg', ok_cb, false)
send_msg (msg.from.print_name, 'Here you go!', ok_cb, false)
elseif (msg.text=='Hello'or msg.text =='Hi') then
send_msg (msg.from.print_name, 'Hi, how can I help you?', ok_cb, false)
else
math.randomseed(os.time())
randNum = math.random(0,5)
if randNum == 0 then
messageText = "Random Text"
elseif randNum == 1 then
messageText = "Random Text"
elseif randNum == 2 then
messageText = "Random Text"
elseif randNum == 3 then
messageText = "Random Text"
elseif randNum == 4 then
messageText = "Random Text"
elseif randNum == 5 then
messageText = "Random Text"
end
send_msg (msg.from.print_name, messageText, ok_cb, false)
end
end
I get the following output:
Ping->Pong
Hi->Hi, how can I help you?
Hello->Hi, how can I help you?
[Anything else]->Random Text
Photo->Here you go! [photo is recieved] Random Text
So when I send any of the message within an if/ifelse other than Photo, the last else isn't reached. When I send 'Photo', it goes into that ifelse as well as the last else. Can't figure out why.