Add custom method

This commit is contained in:
Andrea Cavalli 2024-02-14 11:53:53 +01:00
parent 9b8c41dab1
commit 228e583c26

View File

@ -100,6 +100,25 @@ public class TelegramBotsApi {
} }
} }
/**
* Register a bot in the api that will receive updates using webhook method
* @param bot Bot to register
*
* @apiNote The webhook url will be appended with `/callback/bot.getBotPath()` at the end
*/
public void registerBotWithoutToken(WebhookBot bot) throws TelegramApiException {
if (useWebhook) {
if (webhook == null) {
throw new TelegramApiException("This instance doesn't support Webhook bot, use correct constructor");
}
if (StringUtils.isEmpty(bot.getBotUsername())) {
throw new TelegramApiException("Bot username can't be empty");
}
bot.onRegister();
webhook.registerWebhook(bot);
}
}
/** /**
* Checks that the username and token are presented * Checks that the username and token are presented
* @param telegramBot bot to register * @param telegramBot bot to register