New Telegram Binding - Tester and Feedback welcome

stupid me :slight_smile: :slight_smile: :slight_smile:
sometimes other people find in 10 seconds what we fight for during hours
Was wondering how last message was retrieved.

Added this in an .items file and now working.

String telegramMessage "Telegram Message" { channel = "telegram:telegramBot:2b155b22:lastMessageText" }

Was a pleasure for me :slight_smile:

I put all Replies within one rule and a Switch case, so I have some easier to found the code :slight_smile: Maybe a useful hint.

Is there a latest example how to work with the telegram binding in Javascript and OH3? Could only find something with script helpers for 2.4/2.5

it works in 3.X just like it did it 2.X

Just stumpled across this topic and thought I post my way, maybe it helps:
Have this rule here

triggers:
  - id: "1"
    configuration:
      itemName: Telegram_PhiL
    type: core.ItemStateChangeTrigger
conditions:
  - inputs: {}
    id: "2"
    configuration:
      itemName: Telegram_PhiL
      state: ""
      operator: "!="
    type: core.ItemStateCondition
actions:
  - inputs: {}
    id: "3"
    configuration:
      type: application/javascript
      script: >
        var telegramAction =
        actions.get("telegram","telegram:telegramBot:*********");

        telegramAction.sendTelegram(itemRegistry.getItem( 'Telegram_PhiL' ).getState().toString());
    type: script.ScriptAction

so I can use the item Telegram_PhiL as a proxy, whatever I put this item to will be forwarded to my phone.

3 Likes

It seems that this is the “official” Telegram post, I’d like to mention a current open incident:

Sorry if this is against rules (double posting) but my hope is that maybe someone has a workaround in place or an idea what is happening.
Any feedback welcome…

1 Like

This would be great if this can be fixed. But I am not sure if it is related to the telegram binding or openhab3. Maybe some of the openhab developers can tell if it related to the binding or the system @J-N-K @ysc @David_Graeff

The same is in openhab 2.5.12

I used to receive the telegramaction like a global variable in the rule, at the top outside of every single rule.
But I think we need to move it within the rule just before the sendMessage:
var telegramAction = getActions(“telegram”,“telegram:telegramBot:FS6”) telegramAction.sendTelegram(“Test”)

@eric1905: if you place it before every sendMessage, does it work then?
But it still feels like a bug because leaving the var entry at the top and only reload the rule gets it working

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