Page 2 of 2

Re: A little Small Lua Telegram Library

Posted: Saturday 16 March 2019 9:53
by emme
WOW!!! this is awesome!!!

And probably will fix my connection problem I do have (fix date for my internet connection is March 29th.... :evil: :evil: :evil: :evil: )
I'm actually running a 3G (10Mbit) connection and my domoticz system is under pressure for a lot of queued messages and external connection.

I'll try this immediately and see if this solve that issue!!!

Ciao
M

Re: A little Small Lua Telegram Library

Posted: Wednesday 27 March 2019 14:16
by emme
Created page on the Wiki about the library

Re: A little Small Lua Telegram Library

Posted: Tuesday 23 April 2019 12:13
by snuiter
Hi Emme,
you need to rename the page so it is easer to find ;)

Telegra lua library

The M is missing, I guess I will never forget your forum name now ;)

Re: A little Small Lua Telegram Library

Posted: Thursday 25 April 2019 15:39
by emme
:o :o :o :o :o :o :o

I'm totally unfamiliar with mediawiki.....

And with the alphabet :D :D

Re: A little Small Lua Telegram Library

Posted: Saturday 27 April 2019 21:43
by zicht
Found the wiki, nice job.

ps
If you update it with the simple addons i posted a couple of messages back you make sure it does not slow down domoticz when the network is lagging

Re: A little Small Lua Telegram Library

Posted: Tuesday 30 April 2019 22:06
by freijn
Guys,

Can you please help me ?

I have copied the library Telegram.lua and put it in /home/pi/domoticz/scripts/lua.

but now... where do I put this code ? :

package.path = package.path .. ';' .. '/home/pi/domoticz/scripts/lua/?.lua'
local telegram = require('Telegram')

and would just like to exe
telegram.sendText(123456789,'Hallo World!')

many thanks for your time ,

Frank

Re: A little Small Lua Telegram Library

Posted: Thursday 02 May 2019 8:01
by emme
freijn wrote: Tuesday 30 April 2019 22:06 but now... where do I put this code ? :
put the

Code: Select all

package.path = package.path .. ';' .. '/home/pi/domoticz/scripts/lua/?.lua'
local telegram = require('Telegram')

on top of your script where you want to send the

Code: Select all

telegram.sendText(123456789,'Hallo World!')
that's all

Re: A little Small Lua Telegram Library

Posted: Monday 21 September 2020 20:46
by riko
Cool script, exactly what I was looking for. I only have one question left:

Can I send the message to multiple IDs in one line?

Code: Select all

telegram.sendText(telegram.getId('rik'), 'This is a *TEST* Message')
I have tried:

Code: Select all

telegram.sendText(telegram.getId('rik', 'name2'), 'This is a *TEST* Message')
Which is not working. Or is the only method to copy the telegram send line each time?

Re: A little Small Lua Telegram Library

Posted: Monday 21 September 2020 21:28
by emme
You have ti duplicate the line at the Moment

I moved back to domoticz After a while into another system

I could have a look into it and duplicate It
Ciao
M

Re: A little Small Lua Telegram Library

Posted: Wednesday 23 September 2020 19:50
by riko
emme wrote: Monday 21 September 2020 21:28 You have ti duplicate the line at the Moment

I moved back to domoticz After a while into another system

I could have a look into it and duplicate It
Ciao
M
Thanks for your quick reply. I'll duplicate the lines for now. Please let me know when you have found another solution!

Re: A little Small Lua Telegram Library

Posted: Thursday 24 September 2020 21:28
by Xenomes
emme wrote: Monday 08 January 2018 21:46 added function to send docs and a chatid addressbook to fast references in your code
I have add sendvideo support to your script and embedded the addressbook function.

Code: Select all

local teleTok   = 'Enter your Bot Token here'
local snapFile  = '/home/pi/domoticzSnap'
local snapVideo = '/var/tmp/video.mp4'
local domoReq   = 'http://localhost:8080/camsnapshot.jpg'
local tgAb = {}
tgAb['myName1'] = 222222222
tgAb['myName2'] = 111111111
tgAb['myGroup'] = -00000000
local cameraUri = {}
cameraUri['cam1'] = 'rtsp://user:password@ip-cam/channel'
cameraUri['cam2'] = 'rtsp://admin:[email protected]/12'
cameraUri['cam3'] = 'rtsp://admin:[email protected]/1'

local telegram ={};

    function getId(name)
        return tgAb[name]
    end

    function getCam(num)
        return cameraUri[num]
    end
	
	-- example: telegram.sendText('myName1', 'Test message')
    function telegram.sendText(chatId, message)
        return os.execute('curl --data chat_id='..getId(chatId)..' --data parse_mode=Markdown --data-urlencode "text='..message..'"  "https://api.telegram.org/bot'..teleTok..'/sendMessage" ')
    end

	-- example: telegram.sendImage('myName1', 1, 'Test message')
    function telegram.sendImage(chatId, camChannel, message)
        os.execute('wget -O "'..snapFile..camChannel..'.jpg" "'..domoReq..'?idx='..camChannel..'"')
        return os.execute('curl -s -X POST "https://api.telegram.org/bot'..teleTok..'/sendPhoto?chat_id='..getId(chatId)..'" -F photo="@'..snapFile..camChannel..'.jpg" -F caption="'..message..'"')
    end

	-- example: telegram.sendDoc('myName1', '/home/pi/file.pdf', 'Test message')
    function telegram.sendDoc(chatId, filePath, message)
        return os.execute('curl -s -X POST "https://api.telegram.org/bot'..teleTok..'/sendDocument?chat_id='..getId(chatId)..'" -F document="@'..filePath..'" -F caption="'..message..'"')
    end

	-- example: telegram.sendVideo('myName1', 'cam1', 10, 'Test message')
    function telegram.sendVideo(chatId, cameraNum, recTime, message)
        os.execute('ffmpeg -y -i "'..getCam(cameraNum)..'" -r 30 -vcodec copy -an -t '..recTime..' "'..snapVideo..'"')
        return os.execute('curl -s -X POST "https://api.telegram.org/bot'..teleTok..'/sendVideo?chat_id='..getId(chatId)..'" -F video="@'..snapVideo..'" -F caption="'..message..'"')

    end

return telegram

Re: A little Small Lua Telegram Library

Posted: Sunday 03 January 2021 13:35
by emme
that's great!!!
thenk you

Re: A little Small Lua Telegram Library

Posted: Friday 06 December 2024 8:50
by cimbali
Very good library. This inspired to me to make it one similar for sending message & pictures to Pushbullet.

One downside of a pure-Lua approach for this problem is that it makes the dzVent event handling loop busy for a few seconds, the time it takes to capture the picture from the camera and call the APIs on Pushbullet backend.

As far as I understand the event handling loop will be unable to handle any other events in those few seconds, and you may see the following messages in the domoticz log that warn you about that.

Code: Select all

    dzVents: !Info: ------ Finished myscript.lua after >9 seconds. (using 0.871 seconds CPU time !)
To fix this I have decided to still use the library, but spawn a separate Lua process like this:

Code: Select all

os.execute('cd /home/pi/domoticz/scripts/dzVents/scripts/modules/ ; /usr/bin/lua tgsendpic.lua ' .. '"' .. cameraId .. '"' .. ' "' .. message .. '" &')