mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Implement sendPayment notification command
This commit is contained in:
parent
b18991b9fb
commit
7587a60387
6 changed files with 90 additions and 0 deletions
|
@ -141,6 +141,10 @@ public interface Manager extends Closeable {
|
||||||
Set<RecipientIdentifier> recipients
|
Set<RecipientIdentifier> recipients
|
||||||
) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException, UnregisteredRecipientException;
|
) 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;
|
SendMessageResults sendEndSessionMessage(Set<RecipientIdentifier.Single> recipients) throws IOException;
|
||||||
|
|
||||||
void deleteRecipient(RecipientIdentifier.Single recipient);
|
void deleteRecipient(RecipientIdentifier.Single recipient);
|
||||||
|
|
|
@ -638,6 +638,20 @@ class ManagerImpl implements Manager {
|
||||||
return sendMessage(messageBuilder, recipients);
|
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
|
@Override
|
||||||
public SendMessageResults sendEndSessionMessage(Set<RecipientIdentifier.Single> recipients) throws IOException {
|
public SendMessageResults sendEndSessionMessage(Set<RecipientIdentifier.Single> recipients) throws IOException {
|
||||||
var messageBuilder = SignalServiceDataMessage.newBuilder().asEndSessionMessage();
|
var messageBuilder = SignalServiceDataMessage.newBuilder().asEndSessionMessage();
|
||||||
|
|
|
@ -256,6 +256,19 @@ Specify the mentions of the original message (same format as `--mention`).
|
||||||
*-e*, *--end-session*::
|
*-e*, *--end-session*::
|
||||||
Clear session state and send end session message.
|
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
|
=== sendReaction
|
||||||
|
|
||||||
Send reaction to a previously received or sent message.
|
Send reaction to a previously received or sent message.
|
||||||
|
|
|
@ -34,6 +34,7 @@ public class Commands {
|
||||||
addCommand(new RemoteDeleteCommand());
|
addCommand(new RemoteDeleteCommand());
|
||||||
addCommand(new SendCommand());
|
addCommand(new SendCommand());
|
||||||
addCommand(new SendContactsCommand());
|
addCommand(new SendContactsCommand());
|
||||||
|
addCommand(new SendPaymentNotificationCommand());
|
||||||
addCommand(new SendReactionCommand());
|
addCommand(new SendReactionCommand());
|
||||||
addCommand(new SendReceiptCommand());
|
addCommand(new SendReceiptCommand());
|
||||||
addCommand(new SendSyncRequestCommand());
|
addCommand(new SendSyncRequestCommand());
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -388,6 +388,13 @@ public class DbusManagerImpl implements Manager {
|
||||||
groupId));
|
groupId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SendMessageResults sendPaymentNotificationMessage(
|
||||||
|
final byte[] receipt, final String note, final RecipientIdentifier.Single recipient
|
||||||
|
) throws IOException {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SendMessageResults sendEndSessionMessage(final Set<RecipientIdentifier.Single> recipients) throws IOException {
|
public SendMessageResults sendEndSessionMessage(final Set<RecipientIdentifier.Single> recipients) throws IOException {
|
||||||
signal.sendEndSessionMessage(recipients.stream().map(RecipientIdentifier.Single::getIdentifier).toList());
|
signal.sendEndSessionMessage(recipients.stream().map(RecipientIdentifier.Single::getIdentifier).toList());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue