Добавил реактивную версию для Quarkus

This commit is contained in:
Struchkov Mark 2022-08-07 07:09:04 +03:00
parent 95a8084cae
commit 6e4837a8e7
66 changed files with 1108 additions and 208 deletions

102
pom.xml
View File

@ -38,7 +38,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<godfather.core.ver>0.0.24</godfather.core.ver>
<godfather.core.ver>0.0.25</godfather.core.ver>
<telegrambots.ver>6.1.0</telegrambots.ver>
<haiti.version>1.4.0</haiti.version>
@ -57,11 +57,71 @@
<artifactId>telegram-domain</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-context</artifactId>
<artifactId>telegram-context-main</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-context-simple</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-context-quarkus</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-core-main</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-core-simple</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-core-quarkus</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-consumer-main</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-consumer-simple</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-consumer-quarkus</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-sender-main</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-sender-simple</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-sender-quarkus</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-core</artifactId>
@ -90,16 +150,45 @@
<version>${project.version}</version>
</dependency>
<!--godfather-->
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-context</artifactId>
<artifactId>bot-domain-main</artifactId>
<version>${godfather.core.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-context-main</artifactId>
<version>${godfather.core.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-core</artifactId>
<artifactId>bot-context-simple</artifactId>
<version>${godfather.core.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-context-quarkus</artifactId>
<version>${godfather.core.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-core-main</artifactId>
<version>${godfather.core.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-core-simple</artifactId>
<version>${godfather.core.ver}</version>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-core-quarkus</artifactId>
<version>${godfather.core.ver}</version>
</dependency>
<!--/godfather-->
<dependency>
<groupId>dev.struchkov.haiti</groupId>
@ -112,6 +201,11 @@
<artifactId>telegrambots</artifactId>
<version>${telegrambots.ver}</version>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId>
<version>${telegrambots.ver}</version>
</dependency>
<dependency>
<groupId>org.telegram</groupId>

View File

@ -10,20 +10,12 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>telegram-consumer</artifactId>
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-context</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-context</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-core</artifactId>
</dependency>
</dependencies>
<packaging>pom</packaging>
<modules>
<module>telegram-consumer-main</module>
<module>telegram-consumer-simple</module>
<module>telegram-consumer-quarkus</module>
</modules>
<properties>
<maven.compiler.source>17</maven.compiler.source>

View File

@ -0,0 +1,27 @@
<?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">
<parent>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-consumer</artifactId>
<version>0.0.30</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>telegram-consumer-main</artifactId>
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-domain</artifactId>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -1,11 +1,9 @@
package dev.struchkov.godfather.telegram.convert;
package dev.struchkov.godfather.telegram.main.consumer;
import dev.struchkov.godfather.context.domain.content.Mail;
import dev.struchkov.godfather.main.domain.content.Mail;
import org.telegram.telegrambots.meta.api.objects.CallbackQuery;
import org.telegram.telegrambots.meta.api.objects.User;
import java.time.LocalDateTime;
/**
* TODO: Добавить описание класса.
*
@ -17,7 +15,6 @@ public class CallbackQueryConvert {
final Mail mail = new Mail();
mail.setText(callbackQuery.getData());
mail.setPersonId(callbackQuery.getMessage().getChatId());
mail.setAddDate(LocalDateTime.now());
final User user = callbackQuery.getFrom();
mail.setFirstName(user.getFirstName());

View File

@ -1,13 +1,14 @@
package dev.struchkov.godfather.telegram.convert;
package dev.struchkov.godfather.telegram.main.consumer;
import dev.struchkov.godfather.context.domain.content.Mail;
import dev.struchkov.godfather.context.domain.content.attachment.Attachment;
import dev.struchkov.godfather.main.domain.content.Attachment;
import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.telegram.domain.attachment.CommandAttachment;
import dev.struchkov.godfather.telegram.domain.attachment.ContactAttachment;
import dev.struchkov.godfather.telegram.domain.attachment.DocumentAttachment;
import dev.struchkov.godfather.telegram.domain.attachment.LinkAttachment;
import dev.struchkov.godfather.telegram.domain.attachment.Picture;
import dev.struchkov.godfather.telegram.domain.attachment.PictureGroupAttachment;
import dev.struchkov.haiti.utils.Checker;
import dev.struchkov.haiti.utils.Strings;
import org.telegram.telegrambots.meta.api.objects.Contact;
import org.telegram.telegrambots.meta.api.objects.Document;
@ -22,7 +23,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
/**
@ -39,7 +39,6 @@ public final class MessageMailConvert {
public static Mail apply(Message message) {
final Mail mail = new Mail();
mail.setPersonId(message.getChatId());
mail.setAddDate(LocalDateTime.now());
mail.setText(message.getText());
mail.setCreateDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(message.getDate()), ZoneId.systemDefault()));
mail.setFirstName(message.getChat().getFirstName());
@ -115,7 +114,7 @@ public final class MessageMailConvert {
private static List<Attachment> convertAttachments(Message message) {
final List<MessageEntity> entities = message.getEntities();
if (checkNotEmpty(entities)) {
if (Checker.checkNotEmpty(entities)) {
return entities.stream()
.map(entity -> convertEntity(message, entity))
.filter(Optional::isPresent)
@ -133,7 +132,7 @@ public final class MessageMailConvert {
case "bot_command" -> {
final String commandValue = entity.getText();
String commandArg = message.getText().replace(commandValue, "");
if (checkNotEmpty(commandArg)) {
if (Checker.checkNotEmpty(commandArg)) {
commandArg = commandArg.substring(1);
}
final CommandAttachment commandAttachment = new CommandAttachment();

View File

@ -1,11 +1,13 @@
package dev.struchkov.godfather.telegram.convert;
package dev.struchkov.godfather.telegram.main.consumer;
import dev.struchkov.godfather.telegram.domain.event.Subscribe;
import dev.struchkov.haiti.utils.Exceptions;
import org.telegram.telegrambots.meta.api.objects.Chat;
import org.telegram.telegrambots.meta.api.objects.ChatMemberUpdated;
import java.time.LocalDateTime;
import static dev.struchkov.haiti.utils.Exceptions.*;
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
public final class SubscribeConvert {

View File

@ -1,4 +1,4 @@
package dev.struchkov.godfather.telegram.convert;
package dev.struchkov.godfather.telegram.main.consumer;
import dev.struchkov.godfather.telegram.domain.event.Unsubscribe;
import org.telegram.telegrambots.meta.api.objects.Chat;

View File

@ -0,0 +1,35 @@
<?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">
<parent>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-consumer</artifactId>
<version>0.0.30</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>telegram-consumer-quarkus</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-context-quarkus</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-consumer-main</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-core-quarkus</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,126 @@
package dev.struchkov.godfather.telegram.quarkus.consumer;
import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.quarkus.context.service.EventHandler;
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.quarkus.context.service.EventDistributor;
import dev.struchkov.godfather.telegram.quarkus.core.TelegramConnectBot;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import org.jetbrains.annotations.NotNull;
import org.telegram.telegrambots.meta.api.objects.CallbackQuery;
import org.telegram.telegrambots.meta.api.objects.ChatMemberUpdated;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
/**
* TODO: Добавить описание класса.
*
* @author upagge [30.01.2020]
*/
public class EventDistributorService implements EventDistributor {
private final Map<String, List<EventHandler>> eventHandlerMap;
public EventDistributorService(TelegramConnectBot telegramConnectBot, List<EventHandler> eventProviders) {
this.eventHandlerMap = eventProviders.stream().collect(Collectors.groupingBy(EventHandler::getEventType));
telegramConnectBot.initEventDistributor(this);
}
@Override
public Uni<Void> processing(@NotNull Update update) {
return Uni.createFrom().voidItem()
.onItem().transformToUni(
v -> {
if (checkNotNull(update.getMessage())) {
final Message message = update.getMessage();
if (!isEvent(message)) {
final Optional<List<EventHandler>> optHandlers = getHandler(Mail.TYPE);
if (optHandlers.isPresent()) {
return Multi.createFrom().iterable(optHandlers.get())
.onItem().transformToUni(
eventHandler -> eventHandler.handle(MessageMailConvert.apply(message))
).concatenate().toUni().replaceWithVoid();
}
return Uni.createFrom().voidItem();
}
}
if (checkNotNull(update.getCallbackQuery())) {
final CallbackQuery callbackQuery = update.getCallbackQuery();
final Optional<List<EventHandler>> optHandlers = getHandler(Mail.TYPE);
if (optHandlers.isPresent()) {
return Multi.createFrom().iterable(optHandlers.get())
.onItem().transformToUni(
eventHandler -> eventHandler.handle(CallbackQueryConvert.apply(callbackQuery))
).concatenate().toUni().replaceWithVoid();
}
return Uni.createFrom().voidItem();
}
if (checkNotNull(update.getMyChatMember())) {
final ChatMemberUpdated chatMember = update.getMyChatMember();
if ("kicked".equals(chatMember.getNewChatMember().getStatus())) {
final Optional<List<EventHandler>> optHandlers = getHandler(Unsubscribe.TYPE);
if (optHandlers.isPresent()) {
return Multi.createFrom().iterable(optHandlers.get())
.onItem().transformToUni(
eventHandler -> eventHandler.handle(UnsubscribeConvert.apply(chatMember))
).concatenate().toUni().replaceWithVoid();
}
return Uni.createFrom().voidItem();
}
if ("member".equals(chatMember.getNewChatMember().getStatus())) {
final Optional<List<EventHandler>> optHandlers = getHandler(Subscribe.TYPE);
if (optHandlers.isPresent()) {
return Multi.createFrom().iterable(optHandlers.get())
.onItem().transformToUni(
eventHandler -> eventHandler.handle(SubscribeConvert.apply(chatMember))
).concatenate().toUni().replaceWithVoid();
}
return Uni.createFrom().voidItem();
}
}
return Uni.createFrom().voidItem();
}
);
}
private boolean isEvent(Message message) {
return message.getChannelChatCreated() != null
|| message.getDeleteChatPhoto() != null
|| isNewChatMember(message.getNewChatMembers())
|| message.getNewChatTitle() != null
|| message.getNewChatPhoto() != null
|| message.getVideoChatEnded() != null
|| message.getVideoChatParticipantsInvited() != null
|| message.getVideoChatScheduled() != null
|| message.getVideoNote() != null
|| message.getVideoChatStarted() != null;
}
private boolean isNewChatMember(List<User> newChatMembers) {
if (newChatMembers == null) {
return true;
} else {
return !newChatMembers.isEmpty();
}
}
private Optional<List<EventHandler>> getHandler(String type) {
return Optional.ofNullable(eventHandlerMap.get(type));
}
}

View File

@ -0,0 +1,35 @@
<?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">
<parent>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-consumer</artifactId>
<version>0.0.30</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>telegram-consumer-simple</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-context-simple</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-consumer-main</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-core-simple</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,15 +1,15 @@
package dev.struchkov.godfather.telegram.listen;
package dev.struchkov.godfather.telegram.simple.consumer;
import dev.struchkov.godfather.context.domain.content.Mail;
import dev.struchkov.godfather.context.service.EventHandler;
import dev.struchkov.godfather.telegram.TelegramConnectBot;
import dev.struchkov.godfather.telegram.context.EventDistributor;
import dev.struchkov.godfather.telegram.convert.CallbackQueryConvert;
import dev.struchkov.godfather.telegram.convert.MessageMailConvert;
import dev.struchkov.godfather.telegram.convert.SubscribeConvert;
import dev.struchkov.godfather.telegram.convert.UnsubscribeConvert;
import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.simple.context.service.EventHandler;
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.simple.context.service.EventDistributor;
import dev.struchkov.godfather.telegram.simple.core.TelegramConnectBot;
import org.jetbrains.annotations.NotNull;
import org.telegram.telegrambots.meta.api.objects.CallbackQuery;
import org.telegram.telegrambots.meta.api.objects.ChatMemberUpdated;

View File

@ -10,22 +10,16 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>telegram-context</artifactId>
<packaging>pom</packaging>
<modules>
<module>telegram-context-main</module>
<module>telegram-context-simple</module>
<module>telegram-context-quarkus</module>
</modules>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-context</artifactId>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,11 +0,0 @@
package dev.struchkov.godfather.telegram.context;
import dev.struchkov.godfather.context.domain.BoxAnswer;
import dev.struchkov.godfather.context.service.sender.Sending;
import org.jetbrains.annotations.NotNull;
public interface TelegramSending extends Sending {
void sendNotSave(@NotNull Long personId, @NotNull BoxAnswer boxAnswer);
}

View File

@ -4,12 +4,12 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-sender</artifactId>
<artifactId>telegram-context</artifactId>
<version>0.0.30</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>telegram-sender-core</artifactId>
<artifactId>telegram-context-main</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
@ -22,7 +22,6 @@
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-domain</artifactId>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>

View File

@ -1,4 +1,4 @@
package dev.struchkov.godfather.telegram.context;
package dev.struchkov.godfather.telegram.main.context;
import org.telegram.telegrambots.meta.bots.AbsSender;

View File

@ -0,0 +1,36 @@
<?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">
<parent>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-context</artifactId>
<version>0.0.30</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>telegram-context-quarkus</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-context-quarkus</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-context-main</artifactId>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,13 @@
package dev.struchkov.godfather.telegram.quarkus.context.service;
import io.smallrye.mutiny.Uni;
import org.telegram.telegrambots.meta.api.objects.Update;
import javax.validation.constraints.NotNull;
public interface EventDistributor {
Uni<Void> processing(@NotNull Update update);
}

View File

@ -0,0 +1,13 @@
package dev.struchkov.godfather.telegram.quarkus.context.service;
import io.smallrye.mutiny.Uni;
public interface SenderStorageService {
Uni<Integer> getLastSendMessage(Long telegramId);
Uni<Void> saveLastSendMessage(Long telegramId, Integer messageId);
Uni<Void> removeLastSendMessage(Long telegramId);
}

View File

@ -0,0 +1,18 @@
package dev.struchkov.godfather.telegram.quarkus.context.service;
import org.telegram.telegrambots.meta.bots.AbsSender;
import javax.validation.constraints.NotNull;
/**
* TODO: Добавить описание интерфейса.
*
* @author upagge [12.02.2020]
*/
public interface TelegramBot {
AbsSender getAdsSender();
void initEventDistributor(@NotNull EventDistributor eventDistributor);
}

View File

@ -0,0 +1,12 @@
package dev.struchkov.godfather.telegram.quarkus.context.service;
import dev.struchkov.godfather.main.domain.BoxAnswer;
import dev.struchkov.godfather.quarkus.context.service.Sending;
import io.smallrye.mutiny.Uni;
import org.jetbrains.annotations.NotNull;
public interface TelegramSending extends Sending {
Uni<Void> sendNotSave(@NotNull Long personId, @NotNull BoxAnswer boxAnswer);
}

View File

@ -0,0 +1,37 @@
<?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">
<parent>
<artifactId>telegram-context</artifactId>
<groupId>dev.struchkov.godfather.telegram</groupId>
<version>0.0.30</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>telegram-context-simple</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-context-main</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-context-simple</artifactId>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,4 +1,4 @@
package dev.struchkov.godfather.telegram.context;
package dev.struchkov.godfather.telegram.simple.context.service;
import org.telegram.telegrambots.meta.api.objects.Update;

View File

@ -1,4 +1,4 @@
package dev.struchkov.godfather.telegram.context;
package dev.struchkov.godfather.telegram.simple.context.service;
import java.util.Optional;

View File

@ -1,4 +1,4 @@
package dev.struchkov.godfather.telegram.context;
package dev.struchkov.godfather.telegram.simple.context.service;
import org.telegram.telegrambots.meta.bots.AbsSender;

View File

@ -0,0 +1,11 @@
package dev.struchkov.godfather.telegram.simple.context.service;
import dev.struchkov.godfather.main.domain.BoxAnswer;
import dev.struchkov.godfather.simple.context.service.Sending;
import org.jetbrains.annotations.NotNull;
public interface TelegramSending extends Sending {
void sendNotSave(@NotNull Long personId, @NotNull BoxAnswer boxAnswer);
}

View File

@ -7,41 +7,16 @@
<artifactId>telegram-bot</artifactId>
<version>0.0.30</version>
</parent>
<modules>
<module>telegram-core-main</module>
<module>telegram-core-simple</module>
<module>telegram-core-quarkus</module>
</modules>
<artifactId>telegram-core</artifactId>
<packaging>pom</packaging>
<name>Telegram Core</name>
<description>Allows you to create bots for Telegram</description>
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-domain</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-context</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-core</artifactId>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambotsextensions</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,24 +0,0 @@
package dev.struchkov.godfather.telegram.autoresponder;
import dev.struchkov.godfather.context.domain.content.Mail;
import dev.struchkov.godfather.context.service.PersonSettingService;
import dev.struchkov.godfather.context.service.StorylineService;
import dev.struchkov.godfather.context.service.sender.Sending;
import dev.struchkov.godfather.core.GeneralAutoResponder;
/**
* TODO: Добавить описание класса.
*
* @author upagge [18.08.2019]
*/
public class MailAutoresponderTelegram extends GeneralAutoResponder<Mail> {
public MailAutoresponderTelegram(
Sending sending,
PersonSettingService personSettingService,
StorylineService<Mail> storyLineService
) {
super(sending, personSettingService, storyLineService);
}
}

View File

@ -0,0 +1,27 @@
<?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">
<parent>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-core</artifactId>
<version>0.0.30</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>telegram-core-main</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-context-main</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,7 +1,7 @@
package dev.struchkov.godfather.telegram;
package dev.struchkov.godfather.telegram.main.core;
import dev.struchkov.godfather.telegram.context.TelegramConnect;
import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig;
import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
import org.telegram.telegrambots.bots.DefaultAbsSender;
import org.telegram.telegrambots.bots.DefaultBotOptions;
import org.telegram.telegrambots.meta.bots.AbsSender;

View File

@ -1,6 +1,6 @@
package dev.struchkov.godfather.telegram.utils;
package dev.struchkov.godfather.telegram.main.core.util;
import dev.struchkov.godfather.context.domain.content.attachment.Attachment;
import dev.struchkov.godfather.main.domain.content.Attachment;
import dev.struchkov.godfather.telegram.domain.attachment.CommandAttachment;
import dev.struchkov.godfather.telegram.domain.attachment.ContactAttachment;
import dev.struchkov.godfather.telegram.domain.attachment.DocumentAttachment;

View File

@ -1,16 +1,16 @@
package dev.struchkov.godfather.telegram.utils;
package dev.struchkov.godfather.telegram.main.core.util;
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton;
import dev.struchkov.godfather.context.domain.keyboard.button.SimpleButton;
import dev.struchkov.godfather.context.domain.keyboard.simple.SimpleKeyBoard;
import dev.struchkov.godfather.context.domain.keyboard.simple.SimpleKeyBoardLine;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoardButton;
import dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton;
import dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoard;
import dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine;
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
import java.util.Arrays;
import java.util.List;
import static dev.struchkov.godfather.context.domain.keyboard.button.SimpleButton.simpleButton;
import static dev.struchkov.godfather.context.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
public final class InlineKeyBoards {

View File

@ -0,0 +1,36 @@
<?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">
<parent>
<artifactId>telegram-core</artifactId>
<groupId>dev.struchkov.godfather.telegram</groupId>
<version>0.0.30</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>telegram-core-quarkus</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-context-quarkus</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-core-main</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-core-quarkus</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,24 @@
package dev.struchkov.godfather.telegram.quarkus.core;
import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.quarkus.context.service.PersonSettingService;
import dev.struchkov.godfather.quarkus.core.GeneralAutoResponder;
import dev.struchkov.godfather.quarkus.core.service.StorylineService;
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramSending;
/**
* TODO: Добавить описание класса.
*
* @author upagge [18.08.2019]
*/
public class MailAutoresponderTelegram extends GeneralAutoResponder<Mail> {
public MailAutoresponderTelegram(
TelegramSending sending,
PersonSettingService personSettingService,
StorylineService<Mail> storyLineService
) {
super(sending, personSettingService, storyLineService);
}
}

View File

@ -0,0 +1,125 @@
package dev.struchkov.godfather.telegram.quarkus.core;
import dev.struchkov.godfather.telegram.domain.config.ProxyConfig;
import dev.struchkov.godfather.telegram.domain.config.ProxyConfig.Type;
import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig;
import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
import dev.struchkov.godfather.telegram.quarkus.context.service.EventDistributor;
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramBot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.telegram.telegrambots.bots.DefaultBotOptions;
import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.bots.AbsSender;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
/**
* TODO: Добавить описание класса.
*
* @author upagge [30.01.2020]
*/
public class TelegramConnectBot implements TelegramConnect {
private static final Logger log = LoggerFactory.getLogger(TelegramConnectBot.class);
private TelegramBot telegramBot;
private final TelegramConnectConfig telegramConnectConfig;
public TelegramConnectBot(TelegramConnectConfig telegramConnectConfig) {
this.telegramConnectConfig = telegramConnectConfig;
initLongPolling(telegramConnectConfig);
}
// public TelegramConnect(TelegramWebHookConfig telegramWebHookConfig) {
// initWebHook(telegramWebHookConfig);
// }
//
// private void initWebHook(TelegramWebHookConfig telegramWebHookConfig) {
// TelegramBotsApi botapi = new TelegramBotsApi();
// final TelegramWebhookBot telegramWebhookBot = new TelegramHookBot(telegramWebHookConfig);
// try {
// botapi.registerBot(telegramWebhookBot);
// this.telegramBot = (TelegramBot) telegramWebhookBot;
// } catch (TelegramApiRequestException e) {
// e.printStackTrace();
// }
// }
private void initLongPolling(TelegramConnectConfig telegramConnectConfig) {
final ProxyConfig proxyConfig = telegramConnectConfig.getProxyConfig();
if (proxyConfig != null && proxyConfig.getPassword() != null) {
try {
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
proxyConfig.getUser(),
proxyConfig.getPassword().toCharArray()
);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
final TelegramBotsApi botapi;
try {
if (proxyConfig != null && proxyConfig.getHost() != null) {
System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
System.setProperty("javax.net.debug", "all");
log.info(System.getProperty("https.protocols"));
DefaultBotOptions botOptions = new DefaultBotOptions();
botOptions.setProxyHost(proxyConfig.getHost());
botOptions.setProxyPort(proxyConfig.getPort());
botOptions.setProxyType(convertProxyType(proxyConfig.getType()));
final TelegramPollingBot bot = new TelegramPollingBot(telegramConnectConfig, botOptions);
botapi = new TelegramBotsApi(DefaultBotSession.class);
botapi.registerBot(bot);
this.telegramBot = bot;
} else {
final TelegramPollingBot bot = new TelegramPollingBot(telegramConnectConfig);
botapi = new TelegramBotsApi(DefaultBotSession.class);
botapi.registerBot(bot);
this.telegramBot = bot;
}
} catch (TelegramApiException e) {
log.error(e.getMessage());
}
}
private DefaultBotOptions.ProxyType convertProxyType(Type type) {
switch (type) {
case SOCKS5:
return DefaultBotOptions.ProxyType.SOCKS5;
case SOCKS4:
return DefaultBotOptions.ProxyType.SOCKS4;
case HTTP:
return DefaultBotOptions.ProxyType.HTTP;
default:
return DefaultBotOptions.ProxyType.NO_PROXY;
}
}
public void initEventDistributor(EventDistributor eventDistributor) {
telegramBot.initEventDistributor(eventDistributor);
}
public String getToken() {
return telegramConnectConfig.getBotToken();
}
@Override
public AbsSender getAbsSender() {
return telegramBot.getAdsSender();
}
}

View File

@ -0,0 +1,59 @@
package dev.struchkov.godfather.telegram.quarkus.core;
import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig;
import dev.struchkov.godfather.telegram.quarkus.context.service.EventDistributor;
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramBot;
import org.jetbrains.annotations.NotNull;
import org.telegram.telegrambots.bots.DefaultBotOptions;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.bots.AbsSender;
/**
* TODO: Добавить описание класса.
*
* @author upagge [15/07/2019]
*/
public class TelegramPollingBot extends TelegramLongPollingBot implements TelegramBot {
private final TelegramConnectConfig telegramConnectConfig;
private EventDistributor eventDistributor;
public TelegramPollingBot(TelegramConnectConfig telegramConnectConfig, DefaultBotOptions defaultBotOptions) {
super(defaultBotOptions);
this.telegramConnectConfig = telegramConnectConfig;
}
public TelegramPollingBot(TelegramConnectConfig telegramConnectConfig) {
this.telegramConnectConfig = telegramConnectConfig;
}
@Override
public void onUpdateReceived(Update update) {
if (update != null && eventDistributor != null) {
eventDistributor.processing(update)
.subscribe().asCompletionStage();
}
}
@Override
public String getBotUsername() {
return telegramConnectConfig.getBotUsername();
}
@Override
public String getBotToken() {
return telegramConnectConfig.getBotToken();
}
@Override
public AbsSender getAdsSender() {
return this;
}
@Override
public void initEventDistributor(@NotNull EventDistributor eventDistributor) {
this.eventDistributor = eventDistributor;
}
}

View File

@ -0,0 +1,128 @@
package dev.struchkov.godfather.telegram.quarkus.core.service;
import dev.struchkov.godfather.telegram.domain.attachment.DocumentAttachment;
import dev.struchkov.godfather.telegram.domain.attachment.Picture;
import dev.struchkov.godfather.telegram.domain.files.ByteContainer;
import dev.struchkov.godfather.telegram.domain.files.FileContainer;
import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.telegram.telegrambots.meta.api.methods.GetFile;
import org.telegram.telegrambots.meta.bots.AbsSender;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.UUID;
import java.util.stream.Stream;
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
public class AttachmentServiceImpl {
private static final Logger log = LoggerFactory.getLogger(AttachmentServiceImpl.class);
private final AbsSender absSender;
private final String botToken;
private String folderPathForFiles;
public AttachmentServiceImpl(TelegramConnect telegramConnect) {
this.absSender = telegramConnect.getAbsSender();
this.botToken = telegramConnect.getToken();
}
public void setFolderPathForFiles(String folderPathForFiles) {
if (folderPathForFiles != null) {
this.folderPathForFiles = folderPathForFiles + "/";
try (final Stream<Path> pathStream = Files.list(Path.of(folderPathForFiles))) {
pathStream.forEach(path -> {
try {
Files.delete(path);
} catch (IOException e) {
log.error(e.getMessage());
}
});
} catch (IOException e) {
log.error(e.getMessage());
}
}
}
public FileContainer uploadFile(@NotNull DocumentAttachment documentAttachment) {
isNotNull(documentAttachment);
try {
final File file = downloadFile(documentAttachment);
return new FileContainer(documentAttachment.getFileName(), documentAttachment.getMimeType(), file);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return FileContainer.empty();
}
public ByteContainer uploadBytes(@NotNull DocumentAttachment documentAttachment) {
isNotNull(documentAttachment);
try {
final byte[] bytes = downloadBytes(documentAttachment);
return new ByteContainer(documentAttachment.getFileName(), documentAttachment.getMimeType(), bytes);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return ByteContainer.empty();
}
public ByteContainer uploadBytes(@NotNull Picture picture) {
isNotNull(picture);
try {
final byte[] bytes = downloadBytes(picture);
return new ByteContainer(null, "image/jpeg", bytes);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return ByteContainer.empty();
}
private byte[] downloadBytes(Picture picture) throws TelegramApiException, IOException {
return telegramDownloadBytes(picture.getFileId());
}
private byte[] downloadBytes(DocumentAttachment documentAttachment) throws TelegramApiException, IOException {
return telegramDownloadBytes(documentAttachment.getFileId());
}
private byte[] telegramDownloadBytes(String fileId) throws TelegramApiException, IOException {
final String fileUrl = getFileUrl(fileId);
return IOUtils.toByteArray(new URL(fileUrl));
}
private File downloadFile(DocumentAttachment documentAttachment) throws IOException, TelegramApiException {
final String fileUrl = getFileUrl(documentAttachment.getFileId());
final StringBuilder filePath = new StringBuilder();
if (folderPathForFiles != null) {
filePath.append(folderPathForFiles);
}
filePath.append(UUID.randomUUID());
filePath.append("_");
filePath.append(documentAttachment.getFileName());
final File localFile = new File(filePath.toString());
final InputStream is = new URL(fileUrl).openStream();
FileUtils.copyInputStreamToFile(is, localFile);
return localFile;
}
private String getFileUrl(String fileId) throws TelegramApiException {
final GetFile getFile = new GetFile();
getFile.setFileId(fileId);
return absSender.execute(getFile).getFileUrl(botToken);
}
}

View File

@ -0,0 +1,34 @@
package dev.struchkov.godfather.telegram.quarkus.core.service;
import dev.struchkov.godfather.telegram.quarkus.context.service.SenderStorageService;
import io.smallrye.mutiny.Uni;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
public class SenderMapStorageService implements SenderStorageService {
private final Map<Long, Integer> lastMessageId = new HashMap<>();
@Override
public Uni<Integer> getLastSendMessage(Long telegramId) {
return Uni.createFrom().item(lastMessageId.get(telegramId));
}
@Override
public Uni<Void> saveLastSendMessage(@NotNull Long telegramId, @NotNull Integer messageId) {
isNotNull(telegramId);
lastMessageId.put(telegramId, messageId);
return Uni.createFrom().voidItem();
}
@Override
public Uni<Void> removeLastSendMessage(Long telegramId) {
lastMessageId.remove(telegramId);
return Uni.createFrom().voidItem();
}
}

View File

@ -4,12 +4,12 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-sender</artifactId>
<artifactId>telegram-core</artifactId>
<version>0.0.30</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>telegram-simple-sender</artifactId>
<artifactId>telegram-core-simple</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
@ -20,19 +20,17 @@
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-sender-core</artifactId>
<artifactId>telegram-context-simple</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-core</artifactId>
<artifactId>telegram-core-main</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-context</artifactId>
<artifactId>bot-core-simple</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,24 @@
package dev.struchkov.godfather.telegram.simple.core;
import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.simple.context.service.PersonSettingService;
import dev.struchkov.godfather.simple.core.GeneralAutoResponder;
import dev.struchkov.godfather.simple.core.service.StorylineService;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
/**
* TODO: Добавить описание класса.
*
* @author upagge [18.08.2019]
*/
public class MailAutoresponderTelegram extends GeneralAutoResponder<Mail> {
public MailAutoresponderTelegram(
TelegramSending sending,
PersonSettingService personSettingService,
StorylineService<Mail> storyLineService
) {
super(sending, personSettingService, storyLineService);
}
}

View File

@ -1,11 +1,11 @@
package dev.struchkov.godfather.telegram;
package dev.struchkov.godfather.telegram.simple.core;
import dev.struchkov.godfather.telegram.context.EventDistributor;
import dev.struchkov.godfather.telegram.context.TelegramBot;
import dev.struchkov.godfather.telegram.context.TelegramConnect;
import dev.struchkov.godfather.telegram.domain.config.ProxyConfig;
import dev.struchkov.godfather.telegram.domain.config.ProxyConfig.Type;
import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig;
import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
import dev.struchkov.godfather.telegram.simple.context.service.EventDistributor;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramBot;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.telegram.telegrambots.bots.DefaultBotOptions;

View File

@ -1,8 +1,8 @@
package dev.struchkov.godfather.telegram;
package dev.struchkov.godfather.telegram.simple.core;
import dev.struchkov.godfather.telegram.context.EventDistributor;
import dev.struchkov.godfather.telegram.context.TelegramBot;
import dev.struchkov.godfather.telegram.domain.config.TelegramConnectConfig;
import dev.struchkov.godfather.telegram.simple.context.service.EventDistributor;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramBot;
import org.jetbrains.annotations.NotNull;
import org.telegram.telegrambots.bots.DefaultBotOptions;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;

View File

@ -1,10 +1,10 @@
package dev.struchkov.godfather.telegram.service;
package dev.struchkov.godfather.telegram.simple.core.service;
import dev.struchkov.godfather.telegram.context.TelegramConnect;
import dev.struchkov.godfather.telegram.domain.attachment.DocumentAttachment;
import dev.struchkov.godfather.telegram.domain.attachment.Picture;
import dev.struchkov.godfather.telegram.domain.files.ByteContainer;
import dev.struchkov.godfather.telegram.domain.files.FileContainer;
import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
@ -113,7 +113,7 @@ public class AttachmentServiceImpl {
filePath.append("_");
filePath.append(documentAttachment.getFileName());
final java.io.File localFile = new java.io.File(filePath.toString());
final File localFile = new File(filePath.toString());
final InputStream is = new URL(fileUrl).openStream();
FileUtils.copyInputStreamToFile(is, localFile);
return localFile;

View File

@ -1,6 +1,6 @@
package dev.struchkov.godfather.telegram.service;
package dev.struchkov.godfather.telegram.simple.core.service;
import dev.struchkov.godfather.telegram.context.SenderStorageService;
import dev.struchkov.godfather.telegram.simple.context.service.SenderStorageService;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;

View File

@ -3,8 +3,8 @@
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">
<parent>
<artifactId>telegram-bot</artifactId>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-bot</artifactId>
<version>0.0.30</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -19,7 +19,7 @@
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-context</artifactId>
<artifactId>bot-context-main</artifactId>
</dependency>
<dependency>

View File

@ -1,6 +1,6 @@
package dev.struchkov.godfather.telegram.domain.attachment;
import dev.struchkov.godfather.context.domain.content.attachment.Attachment;
import dev.struchkov.godfather.main.domain.content.Attachment;
import java.util.Optional;

View File

@ -1,6 +1,6 @@
package dev.struchkov.godfather.telegram.domain.attachment;
import dev.struchkov.godfather.context.domain.content.attachment.Attachment;
import dev.struchkov.godfather.main.domain.content.Attachment;
public class ContactAttachment extends Attachment {

View File

@ -1,6 +1,6 @@
package dev.struchkov.godfather.telegram.domain.attachment;
import dev.struchkov.godfather.context.domain.content.attachment.Attachment;
import dev.struchkov.godfather.main.domain.content.Attachment;
public class DocumentAttachment extends Attachment {

View File

@ -1,6 +1,6 @@
package dev.struchkov.godfather.telegram.domain.attachment;
import dev.struchkov.godfather.context.domain.content.attachment.Attachment;
import dev.struchkov.godfather.main.domain.content.Attachment;
import dev.struchkov.haiti.utils.Parser;
import dev.struchkov.haiti.utils.domain.CompositeUrl;

View File

@ -1,6 +1,6 @@
package dev.struchkov.godfather.telegram.domain.attachment;
import dev.struchkov.godfather.context.domain.content.attachment.Attachment;
import dev.struchkov.godfather.main.domain.content.Attachment;
import java.util.Comparator;
import java.util.List;

View File

@ -1,6 +1,6 @@
package dev.struchkov.godfather.telegram.domain.event;
import dev.struchkov.godfather.context.domain.event.Event;
import dev.struchkov.godfather.main.domain.event.Event;
import java.time.LocalDateTime;

View File

@ -1,6 +1,6 @@
package dev.struchkov.godfather.telegram.domain.event;
import dev.struchkov.godfather.context.domain.event.Event;
import dev.struchkov.godfather.main.domain.event.Event;
import java.time.LocalDateTime;

View File

@ -1,14 +1,13 @@
package dev.struchkov.godfather.telegram.domain.keyboard;
import dev.struchkov.godfather.context.domain.keyboard.KeyBoard;
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton;
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine;
import dev.struchkov.godfather.context.domain.keyboard.simple.SimpleKeyBoardLine;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoard;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoardButton;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoardLine;
import java.util.ArrayList;
import java.util.List;
import static dev.struchkov.godfather.context.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
public class InlineKeyBoard implements KeyBoard {

View File

@ -1,14 +1,14 @@
package dev.struchkov.godfather.telegram.domain.keyboard;
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton;
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine;
import dev.struchkov.godfather.context.domain.keyboard.simple.SimpleKeyBoard;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoardButton;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoardLine;
import dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoard;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static dev.struchkov.godfather.context.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
public class MarkupKeyBoard extends SimpleKeyBoard {

View File

@ -1,6 +1,6 @@
package dev.struchkov.godfather.telegram.domain.keyboard.button;
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoardButton;
import org.jetbrains.annotations.NotNull;
/**

View File

@ -1,6 +1,6 @@
package dev.struchkov.godfather.telegram.domain.keyboard.button;
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoardButton;
import org.jetbrains.annotations.NotNull;
public class UrlButton implements KeyBoardButton {

View File

@ -1,6 +1,6 @@
package dev.struchkov.godfather.telegram.domain.keyboard.button;
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoardButton;
import org.jetbrains.annotations.NotNull;
public class WebAppButton implements KeyBoardButton {

View File

@ -12,9 +12,9 @@
<artifactId>telegram-sender</artifactId>
<packaging>pom</packaging>
<modules>
<module>telegram-sender-core</module>
<module>telegram-quarkus-reactive-sender</module>
<module>telegram-simple-sender</module>
<module>telegram-sender-main</module>
<module>telegram-sender-simple</module>
<module>telegram-sender-quarkus</module>
</modules>
<properties>

View File

@ -0,0 +1,31 @@
<?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">
<parent>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-sender</artifactId>
<version>0.0.30</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>telegram-sender-main</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-domain</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,10 +1,10 @@
package dev.struchkov.godfather.telegram.sender.util;
package dev.struchkov.godfather.telegram.main.sender.util;
import dev.struchkov.godfather.context.domain.keyboard.KeyBoard;
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton;
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine;
import dev.struchkov.godfather.context.domain.keyboard.button.SimpleButton;
import dev.struchkov.godfather.context.domain.keyboard.simple.SimpleKeyBoard;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoard;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoardButton;
import dev.struchkov.godfather.main.domain.keyboard.KeyBoardLine;
import dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton;
import dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoard;
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
import dev.struchkov.godfather.telegram.domain.keyboard.MarkupKeyBoard;
import dev.struchkov.godfather.telegram.domain.keyboard.button.ContactButton;

View File

@ -9,7 +9,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>telegram-quarkus-reactive-sender</artifactId>
<artifactId>telegram-sender-quarkus</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
@ -20,17 +20,11 @@
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-sender-core</artifactId>
<artifactId>telegram-context-quarkus</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-context</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-mutiny-vertx-core</artifactId>
<version>2.24.1</version>
<artifactId>telegram-sender-main</artifactId>
</dependency>
</dependencies>

View File

@ -1,9 +1,11 @@
package dev.struchkov.godfather.telegram.quarkus.sender;
import dev.struchkov.godfather.context.domain.BoxAnswer;
import dev.struchkov.godfather.telegram.context.TelegramConnect;
import dev.struchkov.godfather.main.domain.BoxAnswer;
import dev.struchkov.godfather.main.domain.SendType;
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
import dev.struchkov.godfather.telegram.sender.util.KeyBoardConvert;
import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
import dev.struchkov.godfather.telegram.main.sender.util.KeyBoardConvert;
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramSending;
import io.smallrye.mutiny.Uni;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
@ -15,11 +17,11 @@ import org.telegram.telegrambots.meta.bots.AbsSender;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import static dev.struchkov.godfather.telegram.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.Inspector.isNotNull;
public class TelegramSender {
public class TelegramSender implements TelegramSending {
private static final Logger log = LoggerFactory.getLogger(TelegramSender.class);
@ -47,10 +49,16 @@ public class TelegramSender {
this.senderStorageService = senderStorageService;
}
@Override
public Uni<Void> send(@NotNull Long telegramId, @NotNull BoxAnswer boxAnswer) {
return sendBoxAnswer(telegramId, boxAnswer, true);
}
@Override
public SendType getType() {
return SendType.PRIVATE;
}
public Uni<Void> sendNotSave(@NotNull Long telegramId, @NotNull BoxAnswer boxAnswer) {
return sendBoxAnswer(telegramId, boxAnswer, false);
}

View File

@ -0,0 +1,31 @@
<?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">
<parent>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-sender</artifactId>
<version>0.0.30</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>telegram-sender-simple</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-sender-main</artifactId>
</dependency>
<dependency>
<groupId>dev.struchkov.godfather.telegram</groupId>
<artifactId>telegram-context-simple</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,4 +1,4 @@
package dev.struchkov.godfather.telegram.sender.service;
package dev.struchkov.godfather.telegram.simple.sender;
/**
* // TODO: 18.09.2020 Добавить описание.

View File

@ -1,12 +1,12 @@
package dev.struchkov.godfather.telegram.sender.service;
package dev.struchkov.godfather.telegram.simple.sender;
import dev.struchkov.godfather.context.domain.BoxAnswer;
import dev.struchkov.godfather.context.service.sender.SendType;
import dev.struchkov.godfather.telegram.context.SenderStorageService;
import dev.struchkov.godfather.telegram.context.TelegramConnect;
import dev.struchkov.godfather.telegram.context.TelegramSending;
import dev.struchkov.godfather.main.domain.BoxAnswer;
import dev.struchkov.godfather.main.domain.SendType;
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
import dev.struchkov.godfather.telegram.sender.util.KeyBoardConvert;
import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
import dev.struchkov.godfather.telegram.main.sender.util.KeyBoardConvert;
import dev.struchkov.godfather.telegram.simple.context.service.SenderStorageService;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -50,6 +50,7 @@ public class TelegramSender implements TelegramSending {
this.senderStorageService = senderStorageService;
}
@Override
public void send(@NotNull Long telegramId, @NotNull BoxAnswer boxAnswer) {
sendBoxAnswer(telegramId, boxAnswer, true);
}
@ -115,6 +116,7 @@ public class TelegramSender implements TelegramSending {
}
@Override
public SendType getType() {
return SendType.PRIVATE;
}