Interface BotManager
- All Superinterfaces:
AutoCloseable,Closeable
The BotManager provides methods to register and manage bots, supporting both
long polling and webhook-based Telegram bots. It also allows for retrieving the bots
that are currently registered with the manager.
-
Method Summary
Modifier and TypeMethodDescription@NotNull @Unmodifiable Collection<TelegramBot> Retrieves all the bots currently managed by theBotManager.static @NotNull BotManagerdefault voidregisterLongPolling(@NotNull String token, @NotNull String username, @NotNull Consumer<LongPollingTelegramBot> completeCallback) Registers a new long polling bot with the default settings.voidregisterLongPolling(@NotNull String token, @NotNull String username, @NotNull LongPollingBotSettings longPollingSettings, @NotNull Consumer<LongPollingTelegramBot> completeCallback) Registers a new long polling bot with custom settings.voidregisterWebhook(@NotNull String token, @NotNull String username, @NotNull WebhookBotSettings webhookSettings, @NotNull WebhookServerConfig serverConfig, @NotNull Consumer<WebhookTelegramBot> completeCallback) Registers a new webhook-based bot with an internal server configuration.voidregisterWebhook(@NotNull String token, @NotNull String username, @NotNull WebhookBotSettings webhookSettings, @NotNull WebhookServer webhookServer, @NotNull Consumer<WebhookTelegramBot> completeCallback) Registers a new webhook-based bot with no internal server configuration.voidunregisterBot(@NotNull String botToken) Unregisters a bot from the manager.voidunregisterBot(@NotNull TelegramBot telegramBot) Unregisters a bot from the manager.
-
Method Details
-
newBotManager
-
registerLongPolling
default void registerLongPolling(@NotNull @NotNull String token, @NotNull @NotNull String username, @NotNull @NotNull Consumer<LongPollingTelegramBot> completeCallback) Registers a new long polling bot with the default settings.This method simplifies the bot registration process by using default settings provided by
LongPollingBotSettings.DEFAULT. After the bot is successfully registered, the providedcompleteCallbackwill be invoked.- Parameters:
token- the bot's token, required for authentication with Telegramusername- the bot's username, as it appears in TelegramcompleteCallback- the callback that will be invoked when the bot has been registered- Throws:
NullPointerException- if any of the arguments arenull- See Also:
-
registerLongPolling
void registerLongPolling(@NotNull @NotNull String token, @NotNull @NotNull String username, @NotNull @NotNull LongPollingBotSettings longPollingSettings, @NotNull @NotNull Consumer<LongPollingTelegramBot> completeCallback) Registers a new long polling bot with custom settings.This method allows for fine-grained control over the bot's behavior by accepting a
LongPollingBotSettingsobject. The bot is registered with these settings and initialized accordingly. Upon successful registration, thecompleteCallbackwill be invoked.- Parameters:
token- the bot's token, required for authentication with Telegramusername- the bot's username, as it appears in TelegramlongPollingSettings- the settings to configure the long polling botcompleteCallback- the callback that will be invoked when the bot has been registered- Throws:
NullPointerException- if any of the arguments arenull
-
registerWebhook
void registerWebhook(@NotNull @NotNull String token, @NotNull @NotNull String username, @NotNull @NotNull WebhookBotSettings webhookSettings, @NotNull @NotNull WebhookServer webhookServer, @NotNull @NotNull Consumer<WebhookTelegramBot> completeCallback) Registers a new webhook-based bot with no internal server configuration.This method registers a bot that communicates with Telegram using webhooks. It uses no internal server for handling requests, so the bot will not receive updates until a server is set up externally. Once the bot is registered, the provided
completeCallbackwill be invoked.- Parameters:
token- the bot's token, required for authentication with Telegramusername- the bot's username, as it appears in TelegramwebhookSettings- the settings to configure the webhook botwebhookServer- the server to handle incoming webhook requests.completeCallback- the callback that will be invoked when the bot has been registered- Throws:
NullPointerException- if any of the arguments arenull- See Also:
-
registerWebhook
void registerWebhook(@NotNull @NotNull String token, @NotNull @NotNull String username, @NotNull @NotNull WebhookBotSettings webhookSettings, @NotNull @NotNull WebhookServerConfig serverConfig, @NotNull @NotNull Consumer<WebhookTelegramBot> completeCallback) Registers a new webhook-based bot with an internal server configuration.This method allows configuring both the bot settings and the internal server configuration for a webhook-based bot. Once registered, the
completeCallbackwill be invoked.- Parameters:
token- the bot's token, required for authentication with Telegramusername- the bot's username, as it appears in TelegramwebhookSettings- the settings to configure the webhook botserverConfig- the server configuration for handling webhook requests.completeCallback- the callback that will be invoked when the bot has been registered- Throws:
NullPointerException- if any of the arguments arenull
-
unregisterBot
Unregisters a bot from the manager.This method removes the specified bot from the manager, effectively stopping the bot and cleaning up any resources associated with it.
- Parameters:
botToken- the bot (token) to unregister- Throws:
NullPointerException- if the bot isnull
-
unregisterBot
Unregisters a bot from the manager.This method removes the specified bot from the manager, effectively stopping the bot and cleaning up any resources associated with it.
- Parameters:
telegramBot- the bot to unregister- Throws:
NullPointerException- if the bot isnull
-
getRegisteredBots
Retrieves all the bots currently managed by theBotManager.This method returns an unmodifiable collection of all the bots registered with the manager, either through long polling or webhook methods.
- Returns:
- an unmodifiable collection of all registered
TelegramBotinstances
-