org.telegram.telegrambots.meta.generics.BotSession Java Examples
The following examples show how to use
org.telegram.telegrambots.meta.generics.BotSession.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TelegramBotInitializer.java From TelegramBots with MIT License | 6 votes |
private void handleAnnotatedMethod(Object bot, Method method, BotSession session) { try { TelegramApiRequestException test = new TelegramApiRequestException("Error getting updates", new ApiResponse()); log.error(test.getMessage(), test); if (method.getParameterCount() > 1) { log.warn(format("Method %s of Type %s has too many parameters", method.getName(), method.getDeclaringClass().getCanonicalName())); return; } if (method.getParameterCount() == 0) { method.invoke(bot); return; } if (method.getParameterTypes()[0].equals(BotSession.class)) { method.invoke(bot, session); return; } log.warn(format("Method %s of Type %s has invalid parameter type", method.getName(), method.getDeclaringClass().getCanonicalName())); } catch (InvocationTargetException | IllegalAccessException e) { log.error(format("Couldn't invoke Method %s of Type %s", method.getName(), method.getDeclaringClass().getCanonicalName())); } }
Example #2
Source File: TelegramBotsApi.java From TelegramBots with MIT License | 5 votes |
/** * Register a bot. The Bot Session is started immediately, and may be disconnected by calling close. * @param bot the bot to register */ public BotSession registerBot(LongPollingBot bot) throws TelegramApiRequestException { bot.clearWebhook(); BotSession session = ApiContext.getInstance(BotSession.class); session.setToken(bot.getBotToken()); session.setOptions(bot.getOptions()); session.setCallback(bot); session.start(); return session; }
Example #3
Source File: TestBase.java From TelegramBots with MIT License | 4 votes |
@BeforeAll public static void beforeClass() { ApiContext.register(BotSession.class, FakeBotSession.class); ApiContext.register(Webhook.class, FakeWebhook.class); }
Example #4
Source File: TelegramBotInitializer.java From TelegramBots with MIT License | 4 votes |
private void handleAfterRegistrationHook(Object bot, BotSession botSession) { Stream.of(bot.getClass().getMethods()) .filter(method -> method.getAnnotation(AfterBotRegistration.class) != null) .forEach(method -> handleAnnotatedMethod(bot, method, botSession)); }
Example #5
Source File: TestTelegramBotStarterRegistrationHooks.java From TelegramBots with MIT License | 4 votes |
@AfterBotRegistration public void afterBotHookWithSession(BotSession session) { hookCalledWithSession = session.equals(someBotSession); }
Example #6
Source File: ApiContextInitializer.java From TelegramBots with MIT License | 4 votes |
public static void init() { ApiContext.register(BotSession.class, DefaultBotSession.class); ApiContext.register(Webhook.class, DefaultWebhook.class); }