Telegram message sending

Running 3.1.0M3 on CentOS8

I’ve added the Telegram binding, setup the bot and can send messages via the web and telegram API. I have these items set up in my model:

nameBot 
nameBot_ChatId
nameBot_LastMessageUsername
nameBot_LastMessageText
nameBot_LastMessageURL
nameBot_LastMessageDate 
nameBot_LastMessageName 
nameBot_ReplyId

I’m trying to set up a rule so when a z-wave doorbell is rung a message is sent to the telegram bot. So far I’ve not been able to find where I define the message to send. Can somebody share the code for their rule if they have this working?

I tried using the text rule I had working in OH2.5 but I get a java error with that when I manually run the rule.

Rule:

rule "Door bell notification & image to namebot"
when
  Item zwave_device_zwave_node19_switch_binary changed from ON to OFF
then
  sendTelegram("nameBot", "Doorbell was rung, image to follow.")
end

Error:

2021-04-24 07:32:03.214 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'doorbell-1' failed: An error occurred during the script execution
: Could not invoke method: org.openhab.binding.telegram.internal.action.TelegramActions.sendTelegram(org.openhab.core.thing.binding.ThingActions,java.lang.String,java.lang.O
bject[]) on instance: null in doorbell

In your rule you need to use:

val telegramAction = getActions("telegram","telegram:telegramBot:<your_botid_here_same_as_in_thing_definition>")
telegramAction.sendTelegram("Doorbell was rung, image to follow.")

in the last row you also could add the id of the chat you would like to send a message to:

telegramAction.sendTelegram(-123456789L, "Doorbell was rung, image to follow.")

replace 123456789 with your chat’s id.

Thanks that’s working nicely.

1 Like