[Solved] Telegram Binding problem with multiple ChatIDs


I’m running into problems while trying to send queries or messages to an telegram group.

The problem is the telegram chatIDs that belong to a group has a leading - sign.
e.g. “-2173987325983”

My telegram things file has 2 chatIDs defined, one bot and one group.

Thing telegram:telegramBot:HQGroup "Telegram Bot" [ botToken="901234547:AAF3BqIfH-S06zjnlb0YeL1dnRpA9Nt99zo", chatIds="-1234570420082","987617487", parseMode="HTML" ] {
        DateTime    :   lastMessageDate
        String      :   lastMessageText
        String      :   lastMessageName
        String      :   lastMessageURL
        String      :   lastMessageUsername
        String      :   chatId
        String      :   replyId

if I try to send a message to both without defining a chatID everything runs just fine

telegramAction.sendTelegramQuery("Testschalter gedrückt. Soll ich den Schalter wieder ausschalten?", "Reply_Test", "Ja", "Nein")

also with my personal chatID

telegramAction.sendTelegramQuery(987617487,"Testschalter gedrückt. Soll ich den Schalter wieder ausschalten?", "Reply_Test", "Ja", "Nein")

but sending to a group seems not to be possible because of the - sign.

telegramAction.sendTelegramQuery(-1234570420082,"Testschalter gedrückt. Soll ich den Schalter wieder ausschalten?", "Reply_Test", "Ja", "Nein")

I also tried to quote the chatID



Has anyone an idea what to try next, or is this just not covered by the binding and I have to report a bug?

I do also use multiple chatIDs and for me it works in the following format:


Replace 00000 with your ID obviously. (Above is ECMA code).

Does your log show anything?

Edit: also, I think the Chat IDs are 10 numbers long, with a - though only 9 numbers (i.e. 10 signs in total).

hi chris,

very silly not working for me, but the chatIDs defined in the thing are right, I can send messages to both while not adding a chatID to the sendTelegramQuery… hm have to check the logs a second time…

==> /var/log/openhab/openhab.log <==
2022-01-30 15:41:31.248 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'notification-9' failed: An error occurred during the script execution: Integer literal is out of range: 1234570420082 in notification

this is what gets logged when trying your suggestion…

I think java has a problem with the negative numbers - can you confirm that it’s working for you?

I’m running openHAB 3.2.0 Release Build

shuldn’t it look like this, you miss the bot

things.getActions('telegram', 'telegram:telegramBot:xxxxxxxxx').sendTelegramQuery(-xxxxxxx, 'Niemand ist zu Hause, Earlyclose einschalten?', 'Earlyclose', 'Yes', 'No');

This is a blokly skript

hi Rolli

val telegramAction = getActions("telegram","telegram:telegramBot:xxxxxxxx)
telegramAction.sendTelegramQuery(-1234570420082, "Testschalter gedrückt. Soll ich den Schalter wieder ausschalten?", "Reply_Test", "Ja", "Nein")

In my case it’s defined in two lines, but this should do barely the same I think.

took this from the Bindings Documentation, and it works this way if I exchange the group-chatID with a personal chatID which don’t have this “-” sign infront of the numbers

is it a DSL Rule?

Yes it is

define your chat id as long with an L at the end

1 Like

thanks a lot this did the trick :wink:

never heard of flagging a number with a large L for long …nice 1


Have a look here :wink:

ok, missed this - but it’s strange that my privat chatID works without the L - funny

Interesting, maybe the chatID is just too long as the error says.
I remember that on my first try, when I did at the L it did not work for me (using ECMA though).
Glad you found a solution though.