Class AbstractTelegramBot

  • All Implemented Interfaces:
    org.telegram.telegrambots.meta.generics.LongPollingBot
    Direct Known Subclasses:
    DefaultTelegramBot

    public class AbstractTelegramBot
    extends org.telegram.telegrambots.bots.TelegramLongPollingBot
    • Field Summary

      • Fields inherited from class org.telegram.telegrambots.bots.DefaultAbsSender

        exe
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractTelegramBot​(java.lang.String token, java.lang.String username)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addHandler​(ITelegramHandler handler)
      Registers ICommandHandler instance into a collection of handlers
      IAccessLevelValidator getAccessLevelValidator()  
      <T extends ITelegramHandler>
      java.util.List<T>
      getAvailableHandlersForUser​(java.lang.Class<T> clazz, org.telegram.telegrambots.meta.api.objects.User user)
      Returns a List<T> and verifies for access level if any of the handlers implements ITelegramHandler
      java.lang.String getBotToken()  
      java.lang.String getBotUsername()  
      ICommandHandler getHandler​(java.lang.String command)  
      java.util.Collection<ITelegramHandler> getHandlers()  
      void onUpdateReceived​(org.telegram.telegrambots.meta.api.objects.Update update)  
      protected java.lang.String processText​(java.lang.String text)  
      boolean removeHandler​(ITelegramHandler handler)
      Removes ICommandHandler instance from the collection of handlers
      void setAccessLevelValidator​(IAccessLevelValidator accessLevelValidator)
      Sets the Access Level Validator instance that will be used for future access level validations
      <T extends ITelegramHandler>
      boolean
      validateAccessLevel​(T handler, org.telegram.telegrambots.meta.api.objects.User user)
      Validates access level
      • Methods inherited from class org.telegram.telegrambots.bots.TelegramLongPollingBot

        clearWebhook, onClosing
      • Methods inherited from class org.telegram.telegrambots.bots.DefaultAbsSender

        downloadFile, downloadFile, downloadFile, downloadFile, downloadFileAsStream, downloadFileAsStream, downloadFileAsync, downloadFileAsync, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, getBaseUrl, getOptions, sendApiMethod, sendApiMethodAsync
      • Methods inherited from class org.telegram.telegrambots.meta.bots.AbsSender

        execute, executeAsync, getMe, getMeAsync, getWebhookInfo, getWebhookInfoAsync
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.telegram.telegrambots.meta.generics.LongPollingBot

        getOptions, onUpdatesReceived
    • Constructor Detail

      • AbstractTelegramBot

        public AbstractTelegramBot​(java.lang.String token,
                                   java.lang.String username)
    • Method Detail

      • onUpdateReceived

        public void onUpdateReceived​(org.telegram.telegrambots.meta.api.objects.Update update)
      • processText

        protected java.lang.String processText​(java.lang.String text)
        Parameters:
        text - the message's text
        Returns:
        Text without @BotNickname if specified
      • getBotUsername

        public java.lang.String getBotUsername()
      • getBotToken

        public java.lang.String getBotToken()
        Specified by:
        getBotToken in interface org.telegram.telegrambots.meta.generics.LongPollingBot
        Specified by:
        getBotToken in class org.telegram.telegrambots.bots.DefaultAbsSender
      • setAccessLevelValidator

        public void setAccessLevelValidator​(IAccessLevelValidator accessLevelValidator)
        Sets the Access Level Validator instance that will be used for future access level validations
        Parameters:
        accessLevelValidator - the access level validator implementation
      • getAccessLevelValidator

        public IAccessLevelValidator getAccessLevelValidator()
        Returns:
        the Access Level Validator instance that will be used for future access level validations
      • addHandler

        public void addHandler​(ITelegramHandler handler)
        Registers ICommandHandler instance into a collection of handlers
        Parameters:
        handler - the ICommandHandler instance
      • removeHandler

        public boolean removeHandler​(ITelegramHandler handler)
        Removes ICommandHandler instance from the collection of handlers
        Parameters:
        handler - the ICommandHandler instance
        Returns:
        true if handler with such command name was previously registered, false otherwise
      • getHandler

        public ICommandHandler getHandler​(java.lang.String command)
        Parameters:
        command - the command name
        Returns:
        ICommandHandler command handler from the collection of handlers, null if not registered
      • getHandlers

        public java.util.Collection<ITelegramHandler> getHandlers()
        Returns:
        the collection of ICommandHandler containing all currently registered handlers
      • getAvailableHandlersForUser

        public <T extends ITelegramHandler> java.util.List<T> getAvailableHandlersForUser​(java.lang.Class<T> clazz,
                                                                                          org.telegram.telegrambots.meta.api.objects.User user)
        Returns a List<T> and verifies for access level if any of the handlers implements ITelegramHandler
        Type Parameters:
        T - the type of the handler
        Parameters:
        clazz - the class of the handler
        user - the user that requests this handler
        Returns:
        List<T> with all handlers implementing the generic type provided
      • validateAccessLevel

        public <T extends ITelegramHandler> boolean validateAccessLevel​(T handler,
                                                                        org.telegram.telegrambots.meta.api.objects.User user)
        Validates access level
        Parameters:
        handler - the handler
        user - the user requesting the that handler
        Returns:
        true if user is able to use that handler, false otherwise (Not registered, doesn't have access and so)