mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
Add --message-from-stdin flag for send command
This commit is contained in:
parent
f3b2df62da
commit
ec945cd227
3 changed files with 22 additions and 16 deletions
|
@ -25,7 +25,8 @@ System requirements:
|
||||||
- at least Java Runtime Environment (JRE) 17
|
- at least Java Runtime Environment (JRE) 17
|
||||||
- native library: libsignal-client
|
- native library: libsignal-client
|
||||||
|
|
||||||
The native libs are bundled for x86_64 Linux (with recent enough glibc, see #643), Windows and MacOS. For other systems/architectures
|
The native libs are bundled for x86_64 Linux (with recent enough glibc, see #643), Windows and MacOS. For other
|
||||||
|
systems/architectures
|
||||||
see: [Provide native lib for libsignal](https://github.com/AsamK/signal-cli/wiki/Provide-native-lib-for-libsignal)
|
see: [Provide native lib for libsignal](https://github.com/AsamK/signal-cli/wiki/Provide-native-lib-for-libsignal)
|
||||||
|
|
||||||
### Install system-wide on Linux
|
### Install system-wide on Linux
|
||||||
|
@ -75,7 +76,7 @@ of all country codes.)
|
||||||
|
|
||||||
* Pipe the message content from another process.
|
* Pipe the message content from another process.
|
||||||
|
|
||||||
uname -a | signal-cli -a ACCOUNT send RECIPIENT
|
uname -a | signal-cli -a ACCOUNT send --message-from-stdin RECIPIENT
|
||||||
|
|
||||||
* Receive messages
|
* Receive messages
|
||||||
|
|
||||||
|
|
|
@ -212,7 +212,11 @@ Send the message to self without notification.
|
||||||
Specify the recipient group ID in base64 encoding.
|
Specify the recipient group ID in base64 encoding.
|
||||||
|
|
||||||
*-m* MESSAGE, *--message* MESSAGE::
|
*-m* MESSAGE, *--message* MESSAGE::
|
||||||
Specify the message, if missing, standard input is used.
|
Specify the message.
|
||||||
|
Currently, signal-cli reads the message from stdin if `-m` is missing, but this will change in a future version and the explicit flag `--message-from-stdin` should be used instead.
|
||||||
|
|
||||||
|
*--message-from-stdin*::
|
||||||
|
Read the message from standard input.
|
||||||
|
|
||||||
*-a* [ATTACHMENT [ATTACHMENT ...]], *--attachment* [ATTACHMENT [ATTACHMENT ...]]::
|
*-a* [ATTACHMENT [ATTACHMENT ...]], *--attachment* [ATTACHMENT [ATTACHMENT ...]]::
|
||||||
Add one or more files as attachment.
|
Add one or more files as attachment.
|
||||||
|
@ -578,7 +582,7 @@ Send a message to one or more recipients::
|
||||||
signal-cli -a ACCOUNT send -m "This is a message" [RECIPIENT [RECIPIENT ...]] [-a [ATTACHMENT [ATTACHMENT ...]]]
|
signal-cli -a ACCOUNT send -m "This is a message" [RECIPIENT [RECIPIENT ...]] [-a [ATTACHMENT [ATTACHMENT ...]]]
|
||||||
|
|
||||||
Pipe the message content from another process::
|
Pipe the message content from another process::
|
||||||
uname -a | signal-cli -a ACCOUNT send [RECIPIENT [RECIPIENT ...]]
|
uname -a | signal-cli -a ACCOUNT send --message-from-stdin [RECIPIENT [RECIPIENT ...]]
|
||||||
|
|
||||||
Create a group::
|
Create a group::
|
||||||
signal-cli -a ACCOUNT updateGroup -n "Group name" -m [MEMBER [MEMBER ...]]
|
signal-cli -a ACCOUNT updateGroup -n "Group name" -m [MEMBER [MEMBER ...]]
|
||||||
|
|
|
@ -51,7 +51,11 @@ public class SendCommand implements JsonRpcLocalCommand {
|
||||||
.help("Send the message to self without notification.")
|
.help("Send the message to self without notification.")
|
||||||
.action(Arguments.storeTrue());
|
.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("-a", "--attachment").nargs("*").help("Add file as attachment");
|
||||||
subparser.addArgument("-e", "--end-session", "--endsession")
|
subparser.addArgument("-e", "--end-session", "--endsession")
|
||||||
.help("Clear session state and send end session message.")
|
.help("Clear session state and send end session message.")
|
||||||
|
@ -107,10 +111,8 @@ public class SendCommand implements JsonRpcLocalCommand {
|
||||||
final var sticker = stickerString == null ? null : parseSticker(stickerString);
|
final var sticker = stickerString == null ? null : parseSticker(stickerString);
|
||||||
|
|
||||||
var messageText = ns.getString("message");
|
var messageText = ns.getString("message");
|
||||||
if (messageText == null) {
|
final var readMessageFromStdin = ns.getBoolean("message-from-stdin") == Boolean.TRUE;
|
||||||
if (sticker != null) {
|
if (readMessageFromStdin || (messageText == null && sticker == null)) {
|
||||||
messageText = "";
|
|
||||||
} else {
|
|
||||||
logger.debug("Reading message from stdin...");
|
logger.debug("Reading message from stdin...");
|
||||||
try {
|
try {
|
||||||
messageText = IOUtils.readAll(System.in, Charset.defaultCharset());
|
messageText = IOUtils.readAll(System.in, Charset.defaultCharset());
|
||||||
|
@ -118,7 +120,6 @@ public class SendCommand implements JsonRpcLocalCommand {
|
||||||
throw new UserErrorException("Failed to read message from stdin: " + e.getMessage());
|
throw new UserErrorException("Failed to read message from stdin: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
List<String> attachments = ns.getList("attachment");
|
List<String> attachments = ns.getList("attachment");
|
||||||
if (attachments == null) {
|
if (attachments == null) {
|
||||||
|
@ -146,7 +147,7 @@ public class SendCommand implements JsonRpcLocalCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var results = m.sendMessage(new Message(messageText,
|
var results = m.sendMessage(new Message(messageText == null ? "" : messageText,
|
||||||
attachments,
|
attachments,
|
||||||
mentions,
|
mentions,
|
||||||
Optional.ofNullable(quote),
|
Optional.ofNullable(quote),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue