New Telegram Binding - Tester and Feedback welcome

2019-12-11 16:45:04.766 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'test': An error occurred during the script execution: null

No, this is just an example.

This wonā€™t work right now. Changes needed in the bindings code.

Sorry for asking as Iā€™m late to the party it might be written here but I couldnā€™t find it.

First, is it really an updated Action as the thread title says ?

openhab> bundle:list|grep -i teleg
217 x Active   x  80 x 1.14.0                  x openHAB Telegram Action
265 x Active   x  80 x 2.5.0                   x openHAB Add-ons :: Bundles :: Telegram Bi

I have added telegram to the list of bindings during my upgrade to 2.5 and already had it configured as an action before (action = telegram in services/addons.cfg).
Shouldnā€™t that have been a v2 action when starting OH now ?
BTW docs on telegram action are also still marked as v1.

Second, do I still need to install a .jar as the latest post in this thread say ? As you see itā€™s contained in 2.5 (release).

Third, Iā€™m having trouble with the binding docs. They seem to be a copy of the v1 action docs ?
They say
Open a browser and invoke https://api.telegram.org/bot/getUpdates(where is the authentication token previously obtained)

I can retrieve the token from BotFather, it is something like nnnnnnnnn:ZZZZZZZZZZZZZZZZZZZZZZ
Entering that string instead of <token> does not result in anything useful.

Moving on, docs also say in the next line
Look at the JSON result to find the value of id . That is the chatId. Note that if using a Telegram group chat, the group chatIds are prefixed with a dash that must be included in the config file. (e.g. bot1.chatId: -22334455)

What config file ?? Thereā€™s telegram.cfg which is still there for me for the v1 action.
But v2 bindings do not have config files so ?

FWIW I had been using the v1 action to successfully work so I think I can use that existing chat and donā€™t need to do this again.
But this is inconsistent. What if someone starts with v2 ?

Fourth and finally, Iā€™m struggling getting telegram action to work under Python:

The code

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

for now results in

2019-12-16 15:35:40.462 [ERROR] [jsr223.jython.battery monitor       ] - Traceback (most recent call last):
  File "/etc/openhab2/automation/lib/python/core/log.py", line 51, in wrapper
    return fn(*args, **kwargs)
  File "<script>", line 46, in battery_check
AttributeError: 'NoneType' object has no attribute 'sendTelegram'

BTW, as nnnnnnnnn I would need to use the ChatID, correct ? Docs say ā€œuidā€ which is confusing.

It has an action, but not similar to the old one. You can get the action by calling getActions("telegram", "telegram:telegramBot:nnnnnnnnn"). You can then execute the actions (there are more actions available now, compared to the old v1).

I think you need to remove the action, as of now it is included in the binding, there is no seperate Action.

No, just install from PaperUI or specify it in the addons.cfg. The included one in 2.5 is the latest version.

I donā€™t really get this. The returned token from BotFather is exactly what you will need to enter as your token.
The docs says:

Open a browser and invoke https://api.telegram.org/bot<token>/getUpdates (where <token> is the authentication token previously obtained)

This is for obtaining the chatId. However it is not always working (for groups it never worked for me).
The best I found is this bot:

Add this bot temporarly to your group or to your conversation to get the chatId.

Yes this is just a copy and paste error from v1. No cfg file, since this is a v2 addon.

You donā€™t need that. However if you have your old telegram.cfg you can just copy and paste everything from it.

Sorry I canā€™t help with this. I have just started to rewrite everything in Python, and I struggle with easier problems :). But it seems like it canā€™t get the Thing from the API? NoneType surely donā€™t have sendTelegram attribute, and usually this happens in Python when your reference is null (None in Python).

No. The token is always in that format. nnnnnnnnn:ZZZZZZZZZZZZZZZZZZZZZZ. That is what you have to set as token in the binding configuration.
You need to get the chatId seperately, and set it as a chatId in the binding configuration.

I can see now what you mean by uid :slight_smile: No this is not your chatId. This is your Thing UID given by openHAB. This is how it works for all v2 actions.

Your points for the README are right. Not the best because it was copy-pasted from the old one. I will try to update it when I have some time.

Ok, thanks upfront for your answers on binding status.

Ok, @ZzetT, @rkrisi please do.
But anyone easily can. So some other kind benefitting soul from this thread, would you please update the docs for action and binding ?
Just go to the official page, at the bottom thereā€™s a link to Github, edit, boom. Docs maintainers will review your input before itā€™s published.

Ok, but I think you mean to create the Thing, donā€™t ? telegram binding shows up in PaperUI with no editable fields. I created the Thing via the bindingā€™s autoconfig now.
Thatā€™s the step I have been missing so far. Donā€™t forget to put that into the docs.

