]> git.basschouten.com Git - openhab-addons.git/commitdiff
[telegram] Send message if a file download fails and bug fixes. (#11125)
authorMatthew Skinner <matt@pcmus.com>
Sun, 22 Aug 2021 09:54:34 +0000 (19:54 +1000)
committerGitHub <noreply@github.com>
Sun, 22 Aug 2021 09:54:34 +0000 (11:54 +0200)
* 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>
bundles/org.openhab.binding.telegram/pom.xml
bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramBindingConstants.java
bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/TelegramHandler.java
bundles/org.openhab.binding.telegram/src/main/java/org/openhab/binding/telegram/internal/action/TelegramActions.java

index d16911c839d561b8862cfbce85ad2dff96b7b9b1..14a43d424b946a6c8439f3f5b2ce3d140fb0dcc6 100644 (file)
@@ -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>
index 1ec63509cb97ab2367529a017d0a72ed07b1a7ff..4c575a49d457e96f628129ec7be1770f51ef1132 100644 (file)
@@ -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";
 }
index fa6cb46effea8fe9ea0df2771a395c23e0bbc483..c47df21ddce7ba9a78be7c37e28dad4c3dafd8e6 100644 (file)
@@ -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;
     }
index 61932b4d73e918b9ffa89c7242b34a40c829ea68..f25c42eb8fbe0b268638a0dadeadf006daba4260 100644 (file)
@@ -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) {