Added support to send an Image directly (#11346)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp
2021-10-09 15:35:18 +02:00
committed by GitHub
parent 83fd01498a
commit becb8a48f4
4 changed files with 24 additions and 6 deletions

View 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()) {

View 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".

View 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".