Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[telegram] Update chat id before message text and other channels #11048

Closed
valpackett opened this issue Jul 22, 2021 · 4 comments · Fixed by #11215
Closed

[telegram] Update chat id before message text and other channels #11048

valpackett opened this issue Jul 22, 2021 · 4 comments · Fixed by #11215
Labels
bug An unexpected problem or unintended behavior of an add-on

Comments

@valpackett
Copy link

Expected Behavior

In a "LastMessageText was updated to /something" rule, the script should be able to run something like sendTelegram(Long::parseLong(TelegramBot_ChatId.state.toString), …) and that should send the message to the chat where the command came from.

Current Behavior

ChatId is updated after LastMessageText:

updateChannel(LASTMESSAGETEXT, lastMessageText != null ? new StringType(lastMessageText) : UnDefType.NULL);
updateChannel(LASTMESSAGEURL, lastMessageURL != null ? new StringType(lastMessageURL) : UnDefType.NULL);
updateChannel(LASTMESSAGEDATE, lastMessageDate != null
? new DateTimeType(
ZonedDateTime.ofInstant(Instant.ofEpochSecond(lastMessageDate.intValue()), ZoneOffset.UTC))
: UnDefType.NULL);
updateChannel(LASTMESSAGENAME, (lastMessageFirstName != null || lastMessageLastName != null)
? new StringType((lastMessageFirstName != null ? lastMessageFirstName + " " : "")
+ (lastMessageLastName != null ? lastMessageLastName : ""))
: UnDefType.NULL);
updateChannel(LASTMESSAGEUSERNAME,
lastMessageUsername != null ? new StringType(lastMessageUsername) : UnDefType.NULL);
updateChannel(CHATID, chatId != null ? new StringType(chatId.toString()) : UnDefType.NULL);
updateChannel(REPLYID, replyId != null ? new StringType(replyId) : UnDefType.NULL);

So when the last chat changes, one message goes to the wrong chat.

Possible Solution

Reorder these lines of code?

@valpackett valpackett added the bug An unexpected problem or unintended behavior of an add-on label Jul 22, 2021
@Skinah
Copy link
Contributor

Skinah commented Aug 18, 2021

Yes I agree that makes sense to reorder them.

CHATID and REPLYID should be updated first with LASTMESSAGETEXT being second last, and LASTMESSAGEDATE being the very last. Reasoning is that the LASTMESSAGETEXT may be the same for multiple messages in a row (?) and some people may trigger rules based off when LASTMESSAGEDATE changes.

How does that sound as I am not yet sending two way messages on my system.

@valpackett
Copy link
Author

Yeah, makes sense.

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/telegram-sendtelegramanswer-works-but-error-in-log-file-null-in-xxx/126039/6

@Skinah
Copy link
Contributor

Skinah commented Sep 6, 2021

Change has been made. Trying it out on my system for a few days and then will make a PR.

Jar to try can be downloaded from http://pcmus.com/openhab/telegram/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants