@Override public void afterPropertiesSet() throws Exception { try { for (LongPollingBot bot : longPollingBots) { BotSession session = telegramBotsApi.registerBot(bot); handleAfterRegistrationHook(bot, session); } for (WebhookBot bot : webHookBots) { telegramBotsApi.registerBot(bot); } } catch (TelegramApiException e) { throw new RuntimeException(e); } }
@PostConstruct public void start() throws TelegramApiRequestException { log.info("Starting auto config for telegram bots"); TelegramBotsApi api = getApi(); pollingBots.forEach(bot -> { try { log.info("Registering polling bot: {}", bot.getBotUsername()); sessions.add(api.registerBot(bot)); } catch (TelegramApiException e) { log.error("Failed to register bot {} due to error {}", bot.getBotUsername(), e.getMessage()); } }); webHookBots.forEach(bot -> { try { log.info("Registering web hook bot: {}", bot.getBotUsername()); api.registerBot(bot); } catch (TelegramApiException e) { log.error("Failed to register bot {} due to error {}", bot.getBotUsername(), e.getMessage()); } }); }
private static TelegramBotsApi createTelegramBotsApi() throws TelegramApiException { TelegramBotsApi telegramBotsApi; if (!BuildVars.useWebHook) { // Default (long polling only) telegramBotsApi = createLongPollingTelegramBotsApi(); } else if (!BuildVars.pathToCertificatePublicKey.isEmpty()) { // Filled a path to a pem file ? looks like you're going for the self signed option then, invoke with store and pem file to supply. telegramBotsApi = createSelfSignedTelegramBotsApi(); telegramBotsApi.registerBot(new WebHookExampleHandlers()); } else { // Non self signed, make sure you've added private/public and if needed intermediate to your cert-store. telegramBotsApi = createNoSelfSignedTelegramBotsApi(); telegramBotsApi.registerBot(new WebHookExampleHandlers()); } return telegramBotsApi; }
public static void main(String[] args) { BotLogger.setLevel(Level.ALL); BotLogger.registerLogger(new ConsoleHandler()); try { BotLogger.registerLogger(new BotsFileHandler()); } catch (IOException e) { BotLogger.severe(LOGTAG, e); } try { ApiContextInitializer.init(); TelegramBotsApi telegramBotsApi = createTelegramBotsApi(); try { // Register long polling bots. They work regardless type of TelegramBotsApi we are creating telegramBotsApi.registerBot(new ChannelHandlers()); telegramBotsApi.registerBot(new DirectionsHandlers()); telegramBotsApi.registerBot(new RaeHandlers()); telegramBotsApi.registerBot(new WeatherHandlers()); telegramBotsApi.registerBot(new TransifexHandlers()); telegramBotsApi.registerBot(new FilesHandlers()); telegramBotsApi.registerBot(new CommandsHandler(BotConfig.COMMANDS_USER)); telegramBotsApi.registerBot(new ElektrollArtFanHandler()); } catch (TelegramApiException e) { BotLogger.error(LOGTAG, e); } } catch (Exception e) { BotLogger.error(LOGTAG, e); } }