New Telegram Binding - Tester and Feedback welcome

Hey Alex,

I directly installed the binding via PaperUI on Snapshot #1745

Ok… But with telegramAction.sendTelegramAnswer (if i click the buttons) the lastMessageUsername received a update… thats why i was wondering that the telegramAction.sendTelegramQuery does not update that username.

yes… all users i tested with, have a tg username set…

yeah, lastMessageName gets updated… lastMessageUsername not. and both only in case its not from the bot itself.

@ZzetT
It seems that formatting doesn’t work in this Lib. I have a simple message with no variables just a pure string, I have added * around some words and it doesn’t get bold when sent, it just sends it through with the asterisks in it.

For me it works… with the snapshot builds…

with sendTelegramQuery and sendTelegramAnswer

I did not test sendTelegram

Did you set the ParseMode to HTML or Markup in the thing configuration?

I have set it, but now rechecked and it wasn’t there… I had a serious SD issue, might be because of that. I will retry, thanks!

I created the PR https://github.com/openhab/openhab2-addons/pull/6379. It will fix the username channel when a reply is sent back.

1 Like

Thanks for the work on this binding!

I’ve started to convert over to this binding from the OH1 binding. I’m not able to send an image using the sendTelegramPhoto API.

My code:

val String imageUrl = "http://my.openhab.host:8080/static/path/to/image.jpg"
val telegramAction = getActions("telegram", "telegram:telegramBot:mybot")
telegramAction.sendTelegramPhoto(imageUrl, "Test image")

And the error I see in the log:

2019-11-12 09:36:07.874 [WARN ] [binding.telegram.bot.TelegramActions] - Failed to send telegram message: Bad Request: wrong file identifier/HTTP URL specified

I’m able to send this image successfully using the OH1 telegram sendTelegramPhoto API.

Thanks for testing it :smiley:

This is an error message that neither comes from the binding nor from the library itself. It’s a message from the Telegram API.
However, I’m quite sure what the problem is. The library passes the URL directly to the Telegram server which then cannot access the image because you are using an URL from your local network.
Question: Don’t you have the image as a local file? In that case you could pass it as a “file://” pointing to the folder of your hard drive.
I’ll think about it. On one hand, if the image is available from a public URL, then this mechanism is quite memory efficient (otherwise we would download the image first and then send it), but I agree that this will not work for network local URLs.

Makes perfect sense. This also explains why the OH1 Telegram binding works. I took a quick look at the OH1 binding code. The OH1 binding gets the image, then posts the image to the Telegram API.

I’ll try converting to the file:// protocol. Not as flexible, of course, as I’ll need to update the path if I ever change the physical location of openHAB in my filesystem (admittedly, very unlikely :wink:).

If this limitation was mentioned in the docs, I missed it. If it’s not in the docs, it probably should be.

Hey guys,
I’m using the OH1 action as well to send pictures from my IP-webcams using a snapshot url the webcam webgui offers.
Back then I played with curling images first and store them temporarily, but it was not as effective as the directly grabbed image from the link.
I would really love to have this feature also available in the new binding.
Thanks for your efforts so far. Happy to help with testing this feature.

Hey there,
I started playing with the binding as well. It went online right away and thing stays online as well.
I removed the old action but do receive the same error as mentioned above.

Rule 'Send telegram with Fixed Message': Instance is not an TelegramActions class.

Here are some details about my system.
OH 2.5.0M4. System restarted and rebooted.

openhab> bundle:list |grep -i telegram
284 x Active x  80 x 2.5.0.201911052119    x openHAB Add-ons :: Bundles :: Telegram Binding
openhab> things list |grep telegr
telegram:telegramBot:a1f09123 (Type=Thing, Status=ONLINE, Label=HausAUTObot, Bridge=null)

The test rule is a copy&paste from the README.

rule "Send telegram with Fixed Message"
when
    Item test_switch changed
