04.09.2022, 12:32
(01.06.2020, 14:29)Daniel Wrote: It was explained here https://forum.logicmachine.net/showthrea...13#pid2513 but lets make a clear version:Hi, Daniel
1. Install Telegram app
2. Find BotFather or go here https://t.me/botfather
3. Once in BotFather type /newbot and follow instructions. As a result you will get your token and your own bot link like t.me/yourname_bot Click on the link and type any message there
4. Open browser (preferably Firefox as it converts JSON automatically) and go here https://api.telegram.org/bot<token>/getUpdates. Replace <token> with your token. As a result you should have something like that. Save your chat ID
5. Create a user library called telegram. paste this code and replace your token and chat ID
Code:require('ssl.https')
local token = 'token' -- your token
local 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
6. Create an event based script and use this code to send message to Telegram app:
Code:require("user.telegram")
message = 'test message'
res, err = telegram(message)
log(res, err)
I just performed above recommendations. All stages were OK. But during attempt to send telegram message I obtained error - see attachments. Could you explain me the reason and how to resolve it. Thank you in advance. KR Oleg Razumovskyi.