New Telegram Binding - Tester and Feedback welcome

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.

Is this binding available in M5 or is it going to be available in the upcoming final release?

See 58. in openHAB Milestone builds
It is available in M5.

1 Like

Hi!
openHAB 2.5.0 Build #1761
Installation for the first time, before this binding did not install. In paperUI click install …
log:

2019-11-21 19:59:48.501 [ERROR] [core.karaf.internal.FeatureInstaller] - Failed installing 'openhab-binding-telegram': Error:
	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
	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
	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/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

and so every 4 minutes.
in papierUI:

\192.168.215.3\oh-userdata\config\org\openhab\addons.config:

:org.apache.felix.configadmin.revision:=L"20"
binding=",miio,exec,network,expire1,networkupstools,telegram"
package="standard"
persistence="influxdb,mapdb"
service.pid="org.openhab.addons"
transformation="jsonpath"
ui="basic,paper,habpanel"
voice="voicerss"

What am I doing wrong?
Thanks!

Hi @Olymp, did you notice my earlier post? I thought I was only one with the problem. As a short term workaround you can also try downloading the bundle from here,

https://openhab.jfrog.io/openhab/libs-pullrequest-local/org/openhab/addons/bundles/org.openhab.binding.telegram/2.5.0-SNAPSHOT/org.openhab.binding.telegram-2.5.0-SNAPSHOT.jar

and drop it in your addons folder.

I’ll link our posts forward to the M5 problem topic :+1:

Hello! Yes, I saw the post, but it didn’t translate correctly, my English is very poor. I apologize. Thanks for the workaround, I’ll try tomorrow.

Yes, thanks again! it works.
I just could not send the image. Who could do this, tell me how, please!

telegramAction.sendTelegramPhoto("file://192.168.215.3/oh-cfg/html/network.jpg", "sent from openHAB")

log:

2019-11-22 17:00:19.903 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Send telegram with Image Item image and caption': java.net.ConnectException: Failed to connect to api.telegram.org/2001:67c:4e8:f004:0:0:0:9:443

Thanks!

Hi. I met the same question with @gitMiguel… I added the jar file manually. However, I can’t add telegram bot through PAPER-UI.


Can’t click the blue button. Did I miss something?

I’m using openhab2-2.5.0~M5 and here is my addons.config:

:org.apache.felix.configadmin.revision:=L"5"
binding="network,telegram"
package="standard"
service.pid="org.openhab.addons"
ui="basic,paper,habpanel,homebuilder"

By the way, I have tried restarted the openhab2, and it didn’t make any difference

I’ve had the same issue.
Just type in your chatID and press enter.
A dropdown should appear, where you can activate the checkbox.

After Switching from Telegram action to the new Telegram binding I get a lot of messages in openhab.log:
2019-11-23 09:55:04.697 [WARN ] [ng.telegram.internal.TelegramHandler] - Telegram exception: GetUpdates failed with error_code 409 Conflict: terminated by other getUpdates request; make sure that only one bot instance is running

Sending telegram messages works though.
Anyone with the same issue?

EDIT:
I am running the latest 2.5M5

Hi,

Thanks for the great binding and all the work. In general it is working for me but does somebody has any hint how an jsr223 jython rule would look like which is using the action of this binding to send telegram messages? I have some trouble with getting the right thinks imported. Something like telegram = actions.get(“telegram”, “telegrambot:uid”) seems to be not working within some of the python files.

Thanks for the support!

Best regards, christian

I did have problems finding out as well.
My item:
String TelegrMess “Telegram Message” (G_jdbc) {channel=“telegram:telegramBot:MYBOT:lastMessageText”}

My rule:

val action = getActions("telegram","telegram:telegramBot:MYBOT")

rule "Lights Off"
when
    Item G_Lights changed to OFF
then
	action.sendTelegram("Das Licht wurde ausgeschaltet!")
end

Hi,

Thanks for the example. Unfortunately this dosen’t solve the issue.

For the standard rule engine it is working for me somehow. Also for a jython rule which is located in the openhab2/automation/jsr223/personal folder. So the below code is working fine:

from org.slf4j import LoggerFactory
from core.rules import rule
from core.triggers import when

@rule("Test rule for new telegram binding")
@when("Item presence changed")
def someFunction(event):

        telegram = actions.get("telegram","telegram:telegramBot:xxxxxxx")
        telegram.sendTelegram("Hello *World* " +  u"\U0001F44D")

But if I will use some functions from openhab2/automation/lib/python/personal were I have stored my common code - it is not working anymore with the same code like above (same imports). During runtime i will get a “module actions has no attribute get” error which is not the case with the previous file location.

Any ideas?

EDIT:
I’ve solved the problem. For guys with the same problem. You have to add

from core.jsr223 import scope
from core.jsr223.scope import actions

to the imports if you move the file to the lib subfolder. This was missing somehow.
br, christian

@mhilbush, @waitz_sebastian and @Olymp
I re-added the functionality to send pictures via http(s) that are only reachable from your local network.
Use the “file://” protocol only for files on your local hard drive.

That usually means that you are alraedy running a bot for the same token. That can for example happen if you created two things with the same bot token or you have two different OH instances running in parallel. This is not allowed by the Telegram API. If you think you have only instance running, then please try to restart OH.

I get the same error message when I’m trying to install the binding directly from the M5. Copying the JAR to the addons folder works however.

Can @Kai or @J-N-K have a look if this is related to the binding or something else is missing? Thank you!

For me the installation and the binding works great and I also have installed it the first time from 2.5 M5. I’m running openhabian on a Pi3.
Perhaps this info will help. br, christian

Works for me. Here’s my Network check rule that uses sendTelegram(String message) method:

from time import sleep
from core.rules import rule
from core.triggers import when

#Network
@rule("NetworkCheck")
@when("Time cron 0 0 21 * * ?")
@when("Time cron 0 0 12 * * ?")
@when("Member of GrNetwork changed")

# Import new Telegram action
telegram = actions.get("telegram", "telegram:telegramBot:xxxx")

def execute(event, log):
    telegram = actions.get("telegram", "telegram:telegramBot:lanteeBot")
    if ir.getItem("GrNetwork").state == ON:
        if event:
            message = "Network fully online"
            telegram.sendTelegram(message)
            log.info(message)    
    else:
        sleep(1)
        offlineMembers = sorted(member for member in ir.getItem("GrNetwork").getMembers() if member.state == OnOffType.OFF, key = lambda member: member.state)
        message = "Network devices offline:\n\n{}".format("\n".join(item.label for item in offlineMembers))
        telegram.sendTelegram(message)
        log.info(message)

Edit
I replied too fast, sorry. You were asking about personal libraries. But I’ll leave this here as an example.