Telegram on OH4

When I upgraded to OH4 a few telegram actions stopped working. I installed the Nashorn add-on, selected the type of script (ECMAScript (ECMA - 262 Edition 5.1)) and have the scripts working now.

Since I only have a handful of these kind of scripts I’d kind of like to rewrite the scripts to work with the current Java 17 engine. Is there a guide to rewrite these rules for OH4 so I don’t have to run the JavaScript Scripting (Nashorn) add-on?

Got some telegram messages tied into sunrise and sunset rules that change some exterior lights and then notifies me that the rule has run.

var telegramAction = actions.get("telegram", "telegram:telegramBot:botname")
telegramAction.sendTelegram("Astro binding says, 'sunrise'.")

Another script sends a message that one of the garage doors is open or closed along with a snapshot from the surveillance camera:

var telegramActionMe = actions.get("telegram", "telegram:telegramBot:botname")
telegramActionMe.sendTelegram("Garage door West is open.")
telegramActionMe.sendTelegramPhoto("http://camera-name/snapshot/view0.jpg","garage view")

Ran into another similar problem with a telegram action.

I’ve got a rule that triggers from a doorbell press. It plays an mp3 on a couple sonos speakers and it supposed to then grab and send a snapshot from a surveillance camera.

To send the picture this works in a different rule, image is 1920x1080

telegramActionMe.sendTelegramPhoto("http://camera1/snapshot/view0.jpg","garage view")

For this rule a similar action fails, image is 3840x2160


In openhab.log I get this when it fails:

2023-09-03 09:42:30.204 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Doorbell' failed: TypeError: Can not invoke method [jdk.dynalink.beans.OverloadedDynamicMethod
 boolean org.openhab.binding.telegram.internal.action.TelegramActions.sendTelegramPhoto(Long,String,String,String,String)
 boolean org.openhab.binding.telegram.internal.action.TelegramActions.sendTelegramPhoto(Long,String,String)
 boolean org.openhab.binding.telegram.internal.action.TelegramActions.sendTelegramPhoto(String,String,String,String)
 boolean org.openhab.binding.telegram.internal.action.TelegramActions.sendTelegramPhoto(String,String)
] with the passed arguments; they do not match any of its method signatures. in <eval> at line number 3

Makes me think it’s a syntax problem like I need to escape certain characters in the URL but I’ve tried that a few different ways and couldn’t figure out what was causing the issue. Both URLs work from a browser so I know the images are viewable with the URLs I’ve given.

When you upgrade to the JSScripting add-on, you automatically get the extensive helper library. This comes with it’s own documentation (which is, admittedly long, but that’s because there are so many different things that it helps with):

The side bar of that documentation is also direct links to reference page. For example the one that shows actions.get(...) still works:

So, for the two simple cases you’ve posted, the good news there are no changes required to upgrade to the newer JS version at the moment. Just install the JSScripting add-on, go to the rule script and click on the arrow icon on the bottom right. That will expand the panel and let you select which rule engine should run that rule.

If you reduce your function call to just types, what you’ve done is


The error is telling you that one string parameter is not one of the viable options for sendTelegramPhoto and that at the very least you need a second parameter. You can’t just send the photo URL, you also need to include a caption string (although it’s possible that if you really don’t want a caption you can just use "" as the caption string, I don’t know).

I got it working by adding a caption string. Thanks.