Executing script with passed arguments in LUA to control Raspberry PI 3

Viewed 233

I am trying to use Telegram CLI to "control" my virtual Raspberry PI 3. I am messaging the telegram CLI with my smartphone and managed to send "Ping" to receive "Pong" on my phone by following: https://pimylifeup.com/raspberry-pi-telegram-bot/

I created this script: https://www.raspberrypi.org/forums/viewtopic.php?t=252300 So i can play videos on my Raspberry PI (it works when calling directly from CMD)

My idea is to send a message to the Raspberry PI in format: PLAY-youtube-link.com, to catch that message with LUA and call the the script to play the youtube video.

The script to play the youtube video is saved as "ytplayvlc":

#!bin/bash
youtube-dl - U -f $2 -o - "$1" | vlc -

The action script is saved in a child folder /tg and called "actions.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)
     end
     local message = msg.text
     if (message.match(message, "PLAY-")) then
         send_msg (msg.from.print_name, 'Okay! This might take a second..', ok_c$, ok_cb, false)
         local link = string.match(message, "-(.*)")
         local command = [["../ytplayvlc " .. link .. " 18"]]
         os.execute(command)
     end
end
function on_our_id(id)
end
function on_secret_chat_update(user, what_changed)
end
function on_user_update(user_what_changed)
end
function on_chat_update(user, what_changed)
end
function on_get_difference_end()
end
function on_binlog_replay_end()
end

I start telegram CLI with:

bin/telegram-cli -k -N --enable-msg-id tg-server.pub -W -a actions.lua

the Ping-Pong works nicely, but when i send a command to play the youtube video I receive the msg "Okay! This might take a second.." but then nothing happens. Also, when I use Ping-Pong or the youtube command, right after I receive the above mentioned messages I get a message in CMD "lua:: attempt to call a nil value"

I don't know why and if anyone has an idea please let me know.. I am not experienced in any of the above mentioned technologies and I apologize if I missed some info. Thank you.

1 Answers

I solved the issue!! I removed the squared brackets around the command. SO now that line is : local command = "../ytplayvlc " .. link .. " 18"

Related