openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.86k stars 3.56k forks source link

[Telegram] sendTelegram() to group #8706

Closed FrancescoRisso closed 3 years ago

FrancescoRisso commented 3 years ago

Hi all.

I created a Telegram bot to notify me when something happens on the OpenHab (e.g. a web server goes offline).

I wanted some notifications to be in my private chat, as for others to be in a group.

Originally I created two different Things for the same bot, with different chatIds. That worked fine, but now I had to look in the log for other reasons, and I spotted continuous messages Telegram exception: GetUpdates failed with error_code 409 Conflict: terminated by other getUpdates request; make sure that only one bot instance is running.

I understood what the problem was, and I changed the two Things to an only one with multiple chatIds. I went into the rules file and adapted it, using sendTelegram(chatId, "message"): it worked for the private chat, but not for the group (probably due to the negative number). It logs: [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Gruppo': 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

What can I do to solve it?

I also had some sendTelegramQuery()s and some sendTelegramAnswer()s to my private chat. In both cases, I added my chatId as first parameter, but it only works for the query: for the answer I get an error, similar to the previous one: [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Abbassamento automatico tapparelle - risposta': An error occurred during the script execution: Could not invoke method: org.openhab.binding.telegram.bot.TelegramActions.sendTelegramAnswer(org.eclipse.smarthome.core.thing.binding.ThingActions,java.lang.String,java.lang.String,java.lang.String) on instance: null

What can I do for this?

And, Is there a way to use a variable to store the chatId? I tried this, but it did not work, neither with the group nor with the private chat:

val chatId = 123456789

rule "myRule"
when
    [when]
then
    val telegramAction = getActions("telegram","telegram:telegramBot:2b155b22")
    telegramAction.sendTelegram(chatId, "Message")
end

It logged the same error as before ([ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Gruppo': 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)

Using OpenHab2 version 2.5.6-2 Using Telegram binding binding-telegram - 2.5.6

Sorry if it is not in the correct section, I wasn't sure where to put it.

Thanks for help. Francesco

J-N-K commented 3 years ago

Please try OH 2.5.9. I think this has been fixed by https://github.com/openhab/openhab-addons/pull/8141

FrancescoRisso commented 3 years ago

I have uninstalled OH and reinstalled it to have the latest version, OH version 2.5.9-1 and Telegram binding version 2.5.9

At the beginning it was still giving the error as before, so that was not the fix. Then I tried to add the "L" at the end of the chatId as in the example and it worked, both for the private chat, and for the group. If someone has the same problem, this is the solution.