[telegram] Fixes exceptions that stop rules/actions from finishing (#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>pull/11241/head
parent
ce8fac8df2
commit
d0c435b9bd
|
@ -156,7 +156,7 @@ public class TelegramHandler extends BaseThingHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
OkHttpClient.Builder prepareConnection = new OkHttpClient.Builder().connectTimeout(75, TimeUnit.SECONDS)
|
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();
|
String proxyHost = config.getProxyHost();
|
||||||
Integer proxyPort = config.getProxyPort();
|
Integer proxyPort = config.getProxyPort();
|
||||||
|
@ -324,20 +324,20 @@ public class TelegramHandler extends BaseThingHandler {
|
||||||
update.callbackQuery().data());
|
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(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)
|
updateChannel(LASTMESSAGENAME, (lastMessageFirstName != null || lastMessageLastName != null)
|
||||||
? new StringType((lastMessageFirstName != null ? lastMessageFirstName + " " : "")
|
? new StringType((lastMessageFirstName != null ? lastMessageFirstName + " " : "")
|
||||||
+ (lastMessageLastName != null ? lastMessageLastName : ""))
|
+ (lastMessageLastName != null ? lastMessageLastName : ""))
|
||||||
: UnDefType.NULL);
|
: UnDefType.NULL);
|
||||||
updateChannel(LASTMESSAGEUSERNAME,
|
updateChannel(LASTMESSAGEUSERNAME,
|
||||||
lastMessageUsername != null ? new StringType(lastMessageUsername) : UnDefType.NULL);
|
lastMessageUsername != null ? new StringType(lastMessageUsername) : UnDefType.NULL);
|
||||||
updateChannel(CHATID, chatId != null ? new StringType(chatId.toString()) : UnDefType.NULL);
|
updateChannel(LASTMESSAGETEXT, lastMessageText != null ? new StringType(lastMessageText) : UnDefType.NULL);
|
||||||
updateChannel(REPLYID, replyId != null ? new StringType(replyId) : UnDefType.NULL);
|
updateChannel(LASTMESSAGEDATE, lastMessageDate != null
|
||||||
|
? new DateTimeType(
|
||||||
|
ZonedDateTime.ofInstant(Instant.ofEpochSecond(lastMessageDate.intValue()), ZoneOffset.UTC))
|
||||||
|
: UnDefType.NULL);
|
||||||
}
|
}
|
||||||
return UpdatesListener.CONFIRMED_UPDATES_ALL;
|
return UpdatesListener.CONFIRMED_UPDATES_ALL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,10 @@ public class TelegramActions implements ThingActions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Integer messageId = localHandler.removeMessageId(chatId, replyId);
|
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);
|
logger.debug("remove messageId {} for chatId {} and replyId {}", messageId, chatId, replyId);
|
||||||
|
|
||||||
EditMessageReplyMarkup editReplyMarkup = new EditMessageReplyMarkup(chatId, messageId.intValue())
|
EditMessageReplyMarkup editReplyMarkup = new EditMessageReplyMarkup(chatId, messageId.intValue())
|
||||||
|
@ -239,7 +243,12 @@ public class TelegramActions implements ThingActions {
|
||||||
logger.warn("replyId {} must not contain spaces. ReplyMarkup will be ignored.", replyId);
|
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)) {
|
if (!evaluateResponse(retMessage)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue