]> git.basschouten.com Git - openhab-addons.git/commitdiff
Added support to send an Image directly (#11346)
authorChristoph Weitkamp <github@christophweitkamp.de>
Sat, 9 Oct 2021 13:35:18 +0000 (15:35 +0200)
committerGitHub <noreply@github.com>
Sat, 9 Oct 2021 13:35:18 +0000 (15:35 +0200)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
bundles/org.openhab.binding.pushsafer/README.md
bundles/org.openhab.binding.pushsafer/src/main/java/org/openhab/binding/pushsafer/internal/connection/PushsaferMessageBuilder.java
bundles/org.openhab.binding.pushsafer/src/main/resources/OH-INF/i18n/pushsafer.properties
bundles/org.openhab.binding.pushsafer/src/main/resources/OH-INF/i18n/pushsafer_de.properties

index 220287f1966bf243322651697d74423419640e9e..727cd9e6c336c44ac91bf2af89eb7f559923336a 100644 (file)
@@ -47,8 +47,23 @@ The parameter `message` is **mandatory**, the `title` parameter defaults to what
 
 - `sendPushsaferMonospaceMessage(String message, @Nullable String title)` - This method is used to send a monospace message.
 
-- `sendPushsaferAttachmentMessage(String message, @Nullable String title, String attachment, @Nullable String contentType, @Nullable String authentication)` - This method is used to send a message with an image attachment. It takes a local path or url to the image attachment (parameter `attachment` **mandatory**), an optional `contentType` to define the content-type of the attachment (default: `"jpeg"`, possible values: `"jpeg"`, `"png"`, `"gif"`) and an optional `authentication` for the given URL to define the authentication if needed (default: `""`, example: `"user:password"`).
+- `sendPushsaferAttachmentMessage(String message, @Nullable String title, String attachment, @Nullable String contentType, @Nullable String authentication)` - This method is used to send a message with an image attachment. It takes a local path or URL to the image attachment (parameter `attachment` **mandatory**), an optional `contentType` to define the content-type of the attachment (default: `"jpeg"`, possible values: `"jpeg"`, `"png"`, `"gif"`) and an optional `authentication` for the given URL to define the credentials to authenticate a user if needed (default: `""`, example: `"user:password"`).
 
 - `sendPushsaferURLMessage(String message, @Nullable String title, String url, @Nullable String urlTitle)` - This method is used to send a message with an URL. A supplementary `url` to show with the message and a `urlTitle` for the URL, otherwise just the URL is shown.
 
 - `sendPushsaferPriorityMessage(String message, @Nullable String title, @Nullable Integer priority)` - This method is used to send a priority message. Parameter `priority` is the priority (`-2`, `-1`, `0`, `1`, `2`) to be used (default: `2`).
+
+## Example
+
+demo.rules
+
+```java
+```java
+val actions = getActions("pushsafer", "pushsafer:pushsafer-account:account")
+// send message with attachment
+actions.sendPushsaferAttachmentMessage("Hello World!", "openHAB", "/path/to/my-local-image.png", "png", null)
+actions.sendPushsaferAttachmentMessage("Hello World!", "openHAB", "https://www.openhab.org/openhab-logo-square.png", "png", "user:password")
+actions.sendPushsaferAttachmentMessage("Hello World!", "openHAB", "data:[<media type>][;base64],<data>", null, null)
+// in case you want to send the content of an Image Item (RawType)
+actions.sendPushsaferAttachmentMessage("Hello World!", "openHAB", myImageItem.state.toFullString, null, null)
+```
index 958bedf692c3b6aa4bfc491ce5a3bc1a63d31f53..a009ee9fc83c835505bc83bf8a4b0007bbf46a8e 100644 (file)
@@ -310,9 +310,10 @@ public class PushsaferMessageBuilder {
         body.addFieldPart(MESSAGE_KEY_TIME2LIVE, new StringContentProvider(String.valueOf(time2live)), null);
 
         if (attachment != null) {
+            String localAttachment = attachment;
             final String encodedString;
             try {
-                if (attachment.startsWith("http")) {
+                if (localAttachment.startsWith("http")) {
                     Properties headers = new Properties();
                     headers.put("User-Agent", "Mozilla/5.0");
                     if (!authentication.isBlank()) {
@@ -324,7 +325,9 @@ public class PushsaferMessageBuilder {
                         throw new IllegalArgumentException(
                                 String.format("Skip sending the message as content '%s' does not exist.", attachment));
                     }
-                    encodedString = "data:" + contentType + ";base64," + content;
+                    encodedString = "data:image/" + contentType + ";base64," + content;
+                } else if (localAttachment.startsWith("data:")) {
+                    encodedString = localAttachment;
                 } else {
                     File file = new File(attachment);
                     if (!file.exists()) {
index 8b4177f90b2751abc02d303d6b168e5db7ada377..e43d12e6e12573e8e3020b064a1160d0e8b81fd6 100644 (file)
@@ -30,9 +30,9 @@ sendPushsaferMonospaceMessageActionDescription = This method is used to send a m
 sendPushsaferAttachmentMessageActionLabel = send a plain text message with an image attachment
 sendPushsaferAttachmentMessageActionDescription = This method is used to send a message with an image attachment.
 sendPushsaferMessageActionInputAttachmentLabel = Image Attachment
-sendPushsaferMessageActionInputAttachmentDescription = A local path or url to the image.
+sendPushsaferMessageActionInputAttachmentDescription = A local path or URL to the image.
 sendPushsaferMessageActionInputContentTypeLabel = Image Type
-sendPushsaferMessageActionInputContentTypeDescription = The image type of the attachment. Defaults to "jpeg", possible values "jpeg,png,gif".
+sendPushsaferMessageActionInputContentTypeDescription = The image type of the attachment. Defaults to "jpeg", possible values "jpeg" ,"png" or "gif".
 sendPushsaferMessageActionInputAuthenticationLabel = Authentication
 sendPushsaferMessageActionInputAuthenticationDescription = Basic access authentication for HTTP(S) requests. Default: "", Example: "user:password".
 
index 2b84da47cf257bdf62913ee1487d129babf102a4..b1cfe68027d9b49d215ea392a5c9cdcd29a0f016 100644 (file)
@@ -73,7 +73,7 @@ sendPushsaferAttachmentMessageActionDescription = Action zum Versenden einer Tex
 sendPushsaferMessageActionInputAttachmentLabel = Bild-Anhang
 sendPushsaferMessageActionInputAttachmentDescription = Lokaler Pfad oder URL zum Anhang.
 sendPushsaferMessageActionInputContentTypeLabel = Bild-Typ
-sendPushsaferMessageActionInputContentTypeDescription = Der Bild-Typ für den Anhang. Default: "jpeg", mögliche Werte "jpeg,png,gif".
+sendPushsaferMessageActionInputContentTypeDescription = Der Bild-Typ für den Anhang. Default: "jpeg", mögliche Werte "jpeg", "png" oder "gif".
 sendPushsaferMessageActionInputAuthenticationLabel = Authentifizierung
 sendPushsaferMessageActionInputAuthenticationDescription = Basisauthentifizierung für HTTP(S) Aufrufe. Default: "", Beispiel: "user:passwort".