[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 <matt@pcmus.com>pull/11145/head
parent
c084ec3a5b
commit
300ed046a8
|
@ -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>
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -419,7 +419,7 @@ public class TelegramHandler extends BaseThingHandler {
|
|||
|
||||
@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;
|
||||
}
|
||||
|
|
|
@ -312,9 +312,9 @@ public class TelegramActions implements ThingActions {
|
|||
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
|
||||
|
@ -326,6 +326,7 @@ public class TelegramActions implements ThingActions {
|
|||
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) {
|
||||
|
@ -450,6 +451,7 @@ public class TelegramActions implements ThingActions {
|
|||
} 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) {
|
||||
|
@ -527,6 +529,7 @@ public class TelegramActions implements ThingActions {
|
|||
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) {
|
||||
|
|
Loading…
Reference in New Issue