This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Executing command on remote server fails
#6
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()
Reply


Messages In This Thread
RE: Executing command on remote server fails - by admin - 20.01.2025, 12:54

Forum Jump: