Set<RecipientIdentifier> recipients
) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException;
+ SendMessageResults sendPaymentNotificationMessage(
+ byte[] receipt, String note, RecipientIdentifier.Single recipient
+ ) throws IOException;
+
SendMessageResults sendEndSessionMessage(Set<RecipientIdentifier.Single> recipients) throws IOException;
void deleteRecipient(RecipientIdentifier.Single recipient);
return sendMessage(messageBuilder, recipients);
}
+ @Override
+ public SendMessageResults sendPaymentNotificationMessage(
+ byte[] receipt, String note, RecipientIdentifier.Single recipient
+ ) throws IOException {
+ final var paymentNotification = new SignalServiceDataMessage.PaymentNotification(receipt, note);
+ final var payment = new SignalServiceDataMessage.Payment(paymentNotification);
+ final var messageBuilder = SignalServiceDataMessage.newBuilder().withPayment(payment);
+ try {
+ return sendMessage(messageBuilder, Set.of(recipient));
+ } catch (NotAGroupMemberException | GroupNotFoundException | GroupSendingNotAllowedException e) {
+ throw new AssertionError(e);
+ }
+ }
+
@Override
public SendMessageResults sendEndSessionMessage(Set<RecipientIdentifier.Single> recipients) throws IOException {
var messageBuilder = SignalServiceDataMessage.newBuilder().asEndSessionMessage();
*-e*, *--end-session*::
Clear session state and send end session message.
+=== sendPaymentNotification
+
+Send a payment notification.
+
+RECIPIENT::
+Specify the recipient’s phone number.
+
+*--receipt* RECEIPT::
+The base64 encoded receipt blob.
+
+*--note* NOTE::
+Specify a note for the payment notification.
+
=== sendReaction
Send reaction to a previously received or sent message.
addCommand(new RemoteDeleteCommand());
addCommand(new SendCommand());
addCommand(new SendContactsCommand());
+ addCommand(new SendPaymentNotificationCommand());
addCommand(new SendReactionCommand());
addCommand(new SendReceiptCommand());
addCommand(new SendSyncRequestCommand());
--- /dev/null
+package org.asamk.signal.commands;
+
+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.manager.Manager;
+import org.asamk.signal.output.OutputWriter;
+import org.asamk.signal.util.CommandUtil;
+
+import java.io.IOException;
+import java.util.Base64;
+
+import static org.asamk.signal.util.SendMessageResultUtils.outputResult;
+
+public class SendPaymentNotificationCommand implements JsonRpcLocalCommand {
+
+ @Override
+ public String getName() {
+ return "sendPaymentNotification";
+ }
+
+ @Override
+ public void attachToSubparser(final Subparser subparser) {
+ subparser.help("Send a payment notification.");
+ subparser.addArgument("recipient").help("Specify the recipient's phone number.");
+ subparser.addArgument("--receipt").required(true).help("The base64 encoded receipt blob.");
+ subparser.addArgument("--note").help("Specify a note for the payment notification.");
+ }
+
+ @Override
+ public void handleCommand(
+ final Namespace ns, final Manager m, final OutputWriter outputWriter
+ ) throws CommandException {
+ final var recipientString = ns.getString("recipient");
+ final var recipientIdentifier = CommandUtil.getSingleRecipientIdentifier(recipientString, m.getSelfNumber());
+
+ final var receiptString = ns.getString("receipt");
+ final var receipt = Base64.getDecoder().decode(receiptString);
+ final var note = ns.getString("note");
+
+ try {
+ final var results = m.sendPaymentNotificationMessage(receipt, note, recipientIdentifier);
+ outputResult(outputWriter, results);
+ } catch (IOException e) {
+ throw new UnexpectedErrorException("Failed to send message: " + e.getMessage() + " (" + e.getClass()
+ .getSimpleName() + ")", e);
+ }
+ }
+}
groupId));
}
+ @Override
+ public SendMessageResults sendPaymentNotificationMessage(
+ final byte[] receipt, final String note, final RecipientIdentifier.Single recipient
+ ) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
@Override
public SendMessageResults sendEndSessionMessage(final Set<RecipientIdentifier.Single> recipients) throws IOException {
signal.sendEndSessionMessage(recipients.stream().map(RecipientIdentifier.Single::getIdentifier).toList());