v.0.0.9
This commit is contained in:
parent
06d1262c8b
commit
dc7f1cf767
2
pom.xml
2
pom.xml
@ -33,7 +33,7 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
|
||||||
<godfather.core.ver>0.0.6</godfather.core.ver>
|
<godfather.core.ver>0.0.7</godfather.core.ver>
|
||||||
<telegrambots.ver>6.0.1</telegrambots.ver>
|
<telegrambots.ver>6.0.1</telegrambots.ver>
|
||||||
|
|
||||||
<plugin.maven.compiler.ver>3.10.1</plugin.maven.compiler.ver>
|
<plugin.maven.compiler.ver>3.10.1</plugin.maven.compiler.ver>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package dev.struchkov.godfather.telegram;
|
package dev.struchkov.godfather.telegram;
|
||||||
|
|
||||||
import dev.struchkov.godfather.telegram.listen.EventDistributorImpl;
|
import dev.struchkov.godfather.telegram.listen.EventDistributorService;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.telegram.telegrambots.meta.bots.AbsSender;
|
import org.telegram.telegrambots.meta.bots.AbsSender;
|
||||||
|
|
||||||
@ -13,6 +13,6 @@ public interface TelegramBot {
|
|||||||
|
|
||||||
AbsSender getAdsSender();
|
AbsSender getAdsSender();
|
||||||
|
|
||||||
void initEventDistributor(@NotNull EventDistributorImpl eventDistributor);
|
void initEventDistributor(@NotNull EventDistributorService eventDistributor);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,13 @@ package dev.struchkov.godfather.telegram;
|
|||||||
|
|
||||||
import dev.struchkov.godfather.telegram.config.TelegramPollingConfig;
|
import dev.struchkov.godfather.telegram.config.TelegramPollingConfig;
|
||||||
import dev.struchkov.godfather.telegram.listen.EventDistributor;
|
import dev.struchkov.godfather.telegram.listen.EventDistributor;
|
||||||
import dev.struchkov.godfather.telegram.listen.EventDistributorImpl;
|
import dev.struchkov.godfather.telegram.listen.EventDistributorService;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.telegram.telegrambots.bots.DefaultBotOptions;
|
import org.telegram.telegrambots.bots.DefaultBotOptions;
|
||||||
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
|
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
|
||||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||||
import org.telegram.telegrambots.meta.bots.AbsSender;
|
import org.telegram.telegrambots.meta.bots.AbsSender;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Добавить описание класса.
|
* TODO: Добавить описание класса.
|
||||||
*
|
*
|
||||||
@ -32,8 +30,8 @@ public class TelegramPollingBot extends TelegramLongPollingBot implements Telegr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdateReceived(Update update) {
|
public void onUpdateReceived(Update update) {
|
||||||
if (eventDistributor != null) {
|
if (update != null && eventDistributor != null) {
|
||||||
Optional.ofNullable(update).ifPresent(newUpdate -> eventDistributor.processing(update));
|
eventDistributor.processing(update);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +51,7 @@ public class TelegramPollingBot extends TelegramLongPollingBot implements Telegr
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initEventDistributor(@NotNull EventDistributorImpl eventDistributor) {
|
public void initEventDistributor(@NotNull EventDistributorService eventDistributor) {
|
||||||
this.eventDistributor = eventDistributor;
|
this.eventDistributor = eventDistributor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
package dev.struchkov.godfather.telegram.autoresponder;
|
package dev.struchkov.godfather.telegram.autoresponder;
|
||||||
|
|
||||||
import dev.struchkov.autoresponder.repository.UnitPointerRepository;
|
|
||||||
import dev.struchkov.godfather.context.domain.content.Mail;
|
import dev.struchkov.godfather.context.domain.content.Mail;
|
||||||
import dev.struchkov.godfather.context.service.MessageService;
|
import dev.struchkov.godfather.context.service.PersonSettingService;
|
||||||
|
import dev.struchkov.godfather.context.service.UnitPointerService;
|
||||||
import dev.struchkov.godfather.context.service.sender.Sending;
|
import dev.struchkov.godfather.context.service.sender.Sending;
|
||||||
import dev.struchkov.godfather.core.GeneralAutoResponder;
|
import dev.struchkov.godfather.core.GeneralAutoResponder;
|
||||||
import dev.struchkov.godfather.core.domain.unit.MainUnit;
|
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Добавить описание класса.
|
* TODO: Добавить описание класса.
|
||||||
@ -17,11 +16,12 @@ import java.util.Set;
|
|||||||
public class MessageAutoresponderTelegram extends GeneralAutoResponder<Mail> {
|
public class MessageAutoresponderTelegram extends GeneralAutoResponder<Mail> {
|
||||||
|
|
||||||
public MessageAutoresponderTelegram(
|
public MessageAutoresponderTelegram(
|
||||||
Set<MainUnit> menuUnit, Sending sending,
|
Sending sending,
|
||||||
MessageService<Mail> messageService,
|
PersonSettingService personSettingService,
|
||||||
UnitPointerRepository<MainUnit> unitPointerRepository
|
UnitPointerService unitPointerService,
|
||||||
|
List<Object> unitConfigurations
|
||||||
) {
|
) {
|
||||||
super(menuUnit, sending, messageService, unitPointerRepository);
|
super(sending, personSettingService, unitPointerService, unitConfigurations);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
package dev.struchkov.godfather.telegram.domain.keyboard;
|
package dev.struchkov.godfather.telegram.domain.keyboard;
|
||||||
|
|
||||||
|
import dev.struchkov.godfather.context.domain.keyboard.KeyBoard;
|
||||||
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine;
|
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine;
|
||||||
import dev.struchkov.godfather.context.domain.keyboard.simple.SimpleKeyBoard;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class InlineKeyBoard extends SimpleKeyBoard {
|
public class InlineKeyBoard implements KeyBoard {
|
||||||
|
|
||||||
public static final String TYPE = "INLINE";
|
public static final String TYPE = "INLINE";
|
||||||
|
protected List<KeyBoardLine> lines = new ArrayList<>();
|
||||||
|
|
||||||
public InlineKeyBoard(List<KeyBoardLine> lines) {
|
public InlineKeyBoard(List<KeyBoardLine> lines) {
|
||||||
super(lines);
|
this.lines = lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InlineKeyBoard(Builder builder) {
|
private InlineKeyBoard(Builder builder) {
|
||||||
super(builder.lines);
|
this.lines = builder.lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
@ -26,7 +27,10 @@ public class InlineKeyBoard extends SimpleKeyBoard {
|
|||||||
return builder().line(keyBoardLine).build();
|
return builder().line(keyBoardLine).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public List<KeyBoardLine> getLines() {
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return TYPE;
|
return TYPE;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ public class ButtonUrl implements KeyBoardButton {
|
|||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ButtonUrl link(String label, String url) {
|
public static ButtonUrl buttonUrl(String label, String url) {
|
||||||
return new ButtonUrl(label, url);
|
return new ButtonUrl(label, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
package dev.struchkov.godfather.telegram.domain.keyboard.button;
|
||||||
|
|
||||||
|
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton;
|
||||||
|
|
||||||
|
public class ButtonWebApp implements KeyBoardButton {
|
||||||
|
|
||||||
|
public static final String TYPE = "WEB_APP";
|
||||||
|
|
||||||
|
private final String label;
|
||||||
|
private final String url;
|
||||||
|
|
||||||
|
public ButtonWebApp(String label, String url) {
|
||||||
|
this.label = label;
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ButtonWebApp buttonWebApp(String label, String url) {
|
||||||
|
return new ButtonWebApp(label, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package dev.struchkov.godfather.telegram.listen;
|
package dev.struchkov.godfather.telegram.listen;
|
||||||
|
|
||||||
import dev.struchkov.godfather.context.service.MailService;
|
import dev.struchkov.godfather.context.domain.content.Mail;
|
||||||
|
import dev.struchkov.godfather.context.service.EventProvider;
|
||||||
import dev.struchkov.godfather.telegram.convert.CallbackQueryConvert;
|
import dev.struchkov.godfather.telegram.convert.CallbackQueryConvert;
|
||||||
import dev.struchkov.godfather.telegram.convert.MessageMailConvert;
|
import dev.struchkov.godfather.telegram.convert.MessageMailConvert;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -8,17 +9,19 @@ import org.telegram.telegrambots.meta.api.objects.CallbackQuery;
|
|||||||
import org.telegram.telegrambots.meta.api.objects.Message;
|
import org.telegram.telegrambots.meta.api.objects.Message;
|
||||||
import org.telegram.telegrambots.meta.api.objects.Update;
|
import org.telegram.telegrambots.meta.api.objects.Update;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Добавить описание класса.
|
* TODO: Добавить описание класса.
|
||||||
*
|
*
|
||||||
* @author upagge [30.01.2020]
|
* @author upagge [30.01.2020]
|
||||||
*/
|
*/
|
||||||
public class EventDistributorImpl implements EventDistributor {
|
public class EventDistributorService implements EventDistributor {
|
||||||
|
|
||||||
private final MailService mailService;
|
private final List<EventProvider<Mail>> eventProviders;
|
||||||
|
|
||||||
public EventDistributorImpl(TelegramConnect telegramConnect, MailService mailService) {
|
public EventDistributorService(TelegramConnect telegramConnect, List<EventProvider<Mail>> eventProviders) {
|
||||||
this.mailService = mailService;
|
this.eventProviders = eventProviders;
|
||||||
telegramConnect.initEventDistributor(this);
|
telegramConnect.initEventDistributor(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,10 +30,10 @@ public class EventDistributorImpl implements EventDistributor {
|
|||||||
final Message message = update.getMessage();
|
final Message message = update.getMessage();
|
||||||
final CallbackQuery callbackQuery = update.getCallbackQuery();
|
final CallbackQuery callbackQuery = update.getCallbackQuery();
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
mailService.add(MessageMailConvert.apply(message));
|
eventProviders.forEach(provider -> provider.sendEvent(MessageMailConvert.apply(message)));
|
||||||
}
|
}
|
||||||
if (callbackQuery != null) {
|
if (callbackQuery != null) {
|
||||||
mailService.add(CallbackQueryConvert.apply(callbackQuery));
|
eventProviders.forEach(provider -> provider.sendEvent(CallbackQueryConvert.apply(callbackQuery)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +109,7 @@ public class TelegramConnect {
|
|||||||
return telegramBot.getAdsSender();
|
return telegramBot.getAdsSender();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initEventDistributor(EventDistributorImpl eventDistributor) {
|
void initEventDistributor(EventDistributorService eventDistributor) {
|
||||||
telegramBot.initEventDistributor(eventDistributor);
|
telegramBot.initEventDistributor(eventDistributor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import dev.struchkov.godfather.context.service.sender.Sending;
|
|||||||
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
|
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
|
||||||
import dev.struchkov.godfather.telegram.domain.keyboard.MarkupKeyBoard;
|
import dev.struchkov.godfather.telegram.domain.keyboard.MarkupKeyBoard;
|
||||||
import dev.struchkov.godfather.telegram.domain.keyboard.button.ButtonUrl;
|
import dev.struchkov.godfather.telegram.domain.keyboard.button.ButtonUrl;
|
||||||
|
import dev.struchkov.godfather.telegram.domain.keyboard.button.ButtonWebApp;
|
||||||
import dev.struchkov.godfather.telegram.service.SendPreProcessing;
|
import dev.struchkov.godfather.telegram.service.SendPreProcessing;
|
||||||
import dev.struchkov.haiti.context.exception.ConvertException;
|
import dev.struchkov.haiti.context.exception.ConvertException;
|
||||||
import dev.struchkov.haiti.utils.Inspector;
|
import dev.struchkov.haiti.utils.Inspector;
|
||||||
@ -26,6 +27,7 @@ import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardMar
|
|||||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
|
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
|
||||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardButton;
|
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardButton;
|
||||||
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardRow;
|
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardRow;
|
||||||
|
import org.telegram.telegrambots.meta.api.objects.webapp.WebAppInfo;
|
||||||
import org.telegram.telegrambots.meta.bots.AbsSender;
|
import org.telegram.telegrambots.meta.bots.AbsSender;
|
||||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
|
||||||
@ -186,6 +188,12 @@ public class TelegramSender implements Sending {
|
|||||||
button.setUrl(buttonUrl.getUrl());
|
button.setUrl(buttonUrl.getUrl());
|
||||||
button.setText(buttonUrl.getLabel());
|
button.setText(buttonUrl.getLabel());
|
||||||
}
|
}
|
||||||
|
case ButtonWebApp.TYPE -> {
|
||||||
|
final ButtonWebApp buttonWebApp = (ButtonWebApp) keyBoardButton;
|
||||||
|
final WebAppInfo webAppInfo = WebAppInfo.builder().url(buttonWebApp.getUrl()).build();
|
||||||
|
button.setWebApp(webAppInfo);
|
||||||
|
button.setText(buttonWebApp.getLabel());
|
||||||
|
}
|
||||||
default -> throw new ConvertException("Ошибка преобразования кнопки");
|
default -> throw new ConvertException("Ошибка преобразования кнопки");
|
||||||
}
|
}
|
||||||
return button;
|
return button;
|
||||||
@ -199,15 +207,17 @@ public class TelegramSender implements Sending {
|
|||||||
button.setText(simpleButton.getLabel());
|
button.setText(simpleButton.getLabel());
|
||||||
Inspector.isNull(simpleButton.getCallbackData(), ConvertException.supplier("CallbackData поддерживает только Inline клавитаура"));
|
Inspector.isNull(simpleButton.getCallbackData(), ConvertException.supplier("CallbackData поддерживает только Inline клавитаура"));
|
||||||
}
|
}
|
||||||
|
case ButtonWebApp.TYPE -> {
|
||||||
|
final ButtonWebApp buttonWebApp = (ButtonWebApp) keyBoardButton;
|
||||||
|
final WebAppInfo webAppInfo = WebAppInfo.builder().url(buttonWebApp.getUrl()).build();
|
||||||
|
button.setText(buttonWebApp.getLabel());
|
||||||
|
button.setWebApp(webAppInfo);
|
||||||
|
}
|
||||||
default -> throw new ConvertException("Ошибка преобразования кнопки");
|
default -> throw new ConvertException("Ошибка преобразования кнопки");
|
||||||
}
|
}
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(Long integer, Long integer1, BoxAnswer boxAnswer) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public SendType getType() {
|
public SendType getType() {
|
||||||
return SendType.PRIVATE;
|
return SendType.PRIVATE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user