I’m trying to get a Telegram rule working. Rule works but there is an error in the log file, any idea why?
rule "Test rule using sw_Test switch"
when
Item sw_Test changed from OFF to ON
then
getActions("telegram","telegram:telegramBot:xxxx").sendTelegramQuery(xxxxL, "Test question?", "Reply_test", "Yes", "No")
sw_Test.postUpdate(OFF)
end
rule "test rule"
when
Item TelegramBot_ReplyId received update Reply_test
then
if (TelegramBot_LastMessageText.state.toString == "Yes") {
getActions("telegram","telegram:telegramBot:xxxx").sendTelegramAnswer(TelegramBot_ReplyId.state.toString, "Test Yes")
}
else {
getActions("telegram","telegram:telegramBot:xxxx").sendTelegramAnswer(TelegramBot_ReplyId.state.toString, "Test No")
}
end
everything work, I get the question and the answer in my Telegram chat but also an ERROR log entry: Script execution of rule with UID 'test-2' failed: null in test
I’m a 100% sure that this line is the problem. But I don’t understand why.
The telegram action works and other telegram actions like sendTelegramQuery also work.
So sendTelegramAnswer seems to be the problem
val telegramAction = getActions("telegram","telegram:telegramBot:tBot")
Thread::sleep(200)
telegramAction.sendTelegramQuery("No one is at home, but some lights are still on. Do you want me to turn off the lights?", "Reply_Lights2", "Yes", "No")
rule "test rule"
when
Item TelegramBot_ReplyId received update ReplyTest
then
if (TelegramBot_LastMessageText.state.toString == "Yes") {
logInfo( "TestEntry", "before yes")
val telegramAction = getActions("telegram","telegram:telegramBot:BOT")
Thread::sleep(1000)
logInfo( "TestEntry", "{}", telegramAction )
telegramAction.sendTelegramAnswer(TelegramBot_ReplyId.state.toString, "Test Yes")
logInfo( "TestEntry", "after yes")
}
end
log shows this:
2021-09-05 12:18:40.914 [INFO ] [.openhab.core.model.script.TestEntry] - before yes
2021-09-05 12:18:41.920 [INFO ] [.openhab.core.model.script.TestEntry] - org.openhab.binding.telegram.internal.action.TelegramActions@1168a25
2021-09-05 12:18:42.227 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'test-2' failed: null in test
The after yes doesn’t appear in the log file, so the error line has to be telegramAction.sendTelegramAnswer(TelegramBot_ReplyId.state.toString, "Test Yes")
although the answer appears in Telegram
Well, what’s that for example? You can log that out too.
Although it does look more like your telegramAction object has no .sendTelegramAnswer method at this time.
That was a silly comment really, you keep telling us that you actually do get the answer message at your target client.
This looks like a binding bug really, but why blow up the rule? Maybe it has something to do with the return.
Just in case, try
Thanks, had to read the docs to activate debug mode (still learning)
I think you found the issue:
2021-09-05 13:46:02.542 [DEBUG] [gram.internal.action.TelegramActions] - AnswerCallbackQuery for chatId 11111111 and replyId ReplyTest is the callbackId 12345678901234
2021-09-05 13:46:02.646 [DEBUG] [gram.internal.action.TelegramActions] - remove messageId 111 for chatId 11111111 and replyId ReplyTest
2021-09-05 13:46:02.825 [DEBUG] [gram.internal.action.TelegramActions] - remove messageId null for chatId -222222222 and replyId ReplyTest
2021-09-05 13:46:02.827 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'test-2' failed: null in test
There is the error in line 3! The second chatId is the group where my bot is a member of.
Is this my fault? Do I have to change my script?
I did some more testing. Currently, my bot has 2 ChatIds, one is a personal chat with myself and one is a ChatID of a group/supergroup.
I tried to alter the Telegram thing config and tested with only one ChatID (tested on time with the personal ID and one time with the group ChatID) → both time → working without a warning or error.
So the problem exists when the Telegram thing has 2 ChatIDs.
I think, I will post this in the mail Telegram channel and will seek advice. Followed up by a issue ticket if necessary and useful.
Thanks to all for taking time and point me to the right direction.
Most actions have more than 1 overloaded form. That means you can use an action specifying the exact chatID to use and if you use the version that misses chatIDs then it try’s to send it to all of them that the bot has. The readme for clarity does not list all versions of the actions and just mentions this in passing.
Feel free to change the docs to make it clearer as a reword or an exact example may help to make this clearer.