@Bean @ConditionalOnMissingBean(TelegramBotsApi.class) public TelegramBotsApi telegramBotsApi() { return new TelegramBotsApi(); }
/** * @brief Creates a Telegram Bots Api to use Long Polling bots and webhooks bots with self-signed certificates. * @return TelegramBotsApi to register the bots. * * @note https://core.telegram.org/bots/self-signed#java-keystore for generating a keypair in store and exporting the pem. * @note Don't forget to split the pem bundle (begin/end), use only the public key as input! */ private static TelegramBotsApi createSelfSignedTelegramBotsApi() throws TelegramApiException { return new TelegramBotsApi(BuildVars.pathToCertificateStore, BuildVars.certificateStorePassword, BuildVars.EXTERNALWEBHOOKURL, BuildVars.INTERNALWEBHOOKURL, BuildVars.pathToCertificatePublicKey); }
/** * @brief Creates a Telegram Bots Api to use Long Polling (getUpdates) bots. * @return TelegramBotsApi to register the bots. */ private static TelegramBotsApi createLongPollingTelegramBotsApi() { return new TelegramBotsApi(); }
/** * @brief Creates a Telegram Bots Api to use Long Polling bots and webhooks bots with no-self-signed certificates. * @return TelegramBotsApi to register the bots. * * @note Coming from a set of pem files here's one way to do it: * @code{.sh} * openssl pkcs12 -export -in public.pem -inkey private.pem > keypair.p12 * keytool -importkeystore -srckeystore keypair.p12 -destkeystore server.jks -srcstoretype pkcs12 * #have (an) intermediate(s) to supply? first: * cat public.pem intermediate.pem > set.pem (use set.pem as -in) * @endcode */ private static TelegramBotsApi createNoSelfSignedTelegramBotsApi() throws TelegramApiException { return new TelegramBotsApi(BuildVars.pathToCertificateStore, BuildVars.certificateStorePassword, BuildVars.EXTERNALWEBHOOKURL, BuildVars.INTERNALWEBHOOKURL); } }
/** * Get API object depending on configured properties. * If no properties are configured, the API object won't support webhooks. * @return api object * @throws TelegramApiRequestException */ @Bean @ConditionalOnMissingBean public TelegramBotsApi getApi() throws TelegramApiRequestException { TelegramBotsApi result; if (!StringUtils.isEmpty(externalUrl) && !StringUtils.isEmpty(internalUrl)) { if (!StringUtils.isEmpty(keyStore) && !StringUtils.isEmpty(keyStorePassword)) { if (!StringUtils.isEmpty(pathToCertificate)) { log.info("Initializing API with webhook support and configured keystore and path to certificate"); result = new TelegramBotsApi(keyStore, keyStorePassword, externalUrl, internalUrl, pathToCertificate); } else { log.info("Initializing API with webhook support and configured keystore"); result = new TelegramBotsApi(keyStore, keyStorePassword, externalUrl, internalUrl); } } else { log.info("Initializing API with webhook support"); result = new TelegramBotsApi(externalUrl, internalUrl); } } else { log.info("Initializing API without webhook support"); result = new TelegramBotsApi(); } return result; }