From 1208fdb143e444859de7414deea764404fa9cc98 Mon Sep 17 00:00:00 2001 From: Tony Cebzanov Date: Thu, 9 Jul 2026 02:02:49 -0400 Subject: [PATCH] Add sendStory command for posting stories via CLI and JSON-RPC Implements SendStoryCommand to allow users to post stories through the CLI and JSON-RPC interfaces. Command accepts an attachment file path (required) and optional --no-replies flag to disable replies on the story. Handles AttachmentInvalidException and IOException appropriately and outputs results using SendMessageResultUtils. Registered in Commands.java in alphabetical order. --- .../org/asamk/signal/commands/Commands.java | 1 + .../signal/commands/SendStoryCommand.java | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/main/java/org/asamk/signal/commands/SendStoryCommand.java diff --git a/src/main/java/org/asamk/signal/commands/Commands.java b/src/main/java/org/asamk/signal/commands/Commands.java index 05dc1ff4..4787c7d1 100644 --- a/src/main/java/org/asamk/signal/commands/Commands.java +++ b/src/main/java/org/asamk/signal/commands/Commands.java @@ -52,6 +52,7 @@ public class Commands { addCommand(new SendPollTerminateCommand()); addCommand(new SendReactionCommand()); addCommand(new SendReceiptCommand()); + addCommand(new SendStoryCommand()); addCommand(new SendSyncRequestCommand()); addCommand(new SendTypingCommand()); addCommand(new SendUnpinMessageCommand()); diff --git a/src/main/java/org/asamk/signal/commands/SendStoryCommand.java b/src/main/java/org/asamk/signal/commands/SendStoryCommand.java new file mode 100644 index 00000000..d2f032a1 --- /dev/null +++ b/src/main/java/org/asamk/signal/commands/SendStoryCommand.java @@ -0,0 +1,57 @@ +package org.asamk.signal.commands; + +import net.sourceforge.argparse4j.impl.Arguments; +import net.sourceforge.argparse4j.inf.Namespace; +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.Manager; +import org.asamk.signal.manager.api.AttachmentInvalidException; +import org.asamk.signal.output.OutputWriter; + +import java.io.IOException; + +import static org.asamk.signal.util.SendMessageResultUtils.outputResult; + +public class SendStoryCommand implements JsonRpcLocalCommand { + + @Override + public String getName() { + return "sendStory"; + } + + @Override + public void attachToSubparser(final Subparser subparser) { + subparser.help("Post a story to your Story."); + subparser.addArgument("-a", "--attachment") + .required(true) + .help("Specify the file path to the image or video to post as a story."); + subparser.addArgument("--no-replies") + .action(Arguments.storeTrue()) + .help("Disable replies on this story."); + } + + @Override + public void handleCommand( + final Namespace ns, + final Manager m, + final OutputWriter outputWriter + ) throws CommandException { + final var attachment = ns.getString("attachment"); + if (attachment == null || attachment.isEmpty()) { + throw new UserErrorException("An attachment is required for sending a story."); + } + + final var noReplies = Boolean.TRUE.equals(ns.getBoolean("no-replies")); + + try { + final var results = m.sendStory(attachment, !noReplies); + outputResult(outputWriter, results); + } catch (AttachmentInvalidException | IOException e) { + throw new UnexpectedErrorException("Failed to send story: " + e.getMessage() + " (" + e.getClass() + .getSimpleName() + ")", e); + } + } +}