Telegram custom keyboards

Client tools or tools that can connect with Domoticz. Tools for Windows, iOS, Android, Linux etc.

Moderator: leecollings

User avatar
jvdz
Posts: 2441
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Telegram custom keyboards

Post by jvdz »

hoeby wrote: Saturday 15 August 2020 12:49 But simple change the chat-id in the url didn't work.
Do you also know the url api for inline keyboard?
I have used your exact url and that is working so it should work for you too when you put in your botxxxx:yyyy token and chart_id and use that url in your browser.
EDIT: I guess we are mixing 2 things here: Your url is the KEYBOARD option, not the inline..... but I like to understand whether that works before making it inline..... and yes I know how to make the inline as I wrote the dtgbot part doing that.
User avatar
jvdz
Posts: 2441
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Telegram custom keyboards

Post by jvdz »

This inline version of your keyboard version works for me opened from chrome:

Code: Select all

https://api.telegram.org/botToken/sendMessage?chat_id=-1&text=Choose&reply_markup={"inline_keyboard":[[{"text":"Yes","callback_data":"optYES"},{"text":"No","callback_data":"optNO"}]]}
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: Telegram custom keyboards

Post by hoeby »

The reason why i asked for the inline api. Because that works. Then i am not at a hold for the script i am building.
Will not say that i will keep it with inline. Because i like the keyboard option (the not inline)

This one works:

Code: Select all

https://api.telegram.org/botToken/sendMessage?chat_id=-1&text=Choose&reply_markup={"inline_keyboard":[[{"text":"Yes","callback_data":"optYES"},{"text":"No","callback_data":"optNO"}]]}
This one not, but don't know why:

Code: Select all

https://api.telegram.org/botToken/sendMessage?chat_id=-1&text=Choose&reply_markup={"keyboard":[["Yes"],["No"]]}
it replies this:

Code: Select all

{"ok":false,"error_code":400,"description":"Bad Request: inline keyboard expected"}
Tried:
- enabled the privacy mode, no luck
- disabled the privacy mode, no luck

Tried to replace the chat-id to my own chat-id, this is the response

Code: Select all

{"ok":false,"error_code":403,"description":"Forbidden: bot was blocked by the user"}
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
jvdz
Posts: 2441
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Telegram custom keyboards

Post by jvdz »

hoeby wrote: Saturday 15 August 2020 13:24 This one works:

Code: Select all

https://api.telegram.org/botToken/sendMessage?chat_id=-1&text=Choose&reply_markup={"inline_keyboard":[[{"text":"Yes","callback_data":"optYES"},{"text":"No","callback_data":"optNO"}]]}
This one not, but don't know why:

Code: Select all

https://api.telegram.org/botToken/sendMessage?chat_id=-1&text=Choose&reply_markup={"keyboard":[["Yes"],["No"]]}
it replies this:

Code: Select all

{"ok":false,"error_code":400,"description":"Bad Request: inline keyboard expected"}
Are you sure it is a group and not a channel?
hoeby wrote: Saturday 15 August 2020 13:24 Tried to replace the chat-id to my own chat-id, this is the response

Code: Select all

{"ok":false,"error_code":403,"description":"Forbidden: bot was blocked by the user"}
Have you first tried to send a command from your phone to the bot and read that with the BOT to establish connectivity?

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

Re: Telegram custom keyboards

Post by hoeby »

jvdz wrote: Saturday 15 August 2020 13:38 Are you sure it is a group and not a channel?
I think you made a point there.
When i read my small instructions how i made a few years back. I have written that i needed to make a channel.

Looked in the app, and it says private-channel
jvdz wrote: Saturday 15 August 2020 13:38 Have you first tried to send a command from your phone to the bot and read that with the BOT to establish connectivity?
That i have to look over tonight. This goes to quick for me what you mean. Will have a look on telegram instructions, how to get that information out my bot
Last edited by hoeby on Saturday 15 August 2020 13:50, edited 1 time in total.
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
jvdz
Posts: 2441
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Telegram custom keyboards

Post by jvdz »