Possibly yes. Your response made me aware that I hadnā€™t created that yet.
But even now that Iā€™ve added it, same error. Hesitating to restart OH.

Yes you need to config the Telegram Thing first (if preferably you use PaperUI). I might be wrong in terms of used names here, but there is no binding configuration which some binding has, you can specify all parameters and settings at Thing level (when you create your Telegram Thing Bot).

Even the RulesDSL has this kind of problem. It wonā€™t work until you restart. And if you restart just that bundle it wonā€™t work also (at least for me).

I will try. But what is wrong with the action page? It is clearly a v1 Action and has nothing to do with this v2 binding.

Restarted now but it didnā€™t help.

Youā€™re right, the action doc page is fine as-is. But we should stop speaking of a Telegram action and from now refer to the binding to avoid misunderstandings (yes, itā€™s still telegram ā€˜actionsā€™ to use inside the code, but no OH(1) action any more).

Yes you are right. Maybe this thread should be edited with a new, simpler name. The confusion is caused by, because earlier you really needed to install an updated Action to use these features. But now everything is merged into the binding.

I somehow assumed, that the old Telegram action will be finally removed by the maintainers. On Github there is a table what actions will be replaced: https://github.com/openhab/openhab2-addons/issues/6179
Maybe we should raise an issue or maybe there was a reason to keep it?

But yes, the action and the binding shouldnā€™t be used in parallel!

I would also vote for closing this thread and create a new one in case there are issues. There is too much old information in here.

Agreed and done.
On my first steps I did both, creating a new Binding and editing the action.

Agreed

Well, thatā€™s a long term plan to retire all OH1 bindings (and all actions) at some point around OH3, but this is not meant to be handled per binding but in one go. The issue you linked was merely to collect information as first we need to determine whatā€™s in use, where do v2 bindings exist as a replacement etc. Now with this binding to fully replace the v1 action thereā€™s no need left for you to take action now.

I can close it if you like but thatā€™ll not stop its posts from appearing in search results.

Still having trouble, the following python code should work

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

What would need to be the 2nd argument to actions.get?
just the name of that Thing? Is that arbitrary, i.e. whatever I call the Thing to be named ?
Or does it have to be some specially coded string with special tags like telegram:telegramBot: ?

The 2nd line fails because the first does not return an object so I have a ā€˜NoneTypeā€™ object, i.e. NULL.
Probably because I can see the Thing is offline. I gave token and chatID in PaperUI.
Any idea how to debug that ?

Yes it is the name of the Thing. If you use Thing files, then what you declared there. If you use PaperUI, you will see it in the Things tab.

I have this in PaperUI. So it must be:

telegram = actions.get("telegram", "telegram:telegramBot:d7544ea3")

for me

Thanks. The Thing got online for a while but after I changed the formatting type it went offline again ??

And
2019-12-16 23:36:22.776 [WARN ] [binding.telegram.bot.TelegramActions] - Failed to send telegram message: Unauthorized

Hmm, that still seems like for me that it has some problems with the tokenā€¦ But I donā€™t know what can be wrong there.
Or maybe chatId. But that is not a validated value if Iā€™m right. Only token.

Ah, it was a typo in the token. Not sure why it temporarily went ONLINE with the wrong one but ok.
now it works, thanks for your patience!

No problem :slight_smile:
However I have seen this behaviour in multiple bindings. I donā€™t know how these are handled, but maybe some default behaviour is to go ONLINE after saving? And clearly validating these values takes some timeā€¦

Iā€™m trying to work out the new Tgram binding, however when I enter the ChatID, it show somekind of empty drop down, simce like its looking for something.
And most important, I canā€™t save the thing :frowning:

Same API/ChatID from working Telegram action configuration

Enter the chatID and press RETURN
Afterwards you can save the Thing

1 Like

The problem here is that there is no acknowledgment whether the connection to the Telegram server was successfully established. So what the binding does is, it creates a connection, sets the thing to ONLINE and in case there is an error, a callback is called by the underlying Telegram library. In that callback we check for the 401 error code (ā€œUnauthorizedā€) which usually means that the token is wrong and sets the thing back to OFFLINE.
However, if everything went fine, there is no callback called, so itā€™s also not possible to set the status to ONLINE later. In addition, we have to distinguish somehow between a ā€œconfiguration errorā€ meaning that e.g. the login data is wrong and a ā€œper message errorā€ meaning that there was only a problem with a particular message, but not with the general configuration (which should not set the status to OFFLINE).