Compare commits

...

2 Commits

Author SHA1 Message Date
e960c273a0
Поправил заполнение SentBox при replace
All checks were successful
continuous-integration/drone/push Build is passing
2023-04-01 21:46:15 +03:00
ee2024d37f
Добавляю логирование 2023-03-30 22:32:53 +03:00
6 changed files with 34 additions and 39 deletions

View File

@ -8,7 +8,7 @@ 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);
public static final ContextKey<Boolean> ENABLE_MARKDOWN = ContextKey.of("DISABLE_MARKDOWN", Boolean.class);
public static final ContextKey<Boolean> ENABLE_MARKDOWN = ContextKey.of("ENABLE_MARKDOWN", Boolean.class);
public static final ContextKey<SendInvoice> INVOICE = ContextKey.of("INVOICE", SendInvoice.class);
private BoxAnswerPayload() {

View File

@ -17,11 +17,6 @@ import java.net.PasswordAuthentication;
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
/**
* TODO: Добавить описание класса.
*
* @author upagge [30.01.2020]
*/
@Slf4j
public class TelegramPollingConnect implements TelegramConnect {
@ -32,6 +27,7 @@ public class TelegramPollingConnect implements TelegramConnect {
}
private void initLongPolling(TelegramBotConfig telegramBotConfig) {
log.info("Initializing Telegram Long Polling...");
final ProxyConfig proxyConfig = telegramBotConfig.getProxyConfig();
if (checkNotNull(proxyConfig) && proxyConfig.isEnable() && checkNotNull(proxyConfig.getPassword()) && !"".equals(proxyConfig.getPassword())) {
try {
@ -45,8 +41,9 @@ public class TelegramPollingConnect implements TelegramConnect {
}
});
} catch (Exception e) {
e.printStackTrace();
log.error("Error setting default authenticator for telegram proxy", e);
}
log.info("Telegram proxy with authentication enabled");
}
final TelegramBotsApi botapi;
@ -54,26 +51,29 @@ public class TelegramPollingConnect implements TelegramConnect {
if (checkNotNull(proxyConfig) && proxyConfig.isEnable() && checkNotNull(proxyConfig.getHost()) && !"".equals(proxyConfig.getHost())) {
System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
// System.setProperty("javax.net.debug", "all");
log.info(System.getProperty("https.protocols"));
// log.info(System.getProperty("https.protocols"));
DefaultBotOptions botOptions = new DefaultBotOptions();
botOptions.setProxyHost(proxyConfig.getHost());
botOptions.setProxyPort(proxyConfig.getPort());
botOptions.setProxyType(convertProxyType(proxyConfig.getType()));
log.info("Telegram proxy configuration set for bot");
final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig, botOptions);
botapi = new TelegramBotsApi(DefaultBotSession.class);
botapi.registerBot(bot);
this.pollingBot = bot;
log.info("Telegram Bot registered with proxy settings");
} else {
final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig);
botapi = new TelegramBotsApi(DefaultBotSession.class);
botapi.registerBot(bot);
this.pollingBot = bot;
log.info("Telegram Bot registered without proxy settings");
}
} catch (TelegramApiException e) {
log.error(e.getMessage());
log.error("Error registering telegram bot", e);
}
}

View File

