telegram http-response, gives error when using it

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

telegram http-response, gives error when using it

Post by hoeby »

I want to make something with the message_id from telegram.
I get the value out of the answer. But when using it, the script gives me a error.

This one

Code: Select all

2019-11-07 21:22:38.066 Status: dzVents: Error (2.4.19): ...ticz/scripts/dzVents/generated_scripts/test telegram.lua:16: attempt to call local 'onstate' (a number value)
I know why it gives it. Because it sees it as number value and not as plain text.
But don't know how to solve. Somebody has an idea?

The script which gives this error

Code: Select all

return {
    on = { 
       devices         = {'Trigger device'},
       httpResponses   = { "Telegram_Callback"}
         },

    execute = function(dz, item)
        
    local teleTok   = '12345:0987654321'
    local chatId    = '123456789'
            
        if item.isHTTPResponse then
            if (item.ok) then
                local onstate   = item.json.result.message_id
                print (onstate)
                os.execute('curl -s -X POST "https://api.telegram.org/'..teleTok..'/deleteMessage?chat_id='..chatId..'&message_id='..onstate'"').afterSec(10)
            else
                print ('niet goed')
            end
        else
            dz.openURL(
                {
                url         = "https://api.telegram.org/bot12345:0987654321/sendMessage?chat_id=123456789&text=Isstil",
                method      = "GET",
                callback    = "Telegram_Callback", 
                })
        end
    end
}

Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: telegram http-response, gives error when using it

Post by waaren »

hoeby wrote: Thursday 07 November 2019 21:30

Code: Select all

2019-11-07 21:22:38.066 Status: dzVents: Error (2.4.19): ...ticz/scripts/dzVents/generated_scripts/test telegram.lua:16: attempt to call local 'onstate' (a number value)
I know why it gives it. Because it sees it as number value and not as plain text.
Not really...
afterSec is not available for os.execute and you missed a ..

Can you try again after changing line 16 to

Code: Select all

os.execute('curl -s -X POST "https://api.telegram.org/'..teleTok..'/deleteMessage?chat_id='..chatId..'&message_id='.. onstate .. '"')
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest