Skip to content

Commit

Permalink
Added back message quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
Auties00 committed Jan 9, 2024
1 parent 4637b63 commit 911e1bf
Show file tree
Hide file tree
Showing 33 changed files with 1,340 additions and 305 deletions.
26 changes: 25 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.auties00</groupId>
<artifactId>cobalt</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>Standalone fully-featured Whatsapp Web API for Java and Kotlin</description>
<url>https://github.com/Auties00/Cobalt</url>
Expand Down Expand Up @@ -124,6 +124,30 @@
</plugins>
</build>
</profile>
<profile>
<id>uber-jar</id>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<packaging>jar</packaging>

Expand Down
109 changes: 104 additions & 5 deletions src/main/java/it/auties/whatsapp/api/Whatsapp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -411,6 +409,108 @@ public CompletableFuture<? extends MessageInfo> 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<ChatMessageInfo> 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<NewsletterMessageInfo> 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<? extends MessageInfo> 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<? extends MessageInfo> 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<? extends MessageInfo> 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<? extends MessageInfo> 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<ChatMessageInfo> 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<NewsletterMessageInfo> 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
*
Expand All @@ -433,7 +533,6 @@ public CompletableFuture<? extends MessageInfo> 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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ButtonsMessageHeaderText> headerText,
@ProtobufProperty(index = 2, type = ProtobufType.OBJECT)
Optional<DocumentMessage> headerDocument,
@ProtobufProperty(index = 3, type = ProtobufType.OBJECT)
Optional<ImageMessage> headerImage,
@ProtobufProperty(index = 4, type = ProtobufType.OBJECT)
Optional<VideoOrGifMessage> headerVideo,
@ProtobufProperty(index = 5, type = ProtobufType.OBJECT)
Optional<LocationMessage> headerLocation,
@ProtobufProperty(index = 6, type = ProtobufType.STRING)
Optional<String> body,
@ProtobufProperty(index = 7, type = ProtobufType.STRING)
Optional<String> footer,
@ProtobufProperty(index = 8, type = ProtobufType.OBJECT)
Optional<ContextInfo> contextInfo,
@ProtobufProperty(index = 9, type = ProtobufType.OBJECT)
List<Button> buttons,
@ProtobufProperty(index = 10, type = ProtobufType.OBJECT)
Type headerType
) implements ButtonMessage, ContextualMessage {
public final class ButtonsMessage implements ButtonMessage, ContextualMessage<ButtonsMessage> {
@ProtobufProperty(index = 1, type = ProtobufType.STRING)
private final ButtonsMessageHeaderText headerText;
@ProtobufProperty(index = 2, type = ProtobufType.OBJECT)
private final DocumentMessage headerDocument;
@ProtobufProperty(index = 3, type = ProtobufType.OBJECT)
private final ImageMessage headerImage;
@ProtobufProperty(index = 4, type = ProtobufType.OBJECT)
private final VideoOrGifMessage headerVideo;
@ProtobufProperty(index = 5, type = ProtobufType.OBJECT)
private final LocationMessage headerLocation;
@ProtobufProperty(index = 6, type = ProtobufType.STRING)
private final String body;
@ProtobufProperty(index = 7, type = ProtobufType.STRING)
private final String footer;
@ProtobufProperty(index = 8, type = ProtobufType.OBJECT)
private ContextInfo contextInfo;
@ProtobufProperty(index = 9, type = ProtobufType.OBJECT)
private final List<Button> buttons;
@ProtobufProperty(index = 10, type = ProtobufType.OBJECT)
private final Type headerType;


public ButtonsMessage(ButtonsMessageHeaderText headerText, DocumentMessage headerDocument, ImageMessage headerImage, VideoOrGifMessage headerVideo, LocationMessage headerLocation, String body, String footer, ContextInfo contextInfo, List<Button> buttons, Type headerType) {
this.headerText = headerText;
this.headerDocument = headerDocument;
this.headerImage = headerImage;
this.headerVideo = headerVideo;
this.headerLocation = headerLocation;
this.body = body;
this.footer = footer;
this.contextInfo = contextInfo;
this.buttons = buttons;
this.headerType = headerType;
}

@ProtobufBuilder(className = "ButtonsMessageSimpleBuilder")
static ButtonsMessage customBuilder(ButtonsMessageHeader header, String body, String footer, ContextInfo contextInfo, List<Button> buttons) {
var builder = new ButtonsMessageBuilder()
Expand Down Expand Up @@ -84,22 +98,84 @@ public MessageType type() {
* @return an optional
*/
public Optional<? extends ButtonsMessageHeader> header() {
if (headerText.isPresent()) {
return headerText;
if (headerText != null) {
return Optional.of(headerText);
}

if (headerDocument.isPresent()) {
return headerDocument;
if (headerDocument != null) {
return Optional.of(headerDocument);
}

if (headerImage.isPresent()) {
return headerImage;
if (headerImage != null) {
return Optional.of(headerImage);
}

if (headerVideo.isPresent()) {
return headerVideo;
if (headerVideo != null) {
return Optional.of(headerVideo);
}

return headerLocation;
return Optional.ofNullable(headerLocation);
}

public Optional<ButtonsMessageHeaderText> headerText() {
return Optional.ofNullable(headerText);
}

public Optional<DocumentMessage> headerDocument() {
return Optional.ofNullable(headerDocument);
}

public Optional<ImageMessage> headerImage() {
return Optional.ofNullable(headerImage);
}

public Optional<VideoOrGifMessage> headerVideo() {
return Optional.ofNullable(headerVideo);
}

public Optional<LocationMessage> headerLocation() {
return Optional.ofNullable(headerLocation);
}

public Optional<String> body() {
return Optional.ofNullable(body);
}

public Optional<String> footer() {
return Optional.ofNullable(footer);
}

@Override
public Optional<ContextInfo> contextInfo() {
return Optional.ofNullable(contextInfo);
}

public List<Button> buttons() {
return buttons;
}

public Type headerType() {
return headerType;
}

@Override
public ButtonsMessage setContextInfo(ContextInfo contextInfo) {
this.contextInfo = contextInfo;
return this;
}

@Override
public String toString() {
return "ButtonsMessage[" +
"headerText=" + headerText + ", " +
"headerDocument=" + headerDocument + ", " +
"headerImage=" + headerImage + ", " +
"headerVideo=" + headerVideo + ", " +
"headerLocation=" + headerLocation + ", " +
"body=" + body + ", " +
"footer=" + footer + ", " +
"contextInfo=" + contextInfo + ", " +
"buttons=" + buttons + ", " +
"headerType=" + headerType + ']';
}
}
Loading

0 comments on commit 911e1bf

Please sign in to comment.