Skip to content

Instantly share code, notes, and snippets.

@k4ml
Created July 15, 2015 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save k4ml/502f63ed1f5a63e9b5fe to your computer and use it in GitHub Desktop.
Save k4ml/502f63ed1f5a63e9b5fe to your computer and use it in GitHub Desktop.
telegram-bot webscript.io
local tg_token = 'your token'
if request.query['admin_command'] == 'setURL' and request.query['pass'] == 'xxx' then
local response = http.request {
url = 'https://api.telegram.org/bot' .. tg_token .. '/setWebhook',
params = {
url='https://demo-xxxx.webscript.io/script'
},
method='post',
}
log(response.content)
return response.content
end
if not request.body then
return 'no data'
end
local data = json.parse(request.body)
local incoming_msg = data['message']['text']
local chat_id = data['message']['chat']['id']
local send_url = 'https://api.telegram.org/bot' .. tg_token .. '/sendMessage'
local response = http.request {
url = send_url,
data = {
chat_id = chat_id,
text = 'echo:' .. incoming_msg,
},
method='post',
}
log(response.content)
return "OK"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment