New Telegram Binding - Tester and Feedback welcome

yes, when i post it at the begin of a rule or before the sendmessage then it is working for now. no problems since I do it that way. But you are right, for me the other way would look better.

I keep missing Telegram messages from openhab. When I go into the chat I have with my openhab bot, Telegram welcomes me as a new user EVERY time and asks me to revalidate.
Once I do, subsequent messages arrive, but pretty soon (not sure when exactly) it stops working again.
Did anyone else see this? Any idea what to do ?

In the very first post of this topic it seems to be possible to provide a json like this:

var String json_keyboard = '{"inline_keyboard":[[{"text":"Erledigt","callback_data":"trash_done"},{"text":"Erinnere mich nochmal.","callback_data":"trash_later"}]]}'
sendTelegram("BiergartenBot", "%s und %s solltest du noch raus stellen.", json_keyboard, gCal_Abfall_Event1_Summary.state.toString, gCal_Abfall_Event2_Summary.state.toString)

I think in the current version of telegram it is replaced by sendTelegramQuery(String message, String replyId, String… buttons)

I would like to provide the value keyboard instead of inline_keyboard as mentioned here: Telegram Bot API

Is this possible in a workaround?

I think, I stumbled about a bug in the Telegram binding (openHAB 3.2.0.M1). I’ll open a bug report but want to get your opinion on this before, maybe there is a solution I’m not aware of.
Discussed this here, [Telegram] sendTelegramAnswer works but error in log file 'null in xxx' - #17 by cybermcm, short summary:
Telegram bot working, thing config with 2 ChatIDs (personal and group chat).
I want to use the sendTelegramAnswer function.
Snipped:

getActions("telegram","telegram:telegramBot:BOT").sendTelegramQuery(12345678L, "Test question?", "ReplyTest", "Yes", "No")
rule "test rule"
when
	Item TelegramBot_ReplyId received update ReplyTest
then
	if (TelegramBot_LastMessageText.state.toString == "Yes") {
		getActions("telegram","telegram:telegramBot:BOT").sendTelegramAnswer(TelegramBot_ReplyId.state.toString, "Test No")
}
end

rule stopped with a WARN:

2021-09-05 22:16:16.082 [DEBUG] [gram.internal.action.TelegramActions] - AnswerCallbackQuery for chatId 12345678 and replyId ReplyTest is the callbackId 76676868130867550
2021-09-05 22:16:16.133 [DEBUG] [gram.internal.action.TelegramActions] - remove messageId 126 for chatId 12345678 and replyId ReplyTest
2021-09-05 22:16:16.318 [DEBUG] [gram.internal.action.TelegramActions] - AnswerCallbackQuery for chatId -123456789012 and replyId ReplyTest is the callbackId 11222334455667788
2021-09-05 22:16:16.383 [WARN ] [gram.internal.action.TelegramActions] - Failed to send telegram message: Bad Request: query is too old and response timeout expired or query ID is invalid

The sendTelegramAnswer tries to send the answer to both ChatIDs and not just the one which initiates the query.
If I alter the thing config and put just one ChatID in, all is working without an issue. As soon as 2 ChatIDs are present the error occurs (during my tests the rule stopped, now the rule continues to work and only a WARN is present in the log, don’t know exactly why).
Any ideas?

Update from my side: my issue can be solved by updating the sendTelegramAnswer part. You can add an explicit ChatID there, I wasn’t aware about that…
like: getActions("telegram","telegram:telegramBot:BOT").sendTelegramAnswer(12345678L,TelegramBot_ReplyId.state.toString, "Test Yes")
This solves my problem…

1 Like

Is it possible to create an open question? Like: “Whats the pincode”? And then act upon that using the replyId changes? If I create a an action like this:

getActions("telegram","telegram:telegramBot:bot1").sendTelegramQuery("Enter pin", "Reply_Pincode")

I see a warning: but no buttons are defined and when replying, nothing happens to the “telegramReplyId”.

I think query is only multiple choice with buttons. But you can send a normal message and read the answer I think.

Yes, that’s how I’m currently doing it but feels a bit hackish and I would prefer to use replyId item.

Another question, is it possible to expire the reply binding? I don’t always reply to them and I would like the options to go away after x minutes of not responding.

Is it possible that Telegram Binding no longer works after 3.1.1?
I have already uninstalled and reconfigured it but still the same error.

Can anyone give me some details? Or a few tips on what the problem could be?

Greetings Tobi

I am on openHAB 3.2.0.M5 and it is working

Okay then i wait for the stable OH3 release.
The time will soon come. I am so excited. :smiley:

Edit: I clean the cache now ist working again.

I got so many problems with 3.1.1 (zwave too) and because downgrade to 3.0 wasn’t possible I went to 3.2 M5 too. This works fine until yet

[telegram] NumberFormatException (Token/Bot-Id exceeds the range of Integer) · Issue #11732 · openhab/openhab-addons (github.com)

I had no issues with telegram, but remember to declare the chat id as a long value if used in variables!

Hi, I have set up a Telegram bot successfully (I can send messages via an http call).

However, the sendTelegram command executed in a rule (filename “telegramtest.rules”) copied from the documentation results in an error:

The rule is:

rule "Send telegram with question"
when
    Item HUEMotionSensorWohnzimmer_Bewegung changed 
then
    val telegramAction = getActions("telegram","telegram:telegramBot:telegram:telegramBot:dKTelegramBot")
    telegramAction.sendTelegramQuery("No one is at home, but some lights are still on. Do you want me to turn off the lights?", "Reply_Lights", "Yes", "No")
end

When the rule is triggered, the “telegramAction.sendTelegramQuery” results in the following error:

2022-01-22 20:23:22.580 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'telegramtest-1' failed: null in telegramtest

The code from the THING is:

UID: telegram:telegramBot:dKTelegramBot
label: dieKuchars Telegram Bot
thingTypeUID: telegram:telegramBot
configuration:
  proxyType: HTTP
  longPollingTime: 25
  parseMode: ""
  chatIds:
    - ""
  botToken: -

The Telegram THING is active and looks good (note, I have deleted the IDs in this picture):

Any idea what is wrong?

You maybe should delete the token within your post

1 Like

Better try:

    val telegramAction = getActions("telegram","telegram:telegramBot:dKTelegramBot")

instead:

    val telegramAction = getActions("telegram","telegram:telegramBot:telegram:telegramBot:dKTelegramBot")

Thx Jens, it worked! I read the docu wrong then…

thx a lot.

Have tried but couldn’t get silent messages working. Anyone successful with that and could provide a code example?