Class AbstractTelegramBot
- java.lang.Object
-
- org.telegram.telegrambots.meta.bots.AbsSender
-
- org.telegram.telegrambots.bots.DefaultAbsSender
-
- org.telegram.telegrambots.bots.TelegramLongPollingBot
-
- com.github.unafraid.telegrambot.bots.AbstractTelegramBot
-
- All Implemented Interfaces:
org.telegram.telegrambots.meta.generics.LongPollingBot
- Direct Known Subclasses:
DefaultTelegramBot
public class AbstractTelegramBot extends org.telegram.telegrambots.bots.TelegramLongPollingBot
-
-
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 voidaddHandler(ITelegramHandler handler)Registers ICommandHandler instance into a collection of handlersIAccessLevelValidatorgetAccessLevelValidator()<T extends ITelegramHandler>
java.util.List<T>getAvailableHandlersForUser(java.lang.Class<T> clazz, org.telegram.telegrambots.meta.api.objects.User user)Returns aList<T>and verifies for access level if any of the handlers implementsITelegramHandlerjava.lang.StringgetBotToken()java.lang.StringgetBotUsername()ICommandHandlergetHandler(java.lang.String command)java.util.Collection<ITelegramHandler>getHandlers()voidonUpdateReceived(org.telegram.telegrambots.meta.api.objects.Update update)protected java.lang.StringprocessText(java.lang.String text)booleanremoveHandler(ITelegramHandler handler)Removes ICommandHandler instance from the collection of handlersvoidsetAccessLevelValidator(IAccessLevelValidator accessLevelValidator)Sets the Access Level Validator instance that will be used for future access level validations<T extends ITelegramHandler>
booleanvalidateAccessLevel(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
-
-
-
-
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:
getBotTokenin interfaceorg.telegram.telegrambots.meta.generics.LongPollingBot- Specified by:
getBotTokenin classorg.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:
trueif handler with such command name was previously registered,falseotherwise
-
getHandler
public ICommandHandler getHandler(java.lang.String command)
- Parameters:
command- the command name- Returns:
ICommandHandlercommand handler from the collection of handlers,nullif 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 aList<T>and verifies for access level if any of the handlers implementsITelegramHandler- Type Parameters:
T- the type of the handler- Parameters:
clazz- the class of the handleruser- 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 handleruser- the user requesting the that handler- Returns:
trueif user is able to use that handler,falseotherwise (Not registered, doesn't have access and so)
-
-