[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>
This commit is contained in:
parent
c084ec3a5b
commit
300ed046a8
@ -22,7 +22,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.pengrad</groupId>
|
<groupId>com.github.pengrad</groupId>
|
||||||
<artifactId>java-telegram-bot-api</artifactId>
|
<artifactId>java-telegram-bot-api</artifactId>
|
||||||
<version>4.9.0</version>
|
<version>5.2.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@ -41,5 +41,4 @@ public class TelegramBindingConstants {
|
|||||||
public static final String LASTMESSAGEUSERNAME = "lastMessageUsername";
|
public static final String LASTMESSAGEUSERNAME = "lastMessageUsername";
|
||||||
public static final String CHATID = "chatId";
|
public static final String CHATID = "chatId";
|
||||||
public static final String REPLYID = "replyId";
|
public static final String REPLYID = "replyId";
|
||||||
public static final String LONGPOLLINGTIME = "longPollingTime";
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -419,7 +419,7 @@ public class TelegramHandler extends BaseThingHandler {
|
|||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Nullable
|
@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;
|
TelegramBot localBot = bot;
|
||||||
return localBot != null ? localBot.execute(request) : null;
|
return localBot != null ? localBot.execute(request) : null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -312,9 +312,9 @@ public class TelegramActions implements ThingActions {
|
|||||||
if (username != null && password != null) {
|
if (username != null && password != null) {
|
||||||
AuthenticationStore auth = client.getAuthenticationStore();
|
AuthenticationStore auth = client.getAuthenticationStore();
|
||||||
URI uri = URI.create(photoURL);
|
URI uri = URI.create(photoURL);
|
||||||
auth.addAuthenticationResult(new BasicResult(HttpHeader.AUTHORIZATION, uri,
|
auth.addAuthenticationResult(
|
||||||
"Basic " + Base64.getEncoder().encodeToString(
|
new BasicResult(HttpHeader.AUTHORIZATION, uri, "Basic " + Base64.getEncoder()
|
||||||
(username + ":" + password).getBytes(StandardCharsets.ISO_8859_1))));
|
.encodeToString((username + ":" + password).getBytes(StandardCharsets.UTF_8))));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// API has 10mb limit to jpg file size, without this it can only accept 2mb
|
// 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);
|
sendPhoto = new SendPhoto(chatId, fileContent);
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Download from {} failed with status: {}", photoURL, contentResponse.getStatus());
|
logger.warn("Download from {} failed with status: {}", photoURL, contentResponse.getStatus());
|
||||||
|
sendTelegram(chatId, caption + ":Download failed with status " + contentResponse.getStatus());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
@ -450,6 +451,7 @@ public class TelegramActions implements ThingActions {
|
|||||||
} else {
|
} else {
|
||||||
logger.warn("Download from {} failed with status: {}", animationURL,
|
logger.warn("Download from {} failed with status: {}", animationURL,
|
||||||
contentResponse.getStatus());
|
contentResponse.getStatus());
|
||||||
|
sendTelegram(chatId, caption + ":Download failed with status " + contentResponse.getStatus());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
@ -527,6 +529,7 @@ public class TelegramActions implements ThingActions {
|
|||||||
sendVideo = new SendVideo(chatId, fileContent);
|
sendVideo = new SendVideo(chatId, fileContent);
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Download from {} failed with status: {}", videoURL, contentResponse.getStatus());
|
logger.warn("Download from {} failed with status: {}", videoURL, contentResponse.getStatus());
|
||||||
|
sendTelegram(chatId, caption + ":Download failed with status " + contentResponse.getStatus());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user