New Telegram Binding - Tester and Feedback welcome

First, the message “Failed to send telegram message: Bad Request: query is too old and response timeout expired or query ID is invalid” doesn’t really come from the binding but from the Telegram Server. The exact reason is not always well documented by Telegram.
But what I think is that there is some kind of timeout after that the id gets invalid. When I look at your 3rd and 4th attempt, it took more than 5 minutes for the user to answer. It could be that this time is too long and then you get this error message.Whereas in the 1st and 2nd attempt, you answered within one minute.

Could that make sense?

For me it works even after an hour if there is no consequent messages after that one.
At least it worked a few weeks ago like this…

I do have problems configuring telegram.

I’m using openhab 2.5.1.
I simply activated binding using paperui and according to logs its active.
I configured services/telegram.cfg file, giving proper chatId and token.
I verified the bot using curl commands. It works.

Yet, I’m unable to add thing via paperui, and documentation here is missing/hard to understand. Is it required step? why .cfg file? why duplication?

Questions:

  1. do I must to create thing for telegram?
  2. why paperui asks for token and chatId during thing creation if I given and configured it previously in telegram.cfg file ? (as described in https://www.openhab.org/addons/actions/telegram/ )
  3. how to create thing manually WITHOUT paperui ?
  4. paperui is not working for me: I can not add a thing as chat id field is ‘red’ no matter what I enter (and extending it shows nothing) -> this actualy not a question :slight_smile: it simply not works for me.

Please advise :slight_smile:

p.s. telegram action and telegram binding probably are mixed here, but the documentation is not helpful/clear, and also point 4 as above is not working for me due to chatId field not letting me configure the thing.

Yes, please refer to https://www.openhab.org/addons/bindings/telegram/ and don’t use the documentation for the action to configure the binding.

If you enter a chatId in the UI, then don’t forget to press ENTER.

Thanks!!
Silly to admit, but enter was required :slight_smile:

Anyway I suggest to correct https://www.openhab.org/addons/bindings/telegram/:

  1. add information to binding doc, that this is NOT action, and different configuration applies
  2. add information that you must create a thing using paperui or files in /etc/openhab2/things/*.thing
  3. add information HOW to create thing manualy using files (I dont like paperui).

Could you please also here write me about 3?

Hi, I’m trying to replace OH1 telegram.action by OH2.5 telegram.binding but it fails.
Using OH 2.5 Binding Actions dosn’t work as expected.
Using telegram for example in weather rules fail on using humidity in percent. The ‘%’ in a message will fail this.
telegramAction.sendTelegram(<ChatID>, "test: % text") leads into this Error:
2020-01-18 14:20:52.481 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Weather Conditions': Conversion = e, Flags =
Trying to escape the ‘%’ by ‘’ get teh following Error:
telegramAction.sendTelegram(<ChatID>, "test: \% text") ->
2020-01-18 14:32:59.563 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'weather.rules' has errors, therefore ignoring it: [33,52]: Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
Sending a double % will result into the expected message:
telegramAction.sendTelegram(<ChatID>, "test: %% text") -> “test: % text” in telegram.
Using sendTelegram without extra arguments after message must not perform a parameter parsing.

Maybe the way I did it will help you?

answer = String::format("*Climate:* " + 
                        "\nBox: %1$.1f°C | %2$.0f%%%%" + 
                        "\nRoom: %3$.1f°C | %4$.0f%%%%" + 
                        "\nCellar: %5$.1f°C | %6$.0f%%%%" +
                        "\nStreet: %7$.1f°C | %8$.0f%%%%" + 
                        "\nPressure: %9$.0f mm",
                        (box_climate_temp.state as Number).floatValue, (box_climate_humi.state as Number).floatValue, 
                        (room_climate_temp.state as Number).floatValue, (room_climate_humi.state as Number).floatValue,
                        (cellar_climate_temp.state as Number).floatValue, (cellar_climate_humi.state as Number).floatValue,
                        (street_climate_temp.state as Number).floatValue, (street_climate_humi.state as Number).floatValue,
                        (box_climate_press_mm.state as Number).floatValue)
telegramAction.sendTelegram(answer)
1 Like

@Olymp Yes it works fine with SendTelegram but using it together with sending Photo by sendTelegramPhoto you must use only two signs.
So depending on send method you have to use different workarounds.

@Belgadon After a while my Telegram binding stops working. I then get the following error in the log:

‘sendTelegramQuery’ is not a member of ‘org.eclipse.smarthome.core.thing.binding.ThingActions’; line 69, column 17, length 206

After an OH restart the problem is gone. Any ideas what could cause this problem?

See below. This might be the cause.

Note that the issue as written refers to the installation of a new version of the binding as the cause of the problem. However, I think that the problem might also occur whenever a binding is disposed/initialized (which can occur under other conditions than installing a new version of the binding).

Thanks for the quick reply. I didn’t change anything regarding the binding. It just stops working after some time. Is there a workarround for this problem? Or can I maybe enable a debug log to see what causes this problem?

Thanks for the feedback. I consider this as a bug an will open a PR.

@Olymp
You don’t need to call String::format yourself. You can also pass both arguments directly to sendTelegram.

I have been struggling with sending messages to a second user because I failed to get the chatID for him. The JSON response on the link in the binding docs https://api.telegram.org/bot/getUpdates was empty.
The simple alternative (and probably better recommendation for a beginner) is to start a chat with any of the bots such as @get_id_bot that respond with your chatID. I suggest to change the documentation.

I have mentioned this before here, with the same bot…
And I think it is recommended for everyone, because you can’t get the chatId any other way if that API endpoint is empty…

Could it be empty because it was already consumed by the binding? Maybe you would see it when you stop the binding first, send your message and then open the link.

Of course, using the bot you mentioned is easy, but it’s not an official bot and we don’t know how long it will exist.

I noticed that you can just start a chat with your openHAB bot (send a random message) and in the log you will see an entry that the chat id is unknown and needs to be added to the config. I really love that “feature”!

Not really… it only worked a few times for me.
And if you use an already created group (which you’ll do if you want to deliver these automated messages to multiple people and not individually deliver - which doesn’t make sense if you have to make a decision in my opinion… Whose answer will be the correct answer?) it will never work…

IIRC I tried that, too. Yes it likely was consumed by the binding because I had another telegram user active that I kept sending the message to. It’s ages back that I had set that up, and it’s chatID is still valid. As I said the problem only became apparent when I wanted to add messaging to a second user.

Either way, if the JSON reponse is empty then there just is no other way of getting the chatID (at least none that I know of) and when I g**gled, I found several docs of other systems to also send to telegram that also recommend getting the chatID that way.
And there’s actually many more bots to offer the same functionality such as @myidbot. There’s even ones that don’t work, but you can use either of them.

FYI: OpenHab can make Telegram Phone Calls now! (with TTS Voice)
Nice!

3 Likes

Hi @JensH,

is there a chance to have a textual configuration for the thing itself?

Many thanks & KR,
Chris