Добавил поддержку payload для BoxAnswer и Message
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
901a1cdc05
commit
a53b37eb6c
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>dev.struchkov.godfather.telegram</groupId>
|
<groupId>dev.struchkov.godfather.telegram</groupId>
|
||||||
@ -14,6 +15,10 @@
|
|||||||
<groupId>dev.struchkov.godfather.telegram</groupId>
|
<groupId>dev.struchkov.godfather.telegram</groupId>
|
||||||
<artifactId>telegram-domain</artifactId>
|
<artifactId>telegram-domain</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>dev.struchkov.godfather.telegram</groupId>
|
||||||
|
<artifactId>telegram-context-main</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -8,8 +8,10 @@ import dev.struchkov.godfather.telegram.domain.attachment.DocumentAttachment;
|
|||||||
import dev.struchkov.godfather.telegram.domain.attachment.LinkAttachment;
|
import dev.struchkov.godfather.telegram.domain.attachment.LinkAttachment;
|
||||||
import dev.struchkov.godfather.telegram.domain.attachment.Picture;
|
import dev.struchkov.godfather.telegram.domain.attachment.Picture;
|
||||||
import dev.struchkov.godfather.telegram.domain.attachment.PictureGroupAttachment;
|
import dev.struchkov.godfather.telegram.domain.attachment.PictureGroupAttachment;
|
||||||
|
import dev.struchkov.godfather.telegram.main.context.MessagePayload;
|
||||||
import dev.struchkov.haiti.utils.Checker;
|
import dev.struchkov.haiti.utils.Checker;
|
||||||
import dev.struchkov.haiti.utils.Strings;
|
import dev.struchkov.haiti.utils.Strings;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.Chat;
|
||||||
import org.telegram.telegrambots.meta.api.objects.Contact;
|
import org.telegram.telegrambots.meta.api.objects.Contact;
|
||||||
import org.telegram.telegrambots.meta.api.objects.Document;
|
import org.telegram.telegrambots.meta.api.objects.Document;
|
||||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||||
@ -43,8 +45,11 @@ public final class MessageMailConvert {
|
|||||||
mail.setPersonId(chatId != null ? chatId.toString() : null);
|
mail.setPersonId(chatId != null ? chatId.toString() : null);
|
||||||
mail.setText(message.getText());
|
mail.setText(message.getText());
|
||||||
mail.setCreateDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(message.getDate()), ZoneId.systemDefault()));
|
mail.setCreateDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(message.getDate()), ZoneId.systemDefault()));
|
||||||
mail.setFirstName(message.getChat().getFirstName());
|
|
||||||
mail.setLastName(message.getChat().getLastName());
|
final Chat chat = message.getChat();
|
||||||
|
mail.setFirstName(chat.getFirstName());
|
||||||
|
mail.setLastName(chat.getLastName());
|
||||||
|
mail.setPayload(MessagePayload.USERNAME, chat.getUserName());
|
||||||
|
|
||||||
convertDocument(message.getDocument()).ifPresent(mail::addAttachment);
|
convertDocument(message.getDocument()).ifPresent(mail::addAttachment);
|
||||||
convertContact(message.getContact()).ifPresent(mail::addAttachment);
|
convertContact(message.getContact()).ifPresent(mail::addAttachment);
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
package dev.struchkov.godfather.telegram.main.context;
|
||||||
|
|
||||||
|
import dev.struchkov.godfather.main.domain.ContextKey;
|
||||||
|
import dev.struchkov.haiti.utils.Exceptions;
|
||||||
|
|
||||||
|
public final class BoxAnswerPayload {
|
||||||
|
|
||||||
|
public static final ContextKey<Boolean> DISABLE_WEB_PAGE_PREVIEW = ContextKey.of("DISABLE_WEB_PAGE_PREVIEW", Boolean.class);
|
||||||
|
public static final ContextKey<Boolean> DISABLE_NOTIFICATION = ContextKey.of("DISABLE_NOTIFICATION", Boolean.class);
|
||||||
|
|
||||||
|
private BoxAnswerPayload() {
|
||||||
|
Exceptions.utilityClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package dev.struchkov.godfather.telegram.main.context;
|
||||||
|
|
||||||
|
import dev.struchkov.godfather.main.domain.ContextKey;
|
||||||
|
import dev.struchkov.haiti.utils.Exceptions;
|
||||||
|
|
||||||
|
public final class MessagePayload {
|
||||||
|
|
||||||
|
public static final ContextKey<String> USERNAME = ContextKey.of("KEY", String.class);
|
||||||
|
|
||||||
|
private MessagePayload() {
|
||||||
|
Exceptions.utilityClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -22,8 +22,11 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.DISABLE_NOTIFICATION;
|
||||||
|
import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.DISABLE_WEB_PAGE_PREVIEW;
|
||||||
import static dev.struchkov.godfather.telegram.main.sender.util.KeyBoardConvert.convertInlineKeyBoard;
|
import static dev.struchkov.godfather.telegram.main.sender.util.KeyBoardConvert.convertInlineKeyBoard;
|
||||||
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||||
|
import static java.lang.Boolean.TRUE;
|
||||||
|
|
||||||
public class TelegramSender implements TelegramSending {
|
public class TelegramSender implements TelegramSending {
|
||||||
|
|
||||||
@ -148,6 +151,18 @@ public class TelegramSender implements TelegramSending {
|
|||||||
sendMessage.setText(boxAnswer.getMessage());
|
sendMessage.setText(boxAnswer.getMessage());
|
||||||
sendMessage.setReplyMarkup(KeyBoardConvert.convertKeyBoard(boxAnswer.getKeyBoard()));
|
sendMessage.setReplyMarkup(KeyBoardConvert.convertKeyBoard(boxAnswer.getKeyBoard()));
|
||||||
|
|
||||||
|
boxAnswer.getPayLoad(DISABLE_NOTIFICATION).ifPresent(
|
||||||
|
isDisable -> {
|
||||||
|
if (TRUE.equals(isDisable)) sendMessage.disableNotification();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
boxAnswer.getPayLoad(DISABLE_WEB_PAGE_PREVIEW).ifPresent(
|
||||||
|
isDisable -> {
|
||||||
|
if (TRUE.equals(isDisable)) sendMessage.disableWebPagePreview();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return absSender.execute(sendMessage);
|
return absSender.execute(sendMessage);
|
||||||
} catch (TelegramApiRequestException e) {
|
} catch (TelegramApiRequestException e) {
|
||||||
|
@ -24,8 +24,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.DISABLE_NOTIFICATION;
|
||||||
|
import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.DISABLE_WEB_PAGE_PREVIEW;
|
||||||
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||||
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
|
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
|
||||||
|
import static java.lang.Boolean.TRUE;
|
||||||
|
|
||||||
public class TelegramSender implements TelegramSending {
|
public class TelegramSender implements TelegramSending {
|
||||||
|
|
||||||
@ -136,6 +139,14 @@ public class TelegramSender implements TelegramSending {
|
|||||||
sendMessage.setChatId(telegramId);
|
sendMessage.setChatId(telegramId);
|
||||||
sendMessage.setText(boxAnswer.getMessage());
|
sendMessage.setText(boxAnswer.getMessage());
|
||||||
sendMessage.setReplyMarkup(KeyBoardConvert.convertKeyBoard(boxAnswer.getKeyBoard()));
|
sendMessage.setReplyMarkup(KeyBoardConvert.convertKeyBoard(boxAnswer.getKeyBoard()));
|
||||||
|
|
||||||
|
boxAnswer.getPayLoad(DISABLE_WEB_PAGE_PREVIEW).ifPresent(isDisable -> {
|
||||||
|
if (TRUE.equals(isDisable)) sendMessage.disableWebPagePreview();
|
||||||
|
});
|
||||||
|
boxAnswer.getPayLoad(DISABLE_NOTIFICATION).ifPresent(isDisable -> {
|
||||||
|
if (TRUE.equals(isDisable)) sendMessage.disableNotification();
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final Message execute = absSender.execute(sendMessage);
|
final Message execute = absSender.execute(sendMessage);
|
||||||
if (checkNotNull(senderRepository) && saveMessageId) {
|
if (checkNotNull(senderRepository) && saveMessageId) {
|
||||||
|
Loading…
Reference in New Issue
Block a user