(04.03.2021, 17:17)admin Wrote: See this example: https://forum.logicmachine.net/showthrea...4#pid17944
Replace name/filename as needed, set ctype to text/csv and finally replace /sendPhoto with /sendDocument in the URL.
hello admin
but how to attach the CSV file in the script?
I tried mentioned code but I got this in the logs :
params = {
{
name = 'chat_id',
value = chat_id,
},
{
name = 'document',
filename = 'report.csv',
ctype = 'text/csv',
value = filedata,
}
}
boundary = os.date('%d%m%Y%H%M%S')
body = { '--' .. boundary }
for _, param in ipairs(params) do
line = string.format('Content-Disposition: form-data; name=%q', param.name)
if param.filename then
line = string.format('%s; filename=%q', line, param.filename)
end
body[ #body + 1 ] = line
if param.ctype then
body[ #body + 1 ] = string.format('Content-Type: %s', param.ctype)
end
params = {
{
name = 'chat_id',
value = chat_id,
},
{
name = 'document',
filename = 'report.csv',
ctype = 'text/csv',
value = filedata,
}
}
boundary = os.date('%d%m%Y%H%M%S')
body = { '--' .. boundary }
for _, param in ipairs(params) do
line = string.format('Content-Disposition: form-data; name=%q', param.name)
if param.filename then
line = string.format('%s; filename=%q', line, param.filename)
end
body[ #body + 1 ] = line
if param.ctype then
body[ #body + 1 ] = string.format('Content-Type: %s', param.ctype)
end
thank you admin for your time
I want to insert the log object script such as this one
I tried but I still not tough in LUA
logtime = os.time() - 60 * 60
-- Список объектов по id
objects = {}
-- получаем объекты по которым ведется запись действий
query = 'SELECT address, datatype, name FROM objects WHERE disablelog=0'
for _, object in ipairs(db:getall(query)) do
objects[ tonumber(object.address) ] = {
datatype = tonumber(object.datatype),
name = tostring(object.name or ''),
}
end
-- получаем список действий по объектам
query = 'SELECT src, address, datahex, logtime, eventtype FROM objectlog WHERE logtime >= ? ORDER BY id DESC'
for _, row in ipairs(db:getall(query, logtime)) do
object = objects[ tonumber(row.address) ]
-- находим соответствие между объектом и типом события – запись по групповому адресу
if object and row.eventtype == 'write' then
datatype = object.datatype
-- проверяем что тип данных установлен
if datatype then
-- раскодируем данные
data = knxdatatype.decode(row.datahex, datatype)
-- удаляем null символы из char/string типов
if datatype == dt.char or datatype == dt.string then
data = data:gsub('%z+', '')
-- конвертируем date в формат DD.MM.YYYY
elseif datatype == dt.date then
data = string.format('%.2d.%.2d.%.2d', data.day, data.month, data.year)
-- time в HH:MM:SS
elseif datatype == dt.time then
data = string.format('%.2d:%.2d:%.2d', data.hour, data.minute, data.second)
end
else
data = ''
end
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:
Hi, Daniel
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.
1. Fallow instruction in first post how to create bot and your TOKEN
2. Create user library tgupdates and paste this code
Code:
return function(token, callback)
local json = require('json')
local socket = require('socket')
local ssl = require('ssl')
local host = 'api.telegram.org'
local tgupdateid = storage.get('tg_update_id')
local uri = '/bot' .. token .. '/getUpdates'
local sock = socket.tcp()
sock:settimeout(5)
local res, err = sock:connect(host, 443)
if not res then
sock:close()
log('connect failed', err)
os.sleep(5)
return
end
Modify the function to run your actions based on revived text. UserID is a unique number which can be used for authorization/restrictions. username is not a unique as it is just name in your telegram account. It can be duplicated.
Hello, Daniel!
I have LM2 upgraded to 20181002 version.
I used your code for older fw.
Unfortunately, I have reply:
------------
TGtest 06.01.2024 18:30:00
* arg: 1
* nil
* arg: 2
* string: Try again
* arg: 3
* nil
TGtest 06.01.2024 18:30:04
* arg: 1
* nil
* arg: 2
* string: Try again
* arg: 3
* nil
--------------
Could you advice me the right way :-)
Thank you in advance,
KR, Oleg
Hello, Daniel!
I have LM2 upgraded to 20181002 version.
I used your code for older fw.
Unfortunately, I have reply:
------------
TGtest 06.01.2024 18:30:00
* arg: 1
* nil
* arg: 2
* string: Try again
* arg: 3
* nil
TGtest 06.01.2024 18:30:04
* arg: 1
* nil
* arg: 2
* string: Try again
* arg: 3
* nil
--------------
Could you advice me the right way :-)
Thank you in advance,
KR, Oleg
Hello Daniel!
I've found solution in your previous post "Check that you have DNS and gateway configured correctly in System config > Network > Interfaces. "
It works! Have a nice day! KR Oleg