Skip to content

Commit

Permalink
[telegram] Send message if a file download fails and bug fixes. (open…
Browse files Browse the repository at this point in the history
…hab#11125)

* Send message when pic/vid/ani fails to DL
* Upgrade lib to 5.2.0 and fix error.

Signed-off-by: Matthew Skinner <matt@pcmus.com>
  • Loading branch information
Skinah authored and frederictobiasc committed Oct 26, 2021
1 parent f52b7c2 commit 10bfa6c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.telegram/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>com.github.pengrad</groupId>
<artifactId>java-telegram-bot-api</artifactId>
<version>4.9.0</version>
<version>5.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ public class TelegramBindingConstants {
public static final String LASTMESSAGEUSERNAME = "lastMessageUsername";
public static final String CHATID = "chatId";
public static final String REPLYID = "replyId";
public static final String LONGPOLLINGTIME = "longPollingTime";
}
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public ParseMode getParseMode() {

@SuppressWarnings("rawtypes")
@Nullable
public <T extends BaseRequest, R extends BaseResponse> R execute(BaseRequest<T, R> request) {
public <T extends BaseRequest, R extends BaseResponse> R execute(BaseRequest<?, R> request) {
TelegramBot localBot = bot;
return localBot != null ? localBot.execute(request) : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ public boolean sendTelegramPhoto(@ActionInput(name = "chatId") @Nullable Long ch
if (username != null && password != null) {
AuthenticationStore auth = client.getAuthenticationStore();
URI uri = URI.create(photoURL);
auth.addAuthenticationResult(new BasicResult(HttpHeader.AUTHORIZATION, uri,
"Basic " + Base64.getEncoder().encodeToString(
(username + ":" + password).getBytes(StandardCharsets.ISO_8859_1))));
auth.addAuthenticationResult(
new BasicResult(HttpHeader.AUTHORIZATION, uri, "Basic " + Base64.getEncoder()
.encodeToString((username + ":" + password).getBytes(StandardCharsets.UTF_8))));
}
try {
// API has 10mb limit to jpg file size, without this it can only accept 2mb
Expand All @@ -326,6 +326,7 @@ public boolean sendTelegramPhoto(@ActionInput(name = "chatId") @Nullable Long ch
sendPhoto = new SendPhoto(chatId, fileContent);
} else {
logger.warn("Download from {} failed with status: {}", photoURL, contentResponse.getStatus());
sendTelegram(chatId, caption + ":Download failed with status " + contentResponse.getStatus());
return false;
}
} catch (InterruptedException | ExecutionException e) {
Expand Down Expand Up @@ -450,6 +451,7 @@ public boolean sendTelegramAnimation(@ActionInput(name = "chatId") @Nullable Lon
} else {
logger.warn("Download from {} failed with status: {}", animationURL,
contentResponse.getStatus());
sendTelegram(chatId, caption + ":Download failed with status " + contentResponse.getStatus());
return false;
}
} catch (InterruptedException | ExecutionException e) {
Expand Down Expand Up @@ -527,6 +529,7 @@ public boolean sendTelegramVideo(@ActionInput(name = "chatId") @Nullable Long ch
sendVideo = new SendVideo(chatId, fileContent);
} else {
logger.warn("Download from {} failed with status: {}", videoURL, contentResponse.getStatus());
sendTelegram(chatId, caption + ":Download failed with status " + contentResponse.getStatus());
return false;
}
} catch (InterruptedException | ExecutionException e) {
Expand Down

0 comments on commit 10bfa6c

Please sign in to comment.