From 911e1bfb73dc009eeed9bc5ef49092b1e6ffcccf Mon Sep 17 00:00:00 2001 From: Alessandro Autiero Date: Tue, 9 Jan 2024 13:00:33 +0100 Subject: [PATCH] Added back message quoting --- pom.xml | 26 +++- .../java/it/auties/whatsapp/api/Whatsapp.java | 109 +++++++++++++- .../model/message/button/ButtonsMessage.java | 138 +++++++++++++---- .../button/ButtonsResponseMessage.java | 60 ++++++-- .../message/button/InteractiveMessage.java | 105 ++++++++++--- .../button/InteractiveResponseMessage.java | 50 ++++++- .../model/message/button/ListMessage.java | 99 +++++++++--- .../message/button/ListResponseMessage.java | 70 +++++++-- .../model/message/button/TemplateMessage.java | 89 ++++++++--- .../message/button/TemplateReplyMessage.java | 59 ++++++-- .../message/model/ButtonReplyMessage.java | 2 +- .../message/model/ContextualMessage.java | 3 +- .../model/message/model/MediaMessage.java | 2 +- .../model/message/model/MessageContainer.java | 2 +- .../payment/PaymentInvoiceMessage.java | 8 +- .../message/payment/PaymentOrderMessage.java | 141 ++++++++++++++---- .../model/message/standard/AudioMessage.java | 8 +- .../message/standard/ContactMessage.java | 50 ++++++- .../message/standard/ContactsMessage.java | 49 +++++- .../message/standard/DocumentMessage.java | 8 +- .../message/standard/GroupInviteMessage.java | 101 ++++++++++--- .../model/message/standard/ImageMessage.java | 8 +- .../message/standard/LiveLocationMessage.java | 120 ++++++++++++--- .../message/standard/LocationMessage.java | 139 +++++++++++++---- .../message/standard/PollCreationMessage.java | 50 +++---- .../message/standard/ProductMessage.java | 79 ++++++++-- .../standard/RequestPhoneNumberMessage.java | 30 +++- .../message/standard/StickerMessage.java | 8 +- .../model/message/standard/TextMessage.java | 2 +- .../message/standard/VideoOrGifMessage.java | 8 +- .../model/poll/SelectedPollOption.java | 18 +++ .../registration/apns/ApnsClient.java | 2 +- .../auties/whatsapp/util/Specification.java | 2 +- 33 files changed, 1340 insertions(+), 305 deletions(-) create mode 100644 src/main/java/it/auties/whatsapp/model/poll/SelectedPollOption.java diff --git a/pom.xml b/pom.xml index d6da3a82..3cb5b412 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.github.auties00 cobalt - 0.0.1 + 0.0.2 ${project.groupId}:${project.artifactId} Standalone fully-featured Whatsapp Web API for Java and Kotlin https://github.com/Auties00/Cobalt @@ -124,6 +124,30 @@ + + uber-jar + + + + maven-assembly-plugin + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + jar diff --git a/src/main/java/it/auties/whatsapp/api/Whatsapp.java b/src/main/java/it/auties/whatsapp/api/Whatsapp.java index 1ba62e16..cd7f3fc4 100644 --- a/src/main/java/it/auties/whatsapp/api/Whatsapp.java +++ b/src/main/java/it/auties/whatsapp/api/Whatsapp.java @@ -23,10 +23,7 @@ import it.auties.whatsapp.model.companion.CompanionLinkResult; import it.auties.whatsapp.model.contact.Contact; import it.auties.whatsapp.model.contact.ContactStatus; -import it.auties.whatsapp.model.info.ChatMessageInfo; -import it.auties.whatsapp.model.info.ChatMessageInfoBuilder; -import it.auties.whatsapp.model.info.MessageInfo; -import it.auties.whatsapp.model.info.NewsletterMessageInfo; +import it.auties.whatsapp.model.info.*; import it.auties.whatsapp.model.jid.Jid; import it.auties.whatsapp.model.jid.JidProvider; import it.auties.whatsapp.model.jid.JidServer; @@ -38,6 +35,7 @@ import it.auties.whatsapp.model.message.server.ProtocolMessageBuilder; import it.auties.whatsapp.model.message.standard.CallMessageBuilder; import it.auties.whatsapp.model.message.standard.ReactionMessageBuilder; +import it.auties.whatsapp.model.message.standard.TextMessage; import it.auties.whatsapp.model.newsletter.Newsletter; import it.auties.whatsapp.model.newsletter.NewsletterViewerMetadata; import it.auties.whatsapp.model.newsletter.NewsletterViewerRole; @@ -411,6 +409,108 @@ public CompletableFuture sendMessage(JidProvider chat, St return sendMessage(chat, MessageContainer.of(message)); } + /** + * Builds and sends a message from a chat and a message + * + * @param chat the chat where the message should be sent + * @param message the message to send + * @return a CompletableFuture + */ + public CompletableFuture sendChatMessage(JidProvider chat, String message) { + return sendChatMessage(chat, MessageContainer.of(message)); + } + + /** + * Builds and sends a message from a chat and a message + * + * @param chat the chat where the message should be sent + * @param message the message to send + * @return a CompletableFuture + */ + public CompletableFuture sendsNewsletterMessage(JidProvider chat, String message) { + return sendNewsletterMessage(chat, MessageContainer.of(message)); + } + + /** + * Builds and sends a message from a chat and a message + * + * @param chat the chat where the message should be sent + * @param message the message to send + * @param quotedMessage the message to quote + * @return a CompletableFuture + */ + public CompletableFuture sendMessage(JidProvider chat, String message, MessageInfo quotedMessage) { + return sendMessage(chat, TextMessage.of(message), quotedMessage); + } + + /** + * Builds and sends a message from a chat and a message + * + * @param chat the chat where the message should be sent + * @param message the message to send + * @param quotedMessage the message to quote + * @return a CompletableFuture + */ + public CompletableFuture sendChatMessage(JidProvider chat, String message, MessageInfo quotedMessage) { + return sendChatMessage(chat, TextMessage.of(message), quotedMessage); + } + + /** + * Builds and sends a message from a chat and a message + * + * @param chat the chat where the message should be sent + * @param message the message to send + * @param quotedMessage the message to quote + * @return a CompletableFuture + */ + public CompletableFuture sendNewsletterMessage(JidProvider chat, String message, MessageInfo quotedMessage) { + return sendNewsletterMessage(chat, TextMessage.of(message), quotedMessage); + } + + /** + * Builds and sends a message from a chat and a message + * + * @param chat the chat where the message should be sent + * @param message the message to send + * @param quotedMessage the message to quote + * @return a CompletableFuture + */ + public CompletableFuture sendMessage(JidProvider chat, ContextualMessage message, MessageInfo quotedMessage) { + var contextInfo = ContextInfo.of(quotedMessage); + message.setContextInfo(contextInfo); + return sendMessage(chat, MessageContainer.of(message)); + } + + /** + * Builds and sends a message from a chat and a message + * + * @param chat the chat where the message should be sent + * @param message the message to send + * @param quotedMessage the message to quote + * @return a CompletableFuture + */ + public CompletableFuture sendChatMessage(JidProvider chat, ContextualMessage message, MessageInfo quotedMessage) { + var contextInfo = ContextInfo.of(quotedMessage); + message.setContextInfo(contextInfo); + return sendChatMessage(chat, MessageContainer.of(message)); + } + + + /** + * Builds and sends a message from a chat and a message + * + * @param chat the chat where the message should be sent + * @param message the message to send + * @param quotedMessage the message to quote + * @return a CompletableFuture + */ + public CompletableFuture sendNewsletterMessage(JidProvider chat, ContextualMessage message, MessageInfo quotedMessage) { + var contextInfo = ContextInfo.of(quotedMessage); + message.setContextInfo(contextInfo); + return sendNewsletterMessage(chat, MessageContainer.of(message)); + } + + /** * Builds and sends a message from a chat and a message * @@ -433,7 +533,6 @@ public CompletableFuture sendMessage(JidProvider recipien return recipient.toJid().server() == JidServer.NEWSLETTER ? sendNewsletterMessage(recipient, message) : sendChatMessage(recipient, message); } - /** * Builds and sends a message from a recipient and a message * diff --git a/src/main/java/it/auties/whatsapp/model/message/button/ButtonsMessage.java b/src/main/java/it/auties/whatsapp/model/message/button/ButtonsMessage.java index ed0dc311..15a64a09 100644 --- a/src/main/java/it/auties/whatsapp/model/message/button/ButtonsMessage.java +++ b/src/main/java/it/auties/whatsapp/model/message/button/ButtonsMessage.java @@ -22,28 +22,42 @@ * A model class that represents a message that contains buttons inside */ @ProtobufMessageName("Message.ButtonsMessage") -public record ButtonsMessage( - @ProtobufProperty(index = 1, type = ProtobufType.STRING) - Optional headerText, - @ProtobufProperty(index = 2, type = ProtobufType.OBJECT) - Optional headerDocument, - @ProtobufProperty(index = 3, type = ProtobufType.OBJECT) - Optional headerImage, - @ProtobufProperty(index = 4, type = ProtobufType.OBJECT) - Optional headerVideo, - @ProtobufProperty(index = 5, type = ProtobufType.OBJECT) - Optional headerLocation, - @ProtobufProperty(index = 6, type = ProtobufType.STRING) - Optional body, - @ProtobufProperty(index = 7, type = ProtobufType.STRING) - Optional footer, - @ProtobufProperty(index = 8, type = ProtobufType.OBJECT) - Optional contextInfo, - @ProtobufProperty(index = 9, type = ProtobufType.OBJECT) - List