20.01.2025, 13:07
(20.01.2025, 12:54)admin Wrote: You have a separate device that runs your Lua script. You can create a TCP server that forwards messages.
Server code (change token and chat_id as needed):
Code:require('socket') require('ssl.https') token = 'token' -- your token chat_id = '1234567' -- your chat id function telegram(message) local url = 'https://api.telegram.org/bot' .. token .. '/sendMessage' local data = 'chat_id=' .. chat_id .. '&text=' .. socket.url.escape(message) return ssl.https.request(url, data) end server = socket.bind('*', 8000) while true do client = server:accept() client:settimeout(1) message, err = client:receive('*a') if message then telegram(message) end client:close() end
Client code (change ip and message as needed):
Code:require('socket') ip = '127.0.0.1' message = 'hello' client = socket.tcp() client:settimeout(5) res, err = client:connect(ip, 8000) if res then client:send(message) end client:close()
Thanks, I will give this a try.
I still wonder why my existing script now fails while it has been working previously. Would a reboot help?