Добавляю логирование
This commit is contained in:
parent
f916f7aa09
commit
ee2024d37f
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user