X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/404063a080a1a8784a1111304cc6b90b58362923..b178c7c67aea7bf334cbf0d54a4666af0a65b5d9:/src/main/java/org/asamk/signal/commands/SendCommand.java diff --git a/src/main/java/org/asamk/signal/commands/SendCommand.java b/src/main/java/org/asamk/signal/commands/SendCommand.java index 74209feb..4ad75e95 100644 --- a/src/main/java/org/asamk/signal/commands/SendCommand.java +++ b/src/main/java/org/asamk/signal/commands/SendCommand.java @@ -7,8 +7,8 @@ import net.sourceforge.argparse4j.inf.Subparser; import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.UnexpectedErrorException; import org.asamk.signal.commands.exceptions.UserErrorException; -import org.asamk.signal.manager.AttachmentInvalidException; import org.asamk.signal.manager.Manager; +import org.asamk.signal.manager.api.AttachmentInvalidException; import org.asamk.signal.manager.api.InvalidStickerException; import org.asamk.signal.manager.api.Message; import org.asamk.signal.manager.api.RecipientIdentifier; @@ -51,7 +51,11 @@ public class SendCommand implements JsonRpcLocalCommand { .help("Send the message to self without notification.") .action(Arguments.storeTrue()); - subparser.addArgument("-m", "--message").help("Specify the message, if missing standard input is used."); + var mut = subparser.addMutuallyExclusiveGroup(); + mut.addArgument("-m", "--message").help("Specify the message to be sent."); + mut.addArgument("--message-from-stdin") + .action(Arguments.storeTrue()) + .help("Read the message from standard input."); subparser.addArgument("-a", "--attachment").nargs("*").help("Add file as attachment"); subparser.addArgument("-e", "--end-session", "--endsession") .help("Clear session state and send end session message.") @@ -68,6 +72,11 @@ public class SendCommand implements JsonRpcLocalCommand { .nargs("*") .help("Quote with mention of another group member (syntax: start:length:recipientNumber)"); subparser.addArgument("--sticker").help("Send a sticker (syntax: stickerPackId:stickerId)"); + subparser.addArgument("--preview-url") + .help("Specify the url for the link preview (the same url must also appear in the message body)."); + subparser.addArgument("--preview-title").help("Specify the title for the link preview (mandatory)."); + subparser.addArgument("--preview-description").help("Specify the description for the link preview (optional)."); + subparser.addArgument("--preview-image").help("Specify the image file for the link preview (optional)."); } @Override @@ -107,16 +116,13 @@ public class SendCommand implements JsonRpcLocalCommand { final var sticker = stickerString == null ? null : parseSticker(stickerString); var messageText = ns.getString("message"); - if (messageText == null) { - if (sticker != null) { - messageText = ""; - } else { - logger.debug("Reading message from stdin..."); - try { - messageText = IOUtils.readAll(System.in, Charset.defaultCharset()); - } catch (IOException e) { - throw new UserErrorException("Failed to read message from stdin: " + e.getMessage()); - } + final var readMessageFromStdin = ns.getBoolean("message-from-stdin") == Boolean.TRUE; + if (readMessageFromStdin || (messageText == null && sticker == null)) { + logger.debug("Reading message from stdin..."); + try { + messageText = IOUtils.readAll(System.in, Charset.defaultCharset()); + } catch (IOException e) { + throw new UserErrorException("Failed to read message from stdin: " + e.getMessage()); } } @@ -145,12 +151,27 @@ public class SendCommand implements JsonRpcLocalCommand { quote = null; } + final List previews; + String previewUrl = ns.getString("preview-url"); + if (previewUrl != null) { + String previewTitle = ns.getString("preview-title"); + String previewDescription = ns.getString("preview-description"); + String previewImage = ns.getString("preview-image"); + previews = List.of(new Message.Preview(previewUrl, + Optional.ofNullable(previewTitle).orElse(""), + Optional.ofNullable(previewDescription).orElse(""), + Optional.ofNullable(previewImage))); + } else { + previews = List.of(); + } + try { - var results = m.sendMessage(new Message(messageText, + var results = m.sendMessage(new Message(messageText == null ? "" : messageText, attachments, mentions, Optional.ofNullable(quote), - Optional.ofNullable(sticker)), recipientIdentifiers); + Optional.ofNullable(sticker), + previews), recipientIdentifiers); outputResult(outputWriter, results); } catch (AttachmentInvalidException | IOException e) { throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()