then
    logInfo(filename, "Telegram rule executed")
    val telegramAction = getActions("telegram","telegram:telegramBot:1f09123")
    telegramAction.sendTelegram("item Foo changed")
end

Any idea to fix this would be appreciated.
Thanks much Sebastian

Please re-check your thing id is (a1f09123 vs 1f09123).

Shame on me. Thanks Alex.
After fixing the typo the test message get through. Even though binding spits an error:

 2019-11-15 22:34:32.622 [INFO ] [marthome.model.script.telegram.rules] - Telegram rule executed
 2019-11-15 22:34:33.047 [WARN ] [binding.telegram.bot.TelegramActions] - Failed to send telegram message: Bad Request: group chat was upgraded to a supergroup chat

Will continue playing more.

I can’t give much support for this specific error message, because it comes directly from the Telegram Server. You can try to google it to find more information.

Since the mesages get delivered I’m not too converned. And seems like the error message ony happens when using

telegramAction.sendTelegram("item Foo changed")

But when using like this, it works without error message

telegramAction.sendTelegram(220496123, "item Foo changed")

When trying to send to a group chat where ID starts with a minus, the message is not delivered right now. Error message is:

2019-11-15 22:44:29.680 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Send telegram with Fixed Message': An error occurred during the script execution: Could not invoke method: org.openhab.binding.telegram.bot.TelegramActions.sendTelegram(org.eclipse.smarthome.core.thing.binding.ThingActions,java.lang.Long,java.lang.String,java.lang.Object[]) on instance: null

My bot is admin of the group.
Then I tried get_id bot to confirm the group chat ID and received a different ID, but also starting with minus. But this time the group chat ID was not 9 numbers, but 13.

2019-11-15 22:52:03.052 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Send telegram with Fixed Message': An error occurred during the script execution: Integer literal is out of range: 1001315583123

wired.

Yes, because it must be a long value (64 bit) not an integer value (32 bit).
Please check the README (note the “L” at the end of the id):

Just put the chat id (must be a long value!) as the first argument to one of the above mentioned APIs:

telegramAction.sendTelegram(1234567L, "Hello world!")

Dont know if this can be done easily… but wouldn’t it be better to let the binding convert from chat ID to the long value… maybe easier for most of the users? wdyt?

This is something related to the OH environment/rule engine which is based on Java.
Having a method which takes an Integer (where no “L” is required) and converts to a Long doesn’t work, because then the number is already casted to 32 bit and the information is lost. Having a method that takes the chat Id as a String is also not so easy because 1. everbody would need to adapt their existing rules 2. some APIs would become ambiguous, because currently you can call sendTelegram() with two Strings (message + format) but if it is also chat id (as String) + message, then we would need to give the API another suffix to make it unambiguous again.

1 Like

Ok. thanks for the explanation.

I’m trying to install this binding but all I get is:

2019-11-19 14:45:01.137 [ERROR] [core.karaf.internal.FeatureInstaller] - Failed installing 'openhab-binding-telegram': Error:
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okhttp3/logging-interceptor/3.12.3/logging-interceptor-3.12.3.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okhttp3/logging-interceptor/3.12.3/logging-interceptor-3.12.3.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/github/pengrad/java-telegram-bot-api/4.4.0/java-telegram-bot-api-4.4.0.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/github/pengrad/java-telegram-bot-api/4.4.0/java-telegram-bot-api-4.4.0.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okhttp3/okhttp/3.12.3/okhttp-3.12.3.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okhttp3/okhttp/3.12.3/okhttp-3.12.3.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okio/okio/1.15.0/okio-1.15.0.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okio/okio/1.15.0/okio-1.15.0.jar

Running openhab 2.5~M5 on Proxmox VE 5.4 Debian 9 container. All the files are there and permissions are fine. I’ve restarted a few times and cleared the cache to be sure but nothing.

Edit: Downloaded latest bundle from jfrog and dropped into addons folder and everything seems to work. Must be something with karaf.