[SOLVED][Telegram] sendTelegramAnswer works but error in log file 'null in xxx'

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

Is the rule stored in a file or in the DB? Try it in a file if not already doing so.

rule is in a file…
Is there a way to debug which value is NULL; sorry if this is a dumb question, still learning…

var result = getActions("telegram","telegram:t

If everything works then it may be the result that is null. Do the above then send the result to the logs to see if that is it.

I don’t use those actions yet but can give them a try soon as I want to get the newer feature working which is for inline keyboards.

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

What happens if you insert a delay to allow time for the other fields to be updated? Does this issue explain it?

I’m a little bit lost :man_shrugging:. There is only one line which is causing the problem, where should a put a delay in?

Hi. Try this code:

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")
	

Thanks for the hint! I did this:

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.

sorry, still new and sure as hell no programmer… :crazy_face:
added to example from above:

logInfo( "TestEntry2", "{}", telegramAction )
logInfo( "TestEntry3", "{}", TelegramBot_ReplyId )
logInfo( "TestEntry4", "{}", TelegramBot_ReplyId.state.toString)
telegramAction.sendTelegramAnswer(TelegramBot_ReplyId.state.toString, "Test Yes")
logInfo( "TestEntry_last", "after yes")

log:

2021-09-05 12:32:17.660 [INFO ] [openhab.core.model.script.TestEntry1] - before yes
2021-09-05 12:32:18.665 [INFO ] [openhab.core.model.script.TestEntry2] - org.openhab.binding.telegram.internal.action.TelegramActions@1168a25
2021-09-05 12:32:18.668 [INFO ] [openhab.core.model.script.TestEntry3] - TelegramBot_ReplyId (Type=StringItem, State=ReplyTest, Label=TelegramBot_ReplyId, Category=, Groups=[g_Telegram])
2021-09-05 12:32:18.671 [INFO ] [openhab.core.model.script.TestEntry4] - ReplyTest
2021-09-05 12:32:18.942 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'test-2' failed: null in test

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

...
val results = telegramAction.sendTelegramAnswer(TelegramBot_ReplyId.state.toString, "Test Yes")
logInfo( "TestEntry_last", "results {}", results)

now this way:

logInfo( "TestEntry1", "before yes")
val telegramAction = getActions("telegram","telegram:telegramBot:BOT")
Thread::sleep(1000)
logInfo( "TestEntry2", "{}", telegramAction )
logInfo( "TestEntry3", "{}", TelegramBot_ReplyId )
logInfo( "TestEntry4", "{}", TelegramBot_ReplyId.state.toString)
val results = telegramAction.sendTelegramAnswer(TelegramBot_ReplyId.state.toString, "Test Yes")
logInfo( "TestEntry6", "results" )
logInfo( "TestEntry7", "results {}", results)
telegramAction.sendTelegramAnswer(TelegramBot_ReplyId.state.toString, "Test Yes")
val results1 = telegramAction.sendTelegramAnswer(TelegramBot_ReplyId.state.toString, "Test Yes")
logInfo( "TestEntry8", "results {}", results1)

log:

2021-09-05 13:02:27.375 [INFO ] [openhab.core.model.script.TestEntry1] - before yes
2021-09-05 13:02:28.380 [INFO ] [openhab.core.model.script.TestEntry2] - org.openhab.binding.telegram.internal.action.TelegramActions@1168a25
2021-09-05 13:02:28.382 [INFO ] [openhab.core.model.script.TestEntry3] - TelegramBot_ReplyId (Type=StringItem, State=ReplyTest, Label=TelegramBot_ReplyId, Category=, Groups=[g_Telegram])
2021-09-05 13:02:28.385 [INFO ] [openhab.core.model.script.TestEntry4] - ReplyTest
2021-09-05 13:02:28.756 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'test-2' failed: null in test

I’m again lost, why is there no TestEntry6 or TestEntry7?
Answer is still getting through to Telegram…

Because it has blown up on executing
val results = telegramAction.sendTelegramAnswer(
so rule execution stops there.

There’s not much else you can with sendTelegramAnswer() apart from give it two strings, as you do.

That suggest both that the two strings are reasonable, and that you taken note of the stuff about bi-directional chat IDs in the binding notes.

Last roll of the dice is to set the binding to DEBUG logging and see if it offers clues.

Thanks, had to read the docs to activate debug mode (still learning) :face_with_monocle:
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?

Don’t know. This is now about your Telegram Thing configuration. I suppose you can’t answer to a group, or something like…

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.

It makes a sort of sense. You can’t acknowledge (answer) a message from someone that didn’t send you a message.

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.

1 Like

Yes, after all that here is the last time around this loop