Interface BotManager

All Superinterfaces:
AutoCloseable, Closeable

public sealed interface BotManager extends Closeable
Interface for managing bots and their settings.

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 Details

    • newBotManager

      @Internal @NotNull static @NotNull BotManager 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 provided completeCallback will be invoked.

      Parameters:
      token - the bot's token, required for authentication with Telegram
      username - the bot's username, as it appears in Telegram
      completeCallback - the callback that will be invoked when the bot has been registered
      Throws:
      NullPointerException - if any of the arguments are null
      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 LongPollingBotSettings object. The bot is registered with these settings and initialized accordingly. Upon successful registration, the completeCallback will be invoked.

      Parameters:
      token - the bot's token, required for authentication with Telegram
      username - the bot's username, as it appears in Telegram
      longPollingSettings - the settings to configure the long polling bot
      completeCallback - the callback that will be invoked when the bot has been registered
      Throws:
      NullPointerException - if any of the arguments are null
    • 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 completeCallback will be invoked.

      Parameters:
      token - the bot's token, required for authentication with Telegram
      username - the bot's username, as it appears in Telegram
      webhookSettings - the settings to configure the webhook bot
      webhookServer - 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 are null
      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 completeCallback will be invoked.

      Parameters:
      token - the bot's token, required for authentication with Telegram
      username - the bot's username, as it appears in Telegram
      webhookSettings - the settings to configure the webhook bot
      serverConfig - 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 are null
    • unregisterBot

      void unregisterBot(@NotNull @NotNull String botToken)
      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 is null
    • unregisterBot

      void unregisterBot(@NotNull @NotNull TelegramBot telegramBot)
      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 is null
    • getRegisteredBots

      @NotNull @NotNull @Unmodifiable Collection<TelegramBot> getRegisteredBots()
      Retrieves all the bots currently managed by the BotManager.

      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 TelegramBot instances