Installation:
Read this tutorial, we use this configuration as start point.
To intercept a new incoming message we create a file action.lua
“Lua is a powerful, fast, lightweight, embeddable scripting language.
Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.” From https://www.lua.org.
sudo nano /home/pi/tg/action.lua
with this content
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
end
function on_our_id (id)
end
function on_secret_chat_created (peer)
end
function on_user_update (user)
end
function on_chat_update (user)
end
function on_get_difference_end ()
end
function on_binlog_replay_end ()
end
Save and exit, when incoming text message is “ping”, Telegram answers us with a text message containing “pong”.
move in tg
cd /home/pi/tg
then type
bin/telegram-cli -k tg-server.pub -W -s action.lua
Try to send a message, if all goes well, Telegram answers only on “ping” and not “PING”, we should see something like this
Ok, let’s do something more interesting.
Install the Raspberry Camera, see this tutorial, then create a new folder where we will save the captured photos.
sudo mkdir /home/pi/camera
create a new file camera.sh
sudo nano /home/pi/camera/camera.sh
with this content
#!/bin/bash
raspistill -w 800 -h 600 -o /home/pi/camera/photo.jpg
save and exit, give it execution permissions
sudo chmod -R 0655 /home/pi/camera/camera.sh
Edit action.lua
sudo nano /home/pi/tg/action.lua
add this lines in function on_msg_receive
if (msg.text=='photo') then
os.execute('/home/pi/camera/camera.sh')
send_photo (msg.from.print_name, '/home/pi/camera/photo.jpg', ok_cb, false)
end