That is the reason it doen't work as Keyboard only works with persons and groups and will not work with channels. :)
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: Telegram custom keyboards

Post by hoeby »

Made a group with the bot in it.
Finding the chat-id was the biggest challenge. But found it with some help from google, how to do it.

Now the reply keyboard works.
Only one thing. When i choose an option, it still stays visible.
There is a way to add a true command, so it disapears when an option is chosen. But how to add that in the https line?

Tried this, but i didn't work

Code: Select all

https://api.telegram.org/bot:token/sendMessage?chat_id=-1&text=Choose&reply_markup={"keyboard":[["Yes"],["No"]],"one_time_keyboard":["true"]}
Already thanks JVDZ, for all the support
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: Telegram custom keyboards

Post by hoeby »

hoeby wrote: Saturday 15 August 2020 19:12 Tried this, but i didn't work

Code: Select all

https://api.telegram.org/bot:token/sendMessage?chat_id=-1&text=Choose&reply_markup={"keyboard":[["Yes"],["No"]],"one_time_keyboard":["true"]}
I think i found it.

Code: Select all

https://api.telegram.org/bot:token/sendMessage?chat_id=-1&text=Choose&reply_markup={"keyboard":[["Yes"],["No"]],"one_time_keyboard":true}
Is this correct?
It works, but don't know if i made it how it designed
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
jvdz
Posts: 2441
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Telegram custom keyboards

Post by jvdz »

hoeby wrote: Saturday 15 August 2020 19:42 I think i found it.

Code: Select all

https://api.telegram.org/bot:token/sendMessage?chat_id=-1&text=Choose&reply_markup={"keyboard":[["Yes"],["No"]],"one_time_keyboard":true}
Is this correct?
It works, but don't know if i made it how it designed
That looks correct to me.... It will just hide the custom keyboard till you hit the keyboard icon again.
To fully remove it you can send this in a response message:
text=done&&reply_markup={"remove_keyboard":true}
Jos
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: Telegram custom keyboards

Post by hoeby »

Thanks,

The remove functie is made for the https, that worked

Making the remove function work for the ESP took a little more time.
Because the library didn't know the remove_keyboard function, which first needed to add in UniversalTelegramBot
But it is added and works. Only one option for the remove needs to be added to make the story complete. Not needed, but when added i prefer to add all options for that function. Maybe something for tomorrow.
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: Telegram custom keyboards

Post by hoeby »

jvdz wrote: Saturday 15 August 2020 11:37 I am sure I can help you with that. :)
Do you have any advice, which manual to follow for dgtbot?
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
jvdz
Posts: 2441
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Telegram custom keyboards

Post by jvdz »

Just enable the debugging as described in the installation page and have a look at the generated dtg.log. mail me the file in case you need help. :)

EDIT: I was reffering to this Wiki page: https://www.domoticz.com/wiki/Remote_Co ... leshooting
... and it helps when you set the Uservariable TelegramBotLoglevel to 9 in case more detailed log entries are required.
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: Telegram custom keyboards

Post by hoeby »

The dgtbot has to wait.
I started with it today. Which start with update/upgrade.

But on the upgrade i got an error.

Code: Select all

loading files list file for package 'gpg-agent': cannot open /var/lib/dpkg/info/gpg-agent.list (Structure needs cleaning)
When i posted this on google. It looks like a corrupt sd-section.
The system is still running without issues. But i think my sd card is not that great.
I am running a sd card with the name of a local company on it. It says that it is class 10, but i have my questions about the quality of this card.
Last i needed to shutdown the pi because i need to work on the electricity in house. After that the sd was corrupt. And i was sure i did a normal shutdown and waited 5 minutes before cutting the power.

A new sd-card is ordered. Have to wait for it and put a backup on it.
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: Telegram custom keyboards

Post by hoeby »

Because with the SD-card problems,
I can't find problems in working of domoticz, so i tried it with dzvents

When doing this in putty, it works

Code: Select all

