Compare commits
2 Commits
56a4d4957b
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| a06f9940ff | |||
| 8453ba42f8 |
@@ -0,0 +1,20 @@
|
|||||||
|
package ru.penkrat.stbf.common.command;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import ru.penkrat.stbf.api.BotRequest;
|
||||||
|
import ru.penkrat.stbf.api.BotResponse;
|
||||||
|
import ru.penkrat.stbf.api.CommandChain;
|
||||||
|
import ru.penkrat.stbf.api.SessionProvider;
|
||||||
|
import ru.penkrat.stbf.common.session.SessionAwareBotRequest;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SessionAwareCommandChain implements CommandChain {
|
||||||
|
|
||||||
|
private final CommandChain delegate;
|
||||||
|
private final SessionProvider sessionProvider;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processCommand(BotRequest botRequest, BotResponse botResponse) {
|
||||||
|
delegate.processCommand(new SessionAwareBotRequest(botRequest, sessionProvider), botResponse);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package ru.penkrat.stbf.common.command;
|
||||||
|
|
||||||
|
import ru.penkrat.stbf.api.BotRequest;
|
||||||
|
import ru.penkrat.stbf.api.BotResponse;
|
||||||
|
import ru.penkrat.stbf.api.CommandChain;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
public class ThreadPolledCommandChain implements CommandChain {
|
||||||
|
|
||||||
|
private final CommandChain delegate;
|
||||||
|
private final ExecutorService executor;
|
||||||
|
|
||||||
|
public ThreadPolledCommandChain(CommandChain delegate) {
|
||||||
|
this(delegate, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ThreadPolledCommandChain(CommandChain delegate, int nThreads) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
this.executor = Executors.newFixedThreadPool(nThreads);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processCommand(BotRequest botRequest, BotResponse botResponse) {
|
||||||
|
executor.execute(() -> {
|
||||||
|
delegate.processCommand(botRequest, botResponse);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package ru.penkrat.stbf.common.session;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import ru.penkrat.stbf.api.BotRequest;
|
||||||
|
import ru.penkrat.stbf.api.BotSession;
|
||||||
|
import ru.penkrat.stbf.api.SessionProvider;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SessionAwareBotRequest implements BotRequest {
|
||||||
|
|
||||||
|
private final BotRequest delegate;
|
||||||
|
|
||||||
|
private final SessionProvider sessionProvider;
|
||||||
|
|
||||||
|
private BotSession botSession;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BotSession getSession() {
|
||||||
|
if (botSession == null) {
|
||||||
|
botSession = sessionProvider.get(getChatId());
|
||||||
|
Objects.requireNonNull(botSession, "Session can not be null");
|
||||||
|
}
|
||||||
|
return botSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<String> getMessageText() {
|
||||||
|
return this.delegate.getMessageText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<String> getPhoneNumber() {
|
||||||
|
return this.delegate.getPhoneNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<String> getCallbackData() {
|
||||||
|
return this.delegate.getCallbackData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<String> getCallbackMessageText() {
|
||||||
|
return this.delegate.getCallbackMessageText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getChatId() {
|
||||||
|
return this.delegate.getChatId();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,6 +5,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
import ru.penkrat.stbf.api.BotCommandChain;
|
import ru.penkrat.stbf.api.BotCommandChain;
|
||||||
import ru.penkrat.stbf.api.CommandChain;
|
import ru.penkrat.stbf.api.CommandChain;
|
||||||
|
import ru.penkrat.stbf.common.command.SessionAwareCommandChain;
|
||||||
|
import ru.penkrat.stbf.common.command.ThreadPolledCommandChain;
|
||||||
import ru.penkrat.stbf.common.session.InMemBotSessionProvider;
|
import ru.penkrat.stbf.common.session.InMemBotSessionProvider;
|
||||||
import ru.penkrat.stbf.impl.pengrad.PengradTelegramBot;
|
import ru.penkrat.stbf.impl.pengrad.PengradTelegramBot;
|
||||||
import ru.penkrat.stbf.templates.xml.XmlFlowResolver;
|
import ru.penkrat.stbf.templates.xml.XmlFlowResolver;
|
||||||
@@ -12,58 +14,58 @@ import ru.penkrat.stbf.templates.xml.XmlFlowResolver;
|
|||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
@CommandLine.Command(name = "java -jar stbf-demo.jar", mixinStandardHelpOptions = true, description = "Run bot",
|
@CommandLine.Command(name = "java -jar stbf-demo.jar", mixinStandardHelpOptions = true, description = "Run bot",
|
||||||
version = "Simple Telegram bot framework Demo app v. 0.0.1")
|
version = "Simple Telegram bot framework Demo app v. 0.0.2")
|
||||||
public class App implements Runnable {
|
public class App implements Runnable {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(App.class);
|
private static final Logger log = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
private static AtomicReference<PengradTelegramBot> botAtomicReference = new AtomicReference<>();
|
private static AtomicReference<PengradTelegramBot> botAtomicReference = new AtomicReference<>();
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-f", "--file"}, description = "The file with config.")
|
@CommandLine.Option(names = {"-f", "--file"}, description = "The file with config.")
|
||||||
private String flowFile = "classpath:/flow.xml";
|
private String flowFile = "classpath:/flow.xml";
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-t", "--token"}, required = true, description = "bot token 1234:abscdf...")
|
@CommandLine.Option(names = {"-t", "--token"}, required = true, description = "bot token 1234:abscdf...")
|
||||||
private String botToken = "";
|
private String botToken = "";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new CommandLine(new App()).execute(args);
|
new CommandLine(new App()).execute(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BotCommandChain getCommandChain(String filename) {
|
private CommandChain getCommandChain(String filename) {
|
||||||
XmlFlowResolver flow = new XmlFlowResolver(filename);
|
XmlFlowResolver flow = new XmlFlowResolver(filename);
|
||||||
|
|
||||||
BotCommandChain chain = new BotCommandChain();
|
BotCommandChain chain = new BotCommandChain();
|
||||||
flow.getCommands().forEach(chain::add);
|
flow.getCommands().forEach(chain::add);
|
||||||
|
|
||||||
return chain;
|
return new ThreadPolledCommandChain(new SessionAwareCommandChain(chain, new InMemBotSessionProvider()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Runnable start(String token, CommandChain chain) {
|
private Runnable start(String token, CommandChain chain) {
|
||||||
return () -> botAtomicReference.set(new PengradTelegramBot(token, chain, new InMemBotSessionProvider()));
|
return () -> botAtomicReference.set(new PengradTelegramBot(token, chain));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onShutdown() {
|
private void onShutdown() {
|
||||||
try {
|
try {
|
||||||
if (botAtomicReference.get() != null) {
|
if (botAtomicReference.get() != null) {
|
||||||
botAtomicReference.get().close();
|
botAtomicReference.get().close();
|
||||||
log.info("Bot finished.");
|
log.info("Bot finished.");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error:", e);
|
log.error("Error:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Thread botThread = new Thread(start(botToken, getCommandChain(flowFile)));
|
Thread botThread = new Thread(start(botToken, getCommandChain(flowFile)));
|
||||||
botThread.setDaemon(false);
|
botThread.setDaemon(false);
|
||||||
botThread.setName("stbf-bot-thread");
|
botThread.setName("stbf-bot-thread");
|
||||||
|
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(this::onShutdown));
|
Runtime.getRuntime().addShutdownHook(new Thread(this::onShutdown));
|
||||||
|
|
||||||
log.info("Starting bot...");
|
log.info("Starting bot...");
|
||||||
botThread.start();
|
botThread.start();
|
||||||
log.info("Bot started.");
|
log.info("Bot started.");
|
||||||
log.info("Press Ctrl+C to exit.");
|
log.info("Press Ctrl+C to exit.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.pengrad</groupId>
|
<groupId>com.github.pengrad</groupId>
|
||||||
<artifactId>java-telegram-bot-api</artifactId>
|
<artifactId>java-telegram-bot-api</artifactId>
|
||||||
<version>[4.9.0,5.2.0]</version>
|
<version>6.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@@ -16,49 +16,51 @@ import static lombok.AccessLevel.PROTECTED;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class BotRequestImpl implements BotRequest {
|
public class BotRequestImpl implements BotRequest {
|
||||||
|
|
||||||
@Getter(PROTECTED)
|
@Getter(PROTECTED)
|
||||||
private final Update update;
|
private final Update update;
|
||||||
|
|
||||||
@Getter
|
@Override
|
||||||
private final BotSession session;
|
public Optional<String> getMessageText() {
|
||||||
|
if (update.message() != null) {
|
||||||
|
return Optional.ofNullable(update.message().text());
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getMessageText() {
|
public Optional<String> getPhoneNumber() {
|
||||||
if (update.message() != null) {
|
return Optional.of(update)
|
||||||
return Optional.ofNullable(update.message().text());
|
.map(Update::message)
|
||||||
}
|
.map(Message::contact)
|
||||||
return Optional.empty();
|
.map(Contact::phoneNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getPhoneNumber() {
|
public Optional<String> getCallbackData() {
|
||||||
return Optional.of(update)
|
return Optional.of(update)
|
||||||
.map(Update::message)
|
.map(Update::callbackQuery)
|
||||||
.map(Message::contact)
|
.map(CallbackQuery::data);
|
||||||
.map(Contact::phoneNumber);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getCallbackData() {
|
public Optional<String> getCallbackMessageText() {
|
||||||
return Optional.of(update)
|
return Optional.of(update)
|
||||||
.map(Update::callbackQuery)
|
.map(Update::callbackQuery)
|
||||||
.map(CallbackQuery::data);
|
.map(CallbackQuery::message)
|
||||||
}
|
.map(Message::text);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getCallbackMessageText() {
|
public Long getChatId() {
|
||||||
return Optional.of(update)
|
return Optional.of(update)
|
||||||
.map(Update::callbackQuery)
|
.map(Update::callbackQuery)
|
||||||
.map(CallbackQuery::message)
|
.map(CallbackQuery::message)
|
||||||
.map(Message::text);
|
.orElseGet(() -> update.message()).chat().id();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getChatId() {
|
public BotSession getSession() {
|
||||||
return Optional.of(update)
|
throw new UnsupportedOperationException("Session is not supported");
|
||||||
.map(Update::callbackQuery)
|
}
|
||||||
.map(CallbackQuery::message)
|
|
||||||
.orElseGet(() -> update.message()).chat().id();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package ru.penkrat.stbf.impl.pengrad;
|
package ru.penkrat.stbf.impl.pengrad;
|
||||||
|
|
||||||
import com.google.gson.internal.reflect.ReflectionAccessor;
|
import com.google.gson.internal.reflect.ReflectionHelper;
|
||||||
import com.pengrad.telegrambot.model.request.InlineKeyboardButton;
|
import com.pengrad.telegrambot.model.request.InlineKeyboardButton;
|
||||||
import com.pengrad.telegrambot.model.request.KeyboardButton;
|
import com.pengrad.telegrambot.model.request.KeyboardButton;
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
@@ -58,7 +58,7 @@ class KeyboardImpl implements Keyboard {
|
|||||||
return text.computeIfAbsent(btn, o -> {
|
return text.computeIfAbsent(btn, o -> {
|
||||||
try {
|
try {
|
||||||
Field text = btn.getClass().getDeclaredField("text");
|
Field text = btn.getClass().getDeclaredField("text");
|
||||||
ReflectionAccessor.getInstance().makeAccessible(text);
|
ReflectionHelper.makeAccessible(text);
|
||||||
return String.valueOf(text.get(btn));
|
return String.valueOf(text.get(btn));
|
||||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||||
return "*error*";
|
return "*error*";
|
||||||
|
|||||||
@@ -6,46 +6,39 @@ import com.pengrad.telegrambot.model.CallbackQuery;
|
|||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import ru.penkrat.stbf.api.CommandChain;
|
import ru.penkrat.stbf.api.CommandChain;
|
||||||
import ru.penkrat.stbf.api.SessionProvider;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class PengradTelegramBot extends TelegramBot implements AutoCloseable {
|
public class PengradTelegramBot extends TelegramBot implements AutoCloseable {
|
||||||
|
|
||||||
public PengradTelegramBot(String botToken, CommandChain commandChain) {
|
public PengradTelegramBot(String botToken, CommandChain commandChain) {
|
||||||
this(botToken, commandChain, (id) -> {
|
super(botToken);
|
||||||
throw new IllegalArgumentException("'SessionProvider' is not defined");
|
this.setUpdatesListener(updates -> {
|
||||||
});
|
for (Update update : updates) {
|
||||||
}
|
try {
|
||||||
|
final Long chatId = Optional.of(update)
|
||||||
|
.map(Update::callbackQuery)
|
||||||
|
.map(CallbackQuery::message)
|
||||||
|
.orElseGet(() -> update.message()).chat().id();
|
||||||
|
|
||||||
public PengradTelegramBot(String botToken, CommandChain commandChain, SessionProvider sessionProvider) {
|
log.debug("New message in chat {}", chatId);
|
||||||
super(botToken);
|
|
||||||
this.setUpdatesListener(updates -> {
|
|
||||||
for (Update update : updates) {
|
|
||||||
try {
|
|
||||||
final Long chatId = Optional.of(update)
|
|
||||||
.map(Update::callbackQuery)
|
|
||||||
.map(CallbackQuery::message)
|
|
||||||
.orElseGet(() -> update.message()).chat().id();
|
|
||||||
|
|
||||||
log.debug("New message in chat {}", chatId);
|
commandChain.processCommand(
|
||||||
|
new BotRequestImpl(update),
|
||||||
|
new BotResponseImpl(update, this));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Bot Error:", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return UpdatesListener.CONFIRMED_UPDATES_ALL;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
commandChain.processCommand(
|
@Override
|
||||||
new BotRequestImpl(update, sessionProvider.get(chatId)),
|
public void close() throws Exception {
|
||||||
new BotResponseImpl(update, this));
|
removeGetUpdatesListener();
|
||||||
} catch (Exception e) {
|
log.debug("Bot closed.");
|
||||||
log.error("Bot Error:", e);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return UpdatesListener.CONFIRMED_UPDATES_ALL;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws Exception {
|
|
||||||
removeGetUpdatesListener();
|
|
||||||
log.debug("Bot closed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,46 +16,48 @@ import static lombok.AccessLevel.PROTECTED;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
class BotRequestImpl implements BotRequest {
|
class BotRequestImpl implements BotRequest {
|
||||||
|
|
||||||
@Getter(PROTECTED)
|
@Getter(PROTECTED)
|
||||||
private final Update update;
|
private final Update update;
|
||||||
|
|
||||||
@Getter
|
@Override
|
||||||
private final BotSession session;
|
public Optional<String> getMessageText() {
|
||||||
|
if (update.hasMessage()) {
|
||||||
|
return Optional.ofNullable(update.getMessage().getText());
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getMessageText() {
|
public Optional<String> getPhoneNumber() {
|
||||||
if (update.hasMessage()) {
|
return Optional.of(update)
|
||||||
return Optional.ofNullable(update.getMessage().getText());
|
.map(Update::getMessage)
|
||||||
}
|
.map(Message::getContact)
|
||||||
return Optional.empty();
|
.map(Contact::getPhoneNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getPhoneNumber() {
|
public Optional<String> getCallbackData() {
|
||||||
return Optional.of(update)
|
return Optional.of(update)
|
||||||
.map(Update::getMessage)
|
.map(Update::getCallbackQuery)
|
||||||
.map(Message::getContact)
|
.map(CallbackQuery::getData);
|
||||||
.map(Contact::getPhoneNumber);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getCallbackData() {
|
public Optional<String> getCallbackMessageText() {
|
||||||
return Optional.of(update)
|
return Optional.of(update)
|
||||||
.map(Update::getCallbackQuery)
|
.map(Update::getCallbackQuery)
|
||||||
.map(CallbackQuery::getData);
|
.map(CallbackQuery::getMessage)
|
||||||
}
|
.map(Message::getText);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getCallbackMessageText() {
|
public Long getChatId() {
|
||||||
return Optional.of(update)
|
return Utils.getChatId(update);
|
||||||
.map(Update::getCallbackQuery)
|
}
|
||||||
.map(CallbackQuery::getMessage)
|
|
||||||
.map(Message::getText);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getChatId() {
|
public BotSession getSession() {
|
||||||
return Utils.getChatId(update);
|
throw new UnsupportedOperationException("Session is not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,56 +7,47 @@ import org.telegram.telegrambots.meta.api.objects.Update;
|
|||||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||||
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
|
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
|
||||||
import ru.penkrat.stbf.api.BotCommandChain;
|
import ru.penkrat.stbf.api.BotCommandChain;
|
||||||
import ru.penkrat.stbf.api.SessionProvider;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class RubenlagusTelegramBot extends TelegramLongPollingBot {
|
public class RubenlagusTelegramBot extends TelegramLongPollingBot {
|
||||||
|
|
||||||
private final String botUsername;
|
private final String botUsername;
|
||||||
private final String botToken;
|
private final String botToken;
|
||||||
private final BotCommandChain commandChain;
|
private final BotCommandChain commandChain;
|
||||||
private final SessionProvider sessionProvider;
|
|
||||||
|
|
||||||
public RubenlagusTelegramBot(String botUsername, String botToken, BotCommandChain botCommandChain) {
|
public RubenlagusTelegramBot(String botUsername, String botToken, BotCommandChain botCommandChain) {
|
||||||
this(botUsername, botToken, botCommandChain, (id) -> {
|
this.botUsername = botUsername;
|
||||||
throw new IllegalArgumentException("'SessionProvider' is not defined");
|
this.botToken = botToken;
|
||||||
});
|
this.commandChain = botCommandChain;
|
||||||
}
|
|
||||||
|
|
||||||
public RubenlagusTelegramBot(String botUsername, String botToken, BotCommandChain botCommandChain, SessionProvider sessionProvider) {
|
TelegramBotsApi telegramBotsApi;
|
||||||
this.botUsername = botUsername;
|
try {
|
||||||
this.botToken = botToken;
|
telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class);
|
||||||
this.commandChain = botCommandChain;
|
telegramBotsApi.registerBot(this);
|
||||||
this.sessionProvider = sessionProvider;
|
} catch (TelegramApiException e) {
|
||||||
|
log.error("Error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TelegramBotsApi telegramBotsApi;
|
@Override
|
||||||
try {
|
public void onUpdateReceived(Update update) {
|
||||||
telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class);
|
try {
|
||||||
telegramBotsApi.registerBot(this);
|
commandChain.processCommand(
|
||||||
} catch (TelegramApiException e) {
|
new BotRequestImpl(update),
|
||||||
log.error("Error", e);
|
new BotResponseImpl(update, this));
|
||||||
}
|
} catch (Exception e) {
|
||||||
}
|
log.error("Bot Error:", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdateReceived(Update update) {
|
public String getBotUsername() {
|
||||||
try {
|
return botUsername;
|
||||||
commandChain.processCommand(
|
}
|
||||||
new BotRequestImpl(update, sessionProvider.get(Utils.getChatId(update))),
|
|
||||||
new BotResponseImpl(update, this));
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Bot Error:", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getBotUsername() {
|
public String getBotToken() {
|
||||||
return botUsername;
|
return botToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getBotToken() {
|
|
||||||
return botToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user