diff --git a/pom.xml b/pom.xml
index afc83e4..d350302 100644
--- a/pom.xml
+++ b/pom.xml
@@ -38,7 +38,7 @@
UTF-8
UTF-8
- 0.0.55
+ 0.0.56-SNAPSHOT
6.3.0
diff --git a/telegram-consumer/telegram-consumer-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/consumer/EventDistributorService.java b/telegram-consumer/telegram-consumer-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/consumer/EventDistributorService.java
index 7abe83c..a5ae191 100644
--- a/telegram-consumer/telegram-consumer-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/consumer/EventDistributorService.java
+++ b/telegram-consumer/telegram-consumer-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/consumer/EventDistributorService.java
@@ -5,10 +5,10 @@ import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.quarkus.context.service.EventDispatching;
import dev.struchkov.godfather.telegram.domain.event.Subscribe;
import dev.struchkov.godfather.telegram.domain.event.Unsubscribe;
-import dev.struchkov.godfather.telegram.main.consumer.CallbackQueryConvert;
-import dev.struchkov.godfather.telegram.main.consumer.MessageMailConvert;
-import dev.struchkov.godfather.telegram.main.consumer.SubscribeConvert;
-import dev.struchkov.godfather.telegram.main.consumer.UnsubscribeConvert;
+import dev.struchkov.godfather.telegram.main.context.convert.CallbackQueryConvert;
+import dev.struchkov.godfather.telegram.main.context.convert.MessageMailConvert;
+import dev.struchkov.godfather.telegram.main.context.convert.SubscribeConvert;
+import dev.struchkov.godfather.telegram.main.context.convert.UnsubscribeConvert;
import dev.struchkov.godfather.telegram.quarkus.context.service.EventDistributor;
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramConnect;
import io.smallrye.mutiny.Uni;
diff --git a/telegram-consumer/telegram-consumer-simple/src/main/java/dev/struchkov/godfather/telegram/simple/consumer/EventDistributorService.java b/telegram-consumer/telegram-consumer-simple/src/main/java/dev/struchkov/godfather/telegram/simple/consumer/EventDistributorService.java
index eb26e3f..c671648 100644
--- a/telegram-consumer/telegram-consumer-simple/src/main/java/dev/struchkov/godfather/telegram/simple/consumer/EventDistributorService.java
+++ b/telegram-consumer/telegram-consumer-simple/src/main/java/dev/struchkov/godfather/telegram/simple/consumer/EventDistributorService.java
@@ -6,11 +6,11 @@ import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.simple.context.service.EventDispatching;
import dev.struchkov.godfather.telegram.domain.event.Subscribe;
import dev.struchkov.godfather.telegram.domain.event.Unsubscribe;
-import dev.struchkov.godfather.telegram.main.consumer.CallbackQueryConvert;
-import dev.struchkov.godfather.telegram.main.consumer.MessageChatMailConvert;
-import dev.struchkov.godfather.telegram.main.consumer.MessageMailConvert;
-import dev.struchkov.godfather.telegram.main.consumer.SubscribeConvert;
-import dev.struchkov.godfather.telegram.main.consumer.UnsubscribeConvert;
+import dev.struchkov.godfather.telegram.main.context.convert.CallbackQueryConvert;
+import dev.struchkov.godfather.telegram.main.context.convert.MessageChatMailConvert;
+import dev.struchkov.godfather.telegram.main.context.convert.MessageMailConvert;
+import dev.struchkov.godfather.telegram.main.context.convert.SubscribeConvert;
+import dev.struchkov.godfather.telegram.main.context.convert.UnsubscribeConvert;
import dev.struchkov.godfather.telegram.simple.context.service.EventDistributor;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramConnect;
import org.jetbrains.annotations.NotNull;
diff --git a/telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/CallbackQueryConvert.java b/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/CallbackQueryConvert.java
similarity index 96%
rename from telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/CallbackQueryConvert.java
rename to telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/CallbackQueryConvert.java
index 2e8c6b9..65d65d8 100644
--- a/telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/CallbackQueryConvert.java
+++ b/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/CallbackQueryConvert.java
@@ -1,4 +1,4 @@
-package dev.struchkov.godfather.telegram.main.consumer;
+package dev.struchkov.godfather.telegram.main.context.convert;
import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment;
diff --git a/telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/MessageChatMailConvert.java b/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/MessageChatMailConvert.java
similarity index 99%
rename from telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/MessageChatMailConvert.java
rename to telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/MessageChatMailConvert.java
index 7b227aa..260fe52 100644
--- a/telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/MessageChatMailConvert.java
+++ b/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/MessageChatMailConvert.java
@@ -1,4 +1,4 @@
-package dev.struchkov.godfather.telegram.main.consumer;
+package dev.struchkov.godfather.telegram.main.context.convert;
import dev.struchkov.godfather.main.domain.content.Attachment;
import dev.struchkov.godfather.main.domain.content.ChatMail;
diff --git a/telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/MessageMailConvert.java b/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/MessageMailConvert.java
similarity index 99%
rename from telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/MessageMailConvert.java
rename to telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/MessageMailConvert.java
index e0e0c1e..076c9b0 100644
--- a/telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/MessageMailConvert.java
+++ b/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/MessageMailConvert.java
@@ -1,4 +1,4 @@
-package dev.struchkov.godfather.telegram.main.consumer;
+package dev.struchkov.godfather.telegram.main.context.convert;
import dev.struchkov.godfather.main.domain.content.Attachment;
import dev.struchkov.godfather.main.domain.content.Mail;
diff --git a/telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/SubscribeConvert.java b/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/SubscribeConvert.java
similarity index 93%
rename from telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/SubscribeConvert.java
rename to telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/SubscribeConvert.java
index d0cdc3e..dac01ef 100644
--- a/telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/SubscribeConvert.java
+++ b/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/SubscribeConvert.java
@@ -1,4 +1,4 @@
-package dev.struchkov.godfather.telegram.main.consumer;
+package dev.struchkov.godfather.telegram.main.context.convert;
import dev.struchkov.godfather.telegram.domain.event.Subscribe;
import org.telegram.telegrambots.meta.api.objects.ChatMemberUpdated;
diff --git a/telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/UnsubscribeConvert.java b/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/UnsubscribeConvert.java
similarity index 93%
rename from telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/UnsubscribeConvert.java
rename to telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/UnsubscribeConvert.java
index c3994a2..5a19d7c 100644
--- a/telegram-consumer/telegram-consumer-main/src/main/java/dev/struchkov/godfather/telegram/main/consumer/UnsubscribeConvert.java
+++ b/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/UnsubscribeConvert.java
@@ -1,4 +1,4 @@
-package dev.struchkov.godfather.telegram.main.consumer;
+package dev.struchkov.godfather.telegram.main.context.convert;
import dev.struchkov.godfather.telegram.domain.event.Unsubscribe;
import org.telegram.telegrambots.meta.api.objects.ChatMemberUpdated;
diff --git a/telegram-context/telegram-context-simple/pom.xml b/telegram-context/telegram-context-simple/pom.xml
index b9eadc9..109bb85 100644
--- a/telegram-context/telegram-context-simple/pom.xml
+++ b/telegram-context/telegram-context-simple/pom.xml
@@ -24,6 +24,10 @@
dev.struchkov.godfather.telegram
telegram-context-main
+
+ dev.struchkov.godfather.telegram
+ telegram-domain-simple
+
org.telegram
diff --git a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/util/UnitTrigger.java b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/util/UnitTrigger.java
index e6dd5ef..1720c4d 100644
--- a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/util/UnitTrigger.java
+++ b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/util/UnitTrigger.java
@@ -1,13 +1,14 @@
package dev.struchkov.godfather.telegram.quarkus.core.util;
import dev.struchkov.godfather.main.domain.content.Mail;
+import dev.struchkov.godfather.quarkus.domain.unit.func.UniPredicate;
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment;
import dev.struchkov.godfather.telegram.domain.attachment.CommandAttachment;
import dev.struchkov.godfather.telegram.main.core.util.Attachments;
import java.util.Optional;
-import java.util.function.Predicate;
+import static dev.struchkov.godfather.quarkus.domain.unit.func.UniPredicate.predicate;
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
public class UnitTrigger {
@@ -16,40 +17,44 @@ public class UnitTrigger {
utilityClass();
}
- public static Predicate clickButtonRaw(String rawCallBackData) {
- return mail -> {
- final Optional optButtonClick = Attachments.findFirstButtonClick(mail.getAttachments());
- if (optButtonClick.isPresent()) {
- final ButtonClickAttachment buttonClick = optButtonClick.get();
- final String rawData = buttonClick.getRawCallBackData();
- return rawData.equals(rawCallBackData);
- }
- return false;
- };
+ public static UniPredicate clickButtonRaw(String rawCallBackData) {
+ return predicate(
+ mail -> {
+ final Optional optButtonClick = Attachments.findFirstButtonClick(mail.getAttachments());
+ if (optButtonClick.isPresent()) {
+ final ButtonClickAttachment buttonClick = optButtonClick.get();
+ final String rawData = buttonClick.getRawCallBackData();
+ return rawData.equals(rawCallBackData);
+ }
+ return false;
+ }
+ );
}
- public static Predicate isCommandByType(String commandType) {
- return mail -> {
- final Optional optCommand = Attachments.findFirstCommand(mail.getAttachments());
- if (optCommand.isPresent()) {
- final CommandAttachment command = optCommand.get();
- final String type = command.getCommandType();
- return type.equals(commandType);
- }
- return false;
- };
+ public static UniPredicate isCommandByType(String commandType) {
+ return predicate(
+ mail -> {
+ final Optional optCommand = Attachments.findFirstCommand(mail.getAttachments());
+ if (optCommand.isPresent()) {
+ final CommandAttachment command = optCommand.get();
+ final String type = command.getCommandType();
+ return type.equals(commandType);
+ }
+ return false;
+ }
+ );
}
- public static Predicate isCommand() {
- return mail -> Attachments.findFirstCommand(mail.getAttachments()).isPresent();
+ public static UniPredicate isCommand() {
+ return predicate(mail -> Attachments.findFirstCommand(mail.getAttachments()).isPresent());
}
- public static Predicate isClickButton() {
- return mail -> Attachments.findFirstButtonClick(mail.getAttachments()).isPresent();
+ public static UniPredicate isClickButton() {
+ return predicate(mail -> Attachments.findFirstButtonClick(mail.getAttachments()).isPresent());
}
- public static Predicate isLinks() {
- return mail -> Attachments.findFirstLink(mail.getAttachments()).isPresent();
+ public static UniPredicate isLinks() {
+ return predicate(mail -> Attachments.findFirstLink(mail.getAttachments()).isPresent());
}
}
diff --git a/telegram-domain/telegram-domain-simple/src/main/java/dev/struchkov/godfather/telegram/simple/domain/attachment/send/DocumentSendAttachment.java b/telegram-domain/telegram-domain-simple/src/main/java/dev/struchkov/godfather/telegram/simple/domain/attachment/send/DocumentSendAttachment.java
new file mode 100644
index 0000000..a41f14a
--- /dev/null
+++ b/telegram-domain/telegram-domain-simple/src/main/java/dev/struchkov/godfather/telegram/simple/domain/attachment/send/DocumentSendAttachment.java
@@ -0,0 +1,28 @@
+package dev.struchkov.godfather.telegram.simple.domain.attachment.send;
+
+import dev.struchkov.godfather.simple.domain.content.send.SendAttachment;
+import dev.struchkov.godfather.simple.domain.content.send.SendFile;
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@Getter
+@Setter
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor(access = AccessLevel.PRIVATE)
+public class DocumentSendAttachment implements SendAttachment {
+
+ public static final String TYPE = "DOCUMENT";
+
+ private SendFile sendFile;
+
+ @Override
+ public String getType() {
+ return TYPE;
+ }
+
+}
diff --git a/telegram-domain/telegram-domain-simple/src/main/java/dev/struchkov/godfather/telegram/simple/domain/attachment/send/PhotoSendAttachment.java b/telegram-domain/telegram-domain-simple/src/main/java/dev/struchkov/godfather/telegram/simple/domain/attachment/send/PhotoSendAttachment.java
new file mode 100644
index 0000000..a9b355a
--- /dev/null
+++ b/telegram-domain/telegram-domain-simple/src/main/java/dev/struchkov/godfather/telegram/simple/domain/attachment/send/PhotoSendAttachment.java
@@ -0,0 +1,28 @@
+package dev.struchkov.godfather.telegram.simple.domain.attachment.send;
+
+import dev.struchkov.godfather.simple.domain.content.send.SendAttachment;
+import dev.struchkov.godfather.simple.domain.content.send.SendFile;
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@Getter
+@Setter
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor(access = AccessLevel.PRIVATE)
+public class PhotoSendAttachment implements SendAttachment {
+
+ public static final String TYPE = "PHOTO";
+
+ private SendFile sendFile;
+
+ @Override
+ public String getType() {
+ return TYPE;
+ }
+
+}
diff --git a/telegram-sender/telegram-sender-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/sender/TelegramSender.java b/telegram-sender/telegram-sender-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/sender/TelegramSender.java
index 4316d2c..527c4aa 100644
--- a/telegram-sender/telegram-sender-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/sender/TelegramSender.java
+++ b/telegram-sender/telegram-sender-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/sender/TelegramSender.java
@@ -6,6 +6,7 @@ import dev.struchkov.godfather.quarkus.domain.SentBox;
import dev.struchkov.godfather.quarkus.domain.action.PreSendProcessing;
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
import dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload;
+import dev.struchkov.godfather.telegram.main.context.convert.MessageMailConvert;
import dev.struchkov.godfather.telegram.quarkus.context.repository.SenderRepository;
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramConnect;
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramSending;
@@ -179,7 +180,13 @@ public class TelegramSender implements TelegramSending {
});
return Uni.createFrom().completionStage(executeAsync(editMessageText))
- .onItem().ifNotNull().transformToUni(t -> Uni.createFrom().optional(SentBox.optional(telegramId, lastMessageId, boxAnswer, boxAnswer)))
+ .onItem().ifNotNull().transform(t -> {
+ final SentBox sentBox = new SentBox();
+ sentBox.setSentAnswer(boxAnswer);
+ sentBox.setOriginalAnswer(boxAnswer);
+ sentBox.setMessageId(telegramId);
+ return sentBox;
+ })
.onFailure(TelegramApiRequestException.class).recoverWithUni(
ex -> {
final TelegramApiRequestException exception = (TelegramApiRequestException) ex;
@@ -209,8 +216,17 @@ public class TelegramSender implements TelegramSending {
}
return Uni.createFrom().nullItem();
})
- .onItem().ifNotNull().transformToUni(
- answerMessages -> Uni.createFrom().optional(SentBox.optional(telegramId, answerMessages.get(answerMessages.size() - 1).getMessageId().toString(), boxAnswer, boxAnswer))
+ .onItem().ifNotNull().transform(
+ answerMessages -> {
+ final Message lastMessage = answerMessages.get(answerMessages.size() - 1);
+
+ final SentBox sentBox = new SentBox();
+ sentBox.setMessageId(lastMessage.getMessageId().toString());
+ sentBox.setOriginalAnswer(boxAnswer);
+ sentBox.setSentAnswer(boxAnswer);
+ sentBox.setSentMail(MessageMailConvert.apply(lastMessage));
+ return sentBox;
+ }
);
}
diff --git a/telegram-sender/telegram-sender-simple/src/main/java/dev/struchkov/godfather/telegram/simple/sender/TelegramSender.java b/telegram-sender/telegram-sender-simple/src/main/java/dev/struchkov/godfather/telegram/simple/sender/TelegramSender.java
index 26d5a5a..6714a85 100644
--- a/telegram-sender/telegram-sender-simple/src/main/java/dev/struchkov/godfather/telegram/simple/sender/TelegramSender.java
+++ b/telegram-sender/telegram-sender-simple/src/main/java/dev/struchkov/godfather/telegram/simple/sender/TelegramSender.java
@@ -4,23 +4,31 @@ import dev.struchkov.godfather.main.domain.SendType;
import dev.struchkov.godfather.simple.domain.BoxAnswer;
import dev.struchkov.godfather.simple.domain.SentBox;
import dev.struchkov.godfather.simple.domain.action.PreSendProcessing;
+import dev.struchkov.godfather.simple.domain.content.send.SendAttachment;
+import dev.struchkov.godfather.simple.domain.content.send.SendFile;
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
import dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload;
+import dev.struchkov.godfather.telegram.main.context.convert.MessageMailConvert;
import dev.struchkov.godfather.telegram.simple.context.repository.SenderRepository;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramConnect;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
+import dev.struchkov.godfather.telegram.simple.domain.attachment.send.PhotoSendAttachment;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.telegram.telegrambots.meta.api.methods.invoices.SendInvoice;
+import org.telegram.telegrambots.meta.api.methods.send.SendDocument;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
+import org.telegram.telegrambots.meta.api.methods.send.SendPhoto;
import org.telegram.telegrambots.meta.api.methods.updatingmessages.DeleteMessage;
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageText;
+import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.bots.AbsSender;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
+import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@@ -30,6 +38,7 @@ import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.DIS
import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.ENABLE_MARKDOWN;
import static dev.struchkov.godfather.telegram.main.sender.util.KeyBoardConvert.convertInlineKeyBoard;
import static dev.struchkov.godfather.telegram.main.sender.util.KeyBoardConvert.convertKeyBoard;
+import static dev.struchkov.haiti.utils.Checker.checkNotBlank;
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
import static java.lang.Boolean.TRUE;
@@ -148,6 +157,16 @@ public class TelegramSender implements TelegramSending {
}
}
}
+
+ final SendAttachment sendAttachment = boxAnswer.getAttachment();
+ if (checkNotNull(sendAttachment)) {
+ switch (sendAttachment.getType()) {
+ case "PHOTO":
+ return sendPhoto(boxAnswer, preparedAnswer);
+ case "DOCUMENT":
+ return sendDocument(boxAnswer, preparedAnswer);
+ }
+ }
return sendMessage(recipientTelegramId, boxAnswer, preparedAnswer, saveMessageId);
}
@@ -165,7 +184,14 @@ public class TelegramSender implements TelegramSending {
try {
absSender.execute(editMessageText);
- return SentBox.optional(telegramId, replaceMessageId, preparedAnswer, boxAnswer);
+ return Optional.of(
+ SentBox.builder()
+ .personId(telegramId)
+ .messageId(replaceMessageId)
+ .originalAnswer(boxAnswer)
+ .sentAnswer(boxAnswer)
+ .build()
+ );
} catch (TelegramApiRequestException e) {
log.error(e.getApiResponse());
if (ERROR_REPLACE_MESSAGE.equals(e.getApiResponse())) {
@@ -179,6 +205,7 @@ public class TelegramSender implements TelegramSending {
private Optional sendMessage(@NotNull String telegramId, @NotNull BoxAnswer boxAnswer, BoxAnswer preparedAnswer, boolean saveMessageId) {
final List sendMessages = splitBoxAnswerByMessageLength(boxAnswer, 4000);
+
Message execute = null;
for (SendMessage sendMessage : sendMessages) {
try {
@@ -193,11 +220,127 @@ public class TelegramSender implements TelegramSending {
if (checkNotNull(senderRepository) && saveMessageId) {
senderRepository.saveLastSendMessage(telegramId, execute.getMessageId().toString());
}
- return SentBox.optional(telegramId, execute.getMessageId().toString(), preparedAnswer, boxAnswer);
+ return Optional.of(
+ SentBox.builder()
+ .personId(telegramId)
+ .messageId(execute.getMessageId().toString())
+ .sentAnswer(boxAnswer)
+ .originalAnswer(boxAnswer)
+ .sentMail(MessageMailConvert.apply(execute))
+ .build()
+ );
}
return Optional.empty();
}
+ private Optional sendPhoto(BoxAnswer boxAnswer, BoxAnswer preparedAnswer) {
+ final PhotoSendAttachment photoSendAttachment = (PhotoSendAttachment) boxAnswer.getAttachment();
+ final SendFile sendFile = photoSendAttachment.getSendFile();
+
+ final SendPhoto sendPhoto = new SendPhoto();
+ sendPhoto.setCaption(boxAnswer.getMessage());
+ sendPhoto.setChatId(boxAnswer.getRecipientPersonId());
+ sendPhoto.setPhoto(convertInputFile(sendFile));
+ sendPhoto.setReplyMarkup(convertKeyBoard(boxAnswer.getKeyBoard()));
+
+ boxAnswer.getPayLoad(DISABLE_NOTIFICATION).ifPresent(isDisable -> {
+ if (TRUE.equals(isDisable)) sendPhoto.disableNotification();
+ });
+ boxAnswer.getPayLoad(ENABLE_MARKDOWN).ifPresent(isEnable -> {
+ if (TRUE.equals(isEnable)) sendPhoto.setParseMode("Markdown");
+ });
+
+ Message execute = null;
+ try {
+ execute = absSender.execute(sendPhoto);
+ } catch (TelegramApiRequestException e) {
+ log.error(e.getApiResponse());
+ } catch (TelegramApiException e) {
+ log.error(e.getMessage());
+ }
+ if (checkNotNull(execute)) {
+ if (checkNotNull(senderRepository)) {
+ senderRepository.saveLastSendMessage(boxAnswer.getRecipientPersonId(), execute.getMessageId().toString());
+ }
+ return Optional.of(
+ SentBox.builder()
+ .personId(boxAnswer.getRecipientPersonId())
+ .messageId(execute.getMessageId().toString())
+ .sentAnswer(boxAnswer)
+ .originalAnswer(boxAnswer)
+ .sentMail(MessageMailConvert.apply(execute))
+ .build()
+ );
+ }
+ return Optional.empty();
+ }
+
+ private Optional sendDocument(BoxAnswer boxAnswer, BoxAnswer preparedAnswer) {
+ final SendDocument sendDocument = new SendDocument();
+ sendDocument.setCaption(boxAnswer.getMessage());
+ sendDocument.setChatId(boxAnswer.getRecipientPersonId());
+ sendDocument.setReplyMarkup(convertKeyBoard(boxAnswer.getKeyBoard()));
+ sendDocument.setDocument(convertInputFile(boxAnswer.getAttachment().getSendFile()));
+ boxAnswer.getPayLoad(DISABLE_NOTIFICATION).ifPresent(isDisable -> {
+ if (TRUE.equals(isDisable)) sendDocument.disableNotification();
+ });
+ boxAnswer.getPayLoad(ENABLE_MARKDOWN).ifPresent(isEnable -> {
+ if (TRUE.equals(isEnable)) sendDocument.setParseMode("Markdown");
+ });
+
+ Message execute = null;
+ try {
+ execute = absSender.execute(sendDocument);
+ } catch (TelegramApiRequestException e) {
+ log.error(e.getApiResponse());
+ } catch (TelegramApiException e) {
+ log.error(e.getMessage());
+ }
+ if (checkNotNull(execute)) {
+ if (checkNotNull(senderRepository)) {
+ senderRepository.saveLastSendMessage(boxAnswer.getRecipientPersonId(), execute.getMessageId().toString());
+ }
+ return Optional.of(
+ SentBox.builder()
+ .personId(boxAnswer.getRecipientPersonId())
+ .messageId(execute.getMessageId().toString())
+ .sentAnswer(boxAnswer)
+ .originalAnswer(boxAnswer)
+ .sentMail(MessageMailConvert.apply(execute))
+ .build()
+ );
+ }
+ return Optional.empty();
+ }
+
+ private InputFile convertInputFile(SendFile sendFile) {
+ final File fileData = sendFile.getData();
+ final String fileName = sendFile.getFileName();
+
+ if (checkNotBlank(sendFile.getFileId())) {
+ return new InputFile(sendFile.getFileId());
+ }
+
+ if (checkNotBlank(sendFile.getUrl())) {
+ return new InputFile(sendFile.getUrl());
+ }
+
+ if (checkNotNull(fileData)) {
+ if (checkNotBlank(fileName)) {
+ return new InputFile(fileData, fileName);
+ } else {
+ return new InputFile(fileData);
+ }
+ }
+
+ if (checkNotNull(sendFile.getFileStream())) {
+ return new InputFile(sendFile.getFileStream(), fileName);
+ } else {
+ return new InputFile(fileName);
+ }
+
+ }
+
public List splitBoxAnswerByMessageLength(BoxAnswer boxAnswer, int maxMessageLength) {
final List split = new ArrayList<>();
String message = boxAnswer.getMessage();
@@ -205,15 +348,15 @@ public class TelegramSender implements TelegramSending {
while (message.length() > maxMessageLength) {
String subMessage = message.substring(0, maxMessageLength);
message = message.substring(maxMessageLength);
- split.add(createNewBoxAnswer(boxAnswer, subMessage));
+ split.add(createNewMessage(boxAnswer, subMessage));
}
- split.add(createNewBoxAnswer(boxAnswer, message));
+ split.add(createNewMessage(boxAnswer, message));
return split;
}
- private SendMessage createNewBoxAnswer(BoxAnswer boxAnswer, String subMessage) {
+ private SendMessage createNewMessage(BoxAnswer boxAnswer, String subMessage) {
final SendMessage sendMessage = new SendMessage();
sendMessage.setChatId(boxAnswer.getRecipientPersonId());
sendMessage.setText(subMessage);