Created
July 15, 2015 04:38
-
-
Save k4ml/502f63ed1f5a63e9b5fe to your computer and use it in GitHub Desktop.
telegram-bot webscript.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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