curl -s -X POST "https://api.telegram.org/bottoken/sendMessage?chat_id=1" -F text="Kies een van de opties." -F reply_markup="{\"keyboard\":[[{\"text\":\"Yes\"},{\"text\":\"No\"}]]}"
But when doing it this way in dzvents, it doesn't work

Code: Select all

os.execute('curl -s -X POST "https://api.telegram.org/bottoken/sendMessage?chat_id=1" -F text="Kies een van de opties." -F reply_markup="{\"keyboard\":[[{\"text\":\"Yes\"},{\"text\":\"No\"}]]}"')
any idea's ?
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
jvdz
Posts: 2441
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Telegram custom keyboards

Post by jvdz »

Try:

Code: Select all

os.execute('curl -s -X POST "https://api.telegram.org/bottoken/sendMessage?chat_id=1" -F text="Kies een van de opties." -F reply_markup="{\\\"keyboard\\\":[[{\\\"text\":\\\"Yes\\\"},{\\\"text\\\":\\\"No\\\"}]]}"')
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: Telegram custom keyboards

Post by hoeby »

I will try it later this day, thanks for the option.

I moved the script over from os.execute to dz.openurl
Than it was possible to use the https api without issues

Made this script. This is the start to use it for:
- Doorbell is pushed, camera image is send to telegram and a question (telegram keyboard) is posted undernead it, if you would like to get a new (extra) camera image
- After X time (for me 30 seconds) the keyboard is removed again. Because i couldn't send a remove without text. I will take a callback on the remove keyboard to get the message-id out of it. Then remove the message which is send for the remove-keyboard. This also with no notification.

Code: Select all

return {
    on = { 
       customEvents = { 'myCustomEvent',},
       --devices         = {'Trigger device'},                             -- De switch die dit scripts triggerd
       httpResponses   = { "Telegram_Callback"}                          -- Niet aanpassen
         },
     
--[[
Custom event trigger json:
192.168.XXX.XXX:8080/json.htm?type=command&param=customevent&event=myCustomEvent&data=myData
]]--      

    execute = function(dz, item)
        
    local teleTok        = 'xxxxxxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'    -- Jouw telegram token
    local chatId         = 'xxxxxxxxx'                                        -- Jouw telegram ChatId
    
    local tekstpost      = 'Kies een optie.'                                  -- De tekst voor het telegram tekst bericht
    local tekstremove    = 'KeuzeMenuWeg'
    
    local disable_notify = 'true'                                             -- Als het telegram bericht geen geluid mag maken, dan 'true'
                                                                              -- Anders op 'false' zetten
    local KeuzeMenuWeg   = 30                                  -- Aantal seconden, waarna het keuzemenu verwijdert dient te worden.                                                                 
                                                                         
    debug = false                                                             -- Als debug nodig is, deze op true zetten, anders false
            
        if item.isHTTPResponse then
            if (item.ok) then
                local id_message   = item.json.result.message_id
                if debug then
                    print (id_message)
                end
                os.execute('curl -s -X POST "https://api.telegram.org/bot'..teleTok..'/deleteMessage?chat_id='..chatId..'&message_id='..id_message..'"')
            else
                if debug then
                print ('niet goed')
                end
            end
    
        else
    
            local myurl1 = 'https://api.telegram.org/bot'..teleTok..'/sendMessage?chat_id='..chatId..'&text='..tekstpost..'&reply_markup={"keyboard":[["Yes"],["No"]],"one_time_keyboard":true,"resize_keyboard":true}'
            if debug then
                print (myurl1)
            end
        
            dz.openURL(
                {
                url         = myurl1,
                method      = "POST",
                })
        
            local myurl2 = 'https://api.telegram.org/bot'..teleTok..'/sendMessage?chat_id='..chatId..'&text='..tekstremove..'&reply_markup={"remove_keyboard":true}&disable_notification='..disable_notify..''
            if debug then
                print (myurl2)
            end
        
            dz.openURL(
                {
                url         = myurl2,
                method      = "GET",
                callback    = "Telegram_Callback", 
                }).afterSec(KeuzeMenuWeg)
        end
    end
}
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest