Skip to content

Commit

Permalink
[telegram] Fixes exceptions that stop rules/actions from finishing (o…
Browse files Browse the repository at this point in the history
…penhab#11215)

* reorder channel updates.

Signed-off-by: Matthew Skinner <matt@pcmus.com>

* catch exceptions.

Signed-off-by: Matthew Skinner <matt@pcmus.com>

* Spotless fixed

Signed-off-by: Matthew Skinner <matt@pcmus.com>

* increase timeout.

Signed-off-by: Matthew Skinner <matt@pcmus.com>

* Fix NPE in action from causing issues.

Signed-off-by: Matthew Skinner <matt@pcmus.com>

* fix logger.

Signed-off-by: Matthew Skinner <matt@pcmus.com>
Signed-off-by: Dave J Schoepel <dave@theschoepels.com>
  • Loading branch information
Skinah authored and dschoepel committed Nov 9, 2021
1 parent 80e813e commit 92a4148
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void initialize() {
}

OkHttpClient.Builder prepareConnection = new OkHttpClient.Builder().connectTimeout(75, TimeUnit.SECONDS)
.readTimeout(75, TimeUnit.SECONDS);
.writeTimeout(75, TimeUnit.SECONDS).readTimeout(75, TimeUnit.SECONDS);

String proxyHost = config.getProxyHost();
Integer proxyPort = config.getProxyPort();
Expand Down Expand Up @@ -324,20 +324,20 @@ private int handleUpdates(List<Update> updates) {
update.callbackQuery().data());
}
}
updateChannel(LASTMESSAGETEXT, lastMessageText != null ? new StringType(lastMessageText) : UnDefType.NULL);
updateChannel(CHATID, chatId != null ? new StringType(chatId.toString()) : UnDefType.NULL);
updateChannel(REPLYID, replyId != null ? new StringType(replyId) : 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);
updateChannel(LASTMESSAGETEXT, lastMessageText != null ? new StringType(lastMessageText) : UnDefType.NULL);
updateChannel(LASTMESSAGEDATE, lastMessageDate != null
? new DateTimeType(
ZonedDateTime.ofInstant(Instant.ofEpochSecond(lastMessageDate.intValue()), ZoneOffset.UTC))
: UnDefType.NULL);
}
return UpdatesListener.CONFIRMED_UPDATES_ALL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public boolean sendTelegramAnswer(@ActionInput(name = "chatId") @Nullable Long c
}
}
Integer messageId = localHandler.removeMessageId(chatId, replyId);
if (messageId == null) {
logger.warn("messageId could not be found for chatId {} and replyId {}", chatId, replyId);
return false;
}
logger.debug("remove messageId {} for chatId {} and replyId {}", messageId, chatId, replyId);

EditMessageReplyMarkup editReplyMarkup = new EditMessageReplyMarkup(chatId, messageId.intValue())
Expand Down Expand Up @@ -239,7 +243,12 @@ private boolean sendTelegramGeneral(@ActionInput(name = "chatId") @Nullable Long
logger.warn("replyId {} must not contain spaces. ReplyMarkup will be ignored.", replyId);
}
}
SendResponse retMessage = localHandler.execute(sendMessage);
SendResponse retMessage = null;
try {
retMessage = localHandler.execute(sendMessage);
} catch (Exception e) {
logger.warn("Exception occured whilst sending message:{}", e.getMessage());
}
if (!evaluateResponse(retMessage)) {
return false;
}
Expand Down

0 comments on commit 92a4148

Please sign in to comment.