diff --git a/bot-domain/bot-domain-main/src/main/java/dev/struchkov/godfather/main/domain/BoxAnswer.java b/bot-domain/bot-domain-main/src/main/java/dev/struchkov/godfather/main/domain/BoxAnswer.java index 7160ba4..aa6c5d8 100644 --- a/bot-domain/bot-domain-main/src/main/java/dev/struchkov/godfather/main/domain/BoxAnswer.java +++ b/bot-domain/bot-domain-main/src/main/java/dev/struchkov/godfather/main/domain/BoxAnswer.java @@ -2,6 +2,11 @@ package dev.struchkov.godfather.main.domain; import dev.struchkov.godfather.main.domain.keyboard.KeyBoard; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import static dev.struchkov.haiti.utils.Checker.checkNotNull; import static dev.struchkov.haiti.utils.Checker.checkNull; /** @@ -33,12 +38,15 @@ public class BoxAnswer { */ private String recipientPersonId; + protected Map payload; + private BoxAnswer(Builder builder) { message = builder.message; keyBoard = builder.keyBoard; replace = builder.replace; replaceMessageId = builder.replaceMessageId; recipientPersonId = builder.recipientPersonId; + payload = builder.payload; } public static BoxAnswer boxAnswer(boolean replace, String message) { @@ -115,6 +123,21 @@ public class BoxAnswer { } } + public Map getPayload() { + return payload; + } + + public void setPayload(ContextKey key, T value) { + if (checkNotNull(value)) { + payload.put(key, value); + } + } + + public Optional getPayLoad(ContextKey contextKey) { + return Optional.ofNullable(payload.get(contextKey)) + .map(value -> (T) value); + } + @Override public String toString() { return "BoxAnswer{" + @@ -131,6 +154,7 @@ public class BoxAnswer { private boolean replace; private String replaceMessageId; private String recipientPersonId; + private Map payload = new HashMap<>(); private Builder() { } @@ -160,6 +184,13 @@ public class BoxAnswer { return this; } + public Builder payload(ContextKey key, T value) { + if (checkNotNull(value)) { + payload.put(key, value); + } + return this; + } + public BoxAnswer build() { return new BoxAnswer(this); } diff --git a/bot-domain/bot-domain-main/src/main/java/dev/struchkov/godfather/main/domain/content/Message.java b/bot-domain/bot-domain-main/src/main/java/dev/struchkov/godfather/main/domain/content/Message.java index ef70c38..7471fe6 100644 --- a/bot-domain/bot-domain-main/src/main/java/dev/struchkov/godfather/main/domain/content/Message.java +++ b/bot-domain/bot-domain-main/src/main/java/dev/struchkov/godfather/main/domain/content/Message.java @@ -1,9 +1,15 @@ package dev.struchkov.godfather.main.domain.content; import dev.struchkov.autoresponder.entity.DeliverableText; +import dev.struchkov.godfather.main.domain.ContextKey; import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; +import java.util.Optional; + +import static dev.struchkov.haiti.utils.Checker.checkNotNull; /** * Абстрактная сущность - Сообщение от пользователя. @@ -22,17 +28,19 @@ public abstract class Message implements DeliverableText { /** * Дата создания. */ - private LocalDateTime createDate; + protected LocalDateTime createDate; /** * Идентификатор пользователя, отправившего сообщение. */ - private String personId; + protected String personId; /** * Текстовое сообщение. */ - private String text; + protected String text; + + protected Map payload = new HashMap<>(); protected Message(Message source) { this.id = source.getId(); @@ -40,6 +48,7 @@ public abstract class Message implements DeliverableText { this.text = source.getText(); this.createDate = source.getCreateDate(); this.contentType = source.getContentType(); + this.payload = source.getPayload(); } protected Message() { @@ -85,6 +94,21 @@ public abstract class Message implements DeliverableText { this.id = id; } + public Map getPayload() { + return payload; + } + + public void setPayload(ContextKey key, T value) { + if (checkNotNull(value)) { + payload.put(key, value); + } + } + + public Optional getPayLoad(ContextKey contextKey) { + return Optional.ofNullable(payload.get(contextKey)) + .map(value -> (T) value); + } + @Override public boolean equals(Object o) { if (this == o) return true;