mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-02 12:30:39 +00:00
switched to having JSON input
This commit is contained in:
parent
5f9d4f89e6
commit
c3c935fbf4
4 changed files with 46 additions and 16 deletions
10
README.md
10
README.md
|
@ -1,3 +1,13 @@
|
||||||
|
This fork changes the daemon command to read commands as JSON from stdin instead of exporting a DBus interface. It also includes reactions in JSON output.
|
||||||
|
|
||||||
|
Currently, only sendMessage is available. The JSON interface is {"command": "sendMessage", "recipient": number, "content": message, "details": {"attachments": []}}. The details field is optional. As far as I can tell, attachments must be full absolute file paths.
|
||||||
|
|
||||||
|
TODOs:
|
||||||
|
- acknowledge commands received from stdin in valid JSON output instead of freeform text
|
||||||
|
- feature parity with DBus interface and ideally CLI
|
||||||
|
- allow typing indicators to be sent and received
|
||||||
|
- include quotes in JSON output
|
||||||
|
- ideally, expose message IDs referenced by quotes
|
||||||
this is patched such that the daemon command reads recipient:message pairs from stdin instead of exporting an object to dbus while outputing json as normal (though it currently also outputs "sent $msg to $recipient" in response to input as well). it also includes reactions in output, and will include quotes.
|
this is patched such that the daemon command reads recipient:message pairs from stdin instead of exporting an object to dbus while outputing json as normal (though it currently also outputs "sent $msg to $recipient" in response to input as well). it also includes reactions in output, and will include quotes.
|
||||||
|
|
||||||
note that currently sending multiline messages does not work, lines after the first are ignored.
|
note that currently sending multiline messages does not work, lines after the first are ignored.
|
||||||
|
|
Binary file not shown.
|
@ -27,6 +27,16 @@ import static org.asamk.signal.DbusConfig.SIGNAL_OBJECTPATH;
|
||||||
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
|
||||||
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
import org.whispersystems.signalservice.api.push.exceptions.EncapsulatedExceptions;
|
||||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
class JsonInterface {
|
||||||
|
public String commandName;
|
||||||
|
public String recipient;
|
||||||
|
public String content;
|
||||||
|
public JsonNode details;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class InputReader implements Runnable {
|
class InputReader implements Runnable {
|
||||||
private volatile boolean alive = true;
|
private volatile boolean alive = true;
|
||||||
|
@ -42,29 +52,40 @@ class InputReader implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||||
|
ObjectMapper jsonProcessor = new ObjectMapper();
|
||||||
while (alive) {
|
while (alive) {
|
||||||
try {
|
try {
|
||||||
String in = br.readLine();
|
String in = br.readLine();
|
||||||
String args[] = in.split(":", 2);
|
if (in != null) {
|
||||||
// properly this ought to be json or some sort of serialization to not miss multiline messages
|
JsonInterface command = jsonProcessor.readValue(in, JsonInterface.class);
|
||||||
if (args.length == 2) {
|
if (command.commandName.equals("sendMessage")){
|
||||||
String message = args[1];
|
List<String> recipients = new ArrayList<String>();
|
||||||
List<String> recipients = new ArrayList<String>();
|
recipients.add(command.recipient);
|
||||||
recipients.add(args[0]);
|
List<String> attachments = new ArrayList<>();
|
||||||
List<String> attachments = new ArrayList<>();
|
if (command.details != null && command.details.has("attachments") ) {
|
||||||
try {
|
command.details.get("attachments").forEach(attachment -> {
|
||||||
System.out.println("sent '" + message + "' to " + args[0]);
|
if (attachment.isTextual()){
|
||||||
this.m.sendMessage(message, attachments, recipients);
|
attachments.add(attachment.asText());
|
||||||
} catch (AssertionError | EncapsulatedExceptions| AttachmentInvalidException | InvalidNumberException e) {
|
}
|
||||||
System.err.println("aaaaaa (DaemonCommand L59)");
|
});
|
||||||
e.printStackTrace(System.out);
|
}
|
||||||
}
|
try {
|
||||||
|
// verbosity flag? better yet, json acknowledgement with timestamp or message id?
|
||||||
|
System.out.println("sentMessage '" + command.content + "' to " + command.recipient);
|
||||||
|
this.m.sendMessage(command.content, attachments, recipients);
|
||||||
|
} catch (AssertionError | EncapsulatedExceptions| AttachmentInvalidException | InvalidNumberException e) {
|
||||||
|
System.err.println("error in sending message");
|
||||||
|
e.printStackTrace(System.out);
|
||||||
|
}
|
||||||
|
} /* elif (command.commandName == "sendTyping") {
|
||||||
|
getMessageSender().sendTyping(signalServiceAddress?, ....)
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println(e);
|
System.err.println(e);
|
||||||
|
alive = false;
|
||||||
}
|
}
|
||||||
// getMessageSender().sendTyping(signalServiceAddress?, ....)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,6 @@ import org.whispersystems.signalservice.internal.util.DynamicCredentialsProvider
|
||||||
import org.whispersystems.signalservice.internal.util.Hex;
|
import org.whispersystems.signalservice.internal.util.Hex;
|
||||||
import org.whispersystems.util.Base64;
|
import org.whispersystems.util.Base64;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue