Telegram Binding: Address individual chat-IDs (.things)

I was using the Telegram Action to send Messages from one bot to multiple chats individually.
But now I’d like to use the “Query” function to get responses to those messages.
I installed the Telegram-Binding and edited the telegram.things fire, I created:

telegram.things

Thing telegram:telegramBot:telegram001 [chatIds="chatid1", "chatid1", botToken="bottoken", parseMode="Markdown"]

chatid1, chatid2 and bottoken were changed out with my peripherals


Now, in the `telegram.rules`-file, I would like to send my query to only one of those chat-ids

telegram.rules

rule "dev_switch001"
  when
    Item dev_switch001 changed
  then
    getActions("telegram","telegram:telegramBot:telegram001").sendTelegramQuery("Test Question", "Reply_Lights", "Yes", "No")
end

This will send the query to both chatid1 and chatid2


How can I adress the specific chat-id from the .things in my .rules?

But now I’d like to use the “Query” function to get responses to those messages.

What have you researched & tried?

We do not have the volunteer resources here to provide & support complete solutions. We are here to help you with your configuration.

1 Like

I researched here:

https://www.openhab.org/docs/configuration/things.html
https://www.openhab.org/addons/bindings/telegram/

but all those examples lead into sending the query to both given chat-ids


I also tried to split the two chat-ids into two different things. But the openhab-log tells me to not create two things out of one binding.

So the main goal is to address chat1 with e.g. telegram:telegramBot:telegram001:chat1 and chat2 with telegram:telegramBot:telegram001:chat2
I dont think that no one else has tried to send separate queries to different telegram-chats yet.

1 Like

Have a play with it. Using your existing Thing with its list of chatids create and link Items to the lastMessageText and chatid channels. See what you get when a message is sent.

But this would get me the chatId, replyId and lastMessageText of the button pressed or message sent by the Telegram-user.
My problem starts with providing the user with the following buttons, called “query”:

rule "dev_switch001"
  when
    Item dev_switch001 changed
  then
    getActions("telegram","telegram:telegramBot:telegram001").sendTelegramQuery("Test Question", "Reply_Lights", "Yes", "No")
end

which, for right now, results in the following chat for both “chatid1” and “chatid2”

image
I just want to be able to descide, which chatId(s) the rule should send it to.

Okay, I was misled by “Now I want to get responses” and assumed that meant listening.

So you’re saying the Action sending method shown here does not work?

It does indeed work. But there is no way to determine, which of the chatIds - declared in the .things file - the message is sent to.

So the dev_switch001-rule works perfectly fine, sending the message seen in the attached picture.
But I don’t want it to be sent to both chatIds.

Okay, so what happens when you follow the example “Actions to send messages to a particular chat” and specify one chatid in your Action, as the first parameter?

sendTelegramQuery(123456L, “blah”, “bleh” …

1 Like

Oh wow. That seems to work. But only with private chats and not in groups since their id starts with a -.
Thank you so much, rossko67!

https://www.openhab.org/addons/bindings/telegram/#actions-to-send-messages-to-all-configured-chats

the parameter for the Query is missing in the official documentation.

The Soution:

rule "dev_switch001"
  when
    Item dev_switch001 changed
  then
    getActions("telegram","telegram:telegramBot:telegram001").sendTelegramQuery(chat_id_as_long, "Test Question", "Reply_Lights", "Yes", "No")
end

What official documentation now?

Be useful to show how you created a Long variable - not common in rules.

Might be worth raising a github for group -chatid (if that is a sensible thing to do in this telegram usage) for an enhancement. I guess it only needs to recognize a negative number.