@ -15,6 +15,7 @@ public class TelegramWebhookConnect implements TelegramConnect {
private TelegramWebhookBot webhookBot;
public TelegramWebhookConnect(TelegramBotConfig telegramBotConfig) {
log.info("Initializing Webhook Polling...");
try {
final TelegramWebhookBot bot = new TelegramWebhookBot(telegramBotConfig);
final WebhookConfig webhookConfig = telegramBotConfig.getWebhookConfig();

View File

@ -11,11 +11,6 @@ import org.telegram.telegrambots.meta.bots.AbsSender;
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
/**
* TODO: Добавить описание класса.
*
* @author upagge [15/07/2019]
*/
public class TelegramPollingBot extends TelegramLongPollingBot implements TelegramBot {
private final TelegramBotConfig telegramBotConfig;

View File

@ -4,10 +4,8 @@ import dev.struchkov.godfather.telegram.domain.config.ProxyConfig;
import dev.struchkov.godfather.telegram.domain.config.ProxyConfig.Type;
import dev.struchkov.godfather.telegram.domain.config.TelegramBotConfig;
import dev.struchkov.godfather.telegram.simple.context.service.EventDistributor;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramBot;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramConnect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.telegram.telegrambots.bots.DefaultBotOptions;
import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.bots.AbsSender;
@ -19,26 +17,19 @@ import java.net.PasswordAuthentication;
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
/**
* TODO: Добавить описание класса.
*
* @author upagge [30.01.2020]
*/
@Slf4j
public class TelegramPollingConnect implements TelegramConnect {
private static final Logger log = LoggerFactory.getLogger(TelegramPollingConnect.class);
private TelegramBot telegramBot;
private final TelegramBotConfig telegramBotConfig;
private TelegramPollingBot pollingBot;
public TelegramPollingConnect(TelegramBotConfig telegramBotConfig) {
this.telegramBotConfig = telegramBotConfig;
initLongPolling(telegramBotConfig);
}
private void initLongPolling(TelegramBotConfig telegramBotConfig) {
log.info("Initializing Telegram Long Polling...");
final ProxyConfig proxyConfig = telegramBotConfig.getProxyConfig();
if (checkNotNull(proxyConfig) && checkNotNull(proxyConfig.getPassword()) && !"".equals(proxyConfig.getPassword())) {
if (checkNotNull(proxyConfig) && proxyConfig.isEnable() && checkNotNull(proxyConfig.getPassword()) && !"".equals(proxyConfig.getPassword())) {
try {
Authenticator.setDefault(new Authenticator() {
@Override
@ -50,8 +41,9 @@ public class TelegramPollingConnect implements TelegramConnect {
}
});
} catch (Exception e) {
e.printStackTrace();
log.error("Error setting default authenticator for telegram proxy", e);
}
log.info("Telegram proxy with authentication enabled");
}
final TelegramBotsApi botapi;
@ -59,25 +51,29 @@ public class TelegramPollingConnect implements TelegramConnect {
if (checkNotNull(proxyConfig) && proxyConfig.isEnable() && checkNotNull(proxyConfig.getHost()) && !"".equals(proxyConfig.getHost())) {
System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
// System.setProperty("javax.net.debug", "all");
log.info(System.getProperty("https.protocols"));
// log.info(System.getProperty("https.protocols"));
DefaultBotOptions botOptions = new DefaultBotOptions();
botOptions.setProxyHost(proxyConfig.getHost());
botOptions.setProxyPort(proxyConfig.getPort());
botOptions.setProxyType(convertProxyType(proxyConfig.getType()));
log.info("Telegram proxy configuration set for bot");
final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig, botOptions);
botapi = new TelegramBotsApi(DefaultBotSession.class);
botapi.registerBot(bot);
this.telegramBot = bot;
this.pollingBot = bot;
log.info("Telegram Bot registered with proxy settings");
} else {
final TelegramPollingBot bot = new TelegramPollingBot(telegramBotConfig);
botapi = new TelegramBotsApi(DefaultBotSession.class);
botapi.registerBot(bot);
this.telegramBot = bot;
this.pollingBot = bot;
log.info("Telegram Bot registered without proxy settings");
}
} catch (TelegramApiException e) {
log.error(e.getMessage());
log.error("Error registering telegram bot", e);
}
}
@ -89,17 +85,19 @@ public class TelegramPollingConnect implements TelegramConnect {
};
}
public void initEventDistributor(EventDistributor eventDistributor) {
telegramBot.initEventDistributor(eventDistributor);
@Override
public String getToken() {
return pollingBot.getBotToken();
}
public String getToken() {
return telegramBotConfig.getToken();
@Override
public void initEventDistributor(EventDistributor eventDistributorService) {
pollingBot.initEventDistributor(eventDistributorService);
}
@Override
public AbsSender getAbsSender() {
return telegramBot.getAdsSender();
return pollingBot.getAdsSender();
}
}

View File

@ -182,9 +182,10 @@ public class TelegramSender implements TelegramSending {
return Uni.createFrom().completionStage(executeAsync(editMessageText))
.onItem().ifNotNull().transform(t -> {
final SentBox sentBox = new SentBox();
sentBox.setPersonId(telegramId);
sentBox.setMessageId(lastMessageId);
sentBox.setSentAnswer(boxAnswer);
sentBox.setOriginalAnswer(boxAnswer);
sentBox.setMessageId(telegramId);
return sentBox;
})
.onFailure(TelegramApiRequestException.class).recoverWithUni(