Skip to content

Commit 300ed04

Browse files
authored
[telegram] Send message if a file download fails and bug fixes. (#11125)
* Send message when pic/vid/ani fails to DL * Upgrade lib to 5.2.0 and fix error. Signed-off-by: Matthew Skinner <[email protected]>
1 parent c084ec3 commit 300ed04

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

bundles/org.openhab.binding.telegram/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<dependency>
2323
<groupId>com.github.pengrad</groupId>
2424
<artifactId>java-telegram-bot-api</artifactId>
25-
<version>4.9.0</version>
25+
<version>5.2.0</version>
2626
<scope>compile</scope>
2727
</dependency>
2828
<dependency>

bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramBindingConstants.java

-1
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,4 @@ public class TelegramBindingConstants {
4141
public static final String LASTMESSAGEUSERNAME = "lastMessageUsername";
4242
public static final String CHATID = "chatId";
4343
public static final String REPLYID = "replyId";
44-
public static final String LONGPOLLINGTIME = "longPollingTime";
4544
}

bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ public ParseMode getParseMode() {
419419

420420
@SuppressWarnings("rawtypes")
421421
@Nullable
422-
public <T extends BaseRequest, R extends BaseResponse> R execute(BaseRequest<T, R> request) {
422+
public <T extends BaseRequest, R extends BaseResponse> R execute(BaseRequest<?, R> request) {
423423
TelegramBot localBot = bot;
424424
return localBot != null ? localBot.execute(request) : null;
425425
}

bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/action/TelegramActions.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,9 @@ public boolean sendTelegramPhoto(@ActionInput(name = "chatId") @Nullable Long ch
312312
if (username != null && password != null) {
313313
AuthenticationStore auth = client.getAuthenticationStore();
314314
URI uri = URI.create(photoURL);
315-
auth.addAuthenticationResult(new BasicResult(HttpHeader.AUTHORIZATION, uri,
316-
"Basic " + Base64.getEncoder().encodeToString(
317-
(username + ":" + password).getBytes(StandardCharsets.ISO_8859_1))));
315+
auth.addAuthenticationResult(
316+
new BasicResult(HttpHeader.AUTHORIZATION, uri, "Basic " + Base64.getEncoder()
317+
.encodeToString((username + ":" + password).getBytes(StandardCharsets.UTF_8))));
318318
}
319319
try {
320320
// API has 10mb limit to jpg file size, without this it can only accept 2mb
@@ -326,6 +326,7 @@ public boolean sendTelegramPhoto(@ActionInput(name = "chatId") @Nullable Long ch
326326
sendPhoto = new SendPhoto(chatId, fileContent);
327327
} else {
328328
logger.warn("Download from {} failed with status: {}", photoURL, contentResponse.getStatus());
329+
sendTelegram(chatId, caption + ":Download failed with status " + contentResponse.getStatus());
329330
return false;
330331
}
331332
} catch (InterruptedException | ExecutionException e) {
@@ -450,6 +451,7 @@ public boolean sendTelegramAnimation(@ActionInput(name = "chatId") @Nullable Lon
450451
} else {
451452
logger.warn("Download from {} failed with status: {}", animationURL,
452453
contentResponse.getStatus());
454+
sendTelegram(chatId, caption + ":Download failed with status " + contentResponse.getStatus());
453455
return false;
454456
}
455457
} catch (InterruptedException | ExecutionException e) {
@@ -527,6 +529,7 @@ public boolean sendTelegramVideo(@ActionInput(name = "chatId") @Nullable Long ch
527529
sendVideo = new SendVideo(chatId, fileContent);
528530
} else {
529531
logger.warn("Download from {} failed with status: {}", videoURL, contentResponse.getStatus());
532+
sendTelegram(chatId, caption + ":Download failed with status " + contentResponse.getStatus());
530533
return false;
531534
}
532535
} catch (InterruptedException | ExecutionException e) {

0 commit comments

Comments
 (0)