Class BaseAbilityBot

  • All Implemented Interfaces:
    AbilityExtension
    Direct Known Subclasses:
    AbilityBot, AbilityWebhookBot

    public abstract class BaseAbilityBot
    extends DefaultAbsSender
    implements AbilityExtension
    The father of all ability bots. Bots that need to utilize abilities need to extend this bot.

    It's important to note that this bot strictly extends TelegramLongPollingBot.

    All bots extending the BaseAbilityBot get implicit abilities:

    • /claim - Claims this bot
    • /report - reports all user-defined commands (abilities)
      • The same format acceptable by BotFather
    • /commands - returns a list of all possible bot commands based on the privacy of the requesting user
    • /backup - returns a backup of the bot database
    • /recover - recovers the database
    • /promote @username - promotes user to bot admin
    • /demote @username - demotes bot admin to user
    • /ban @username - bans the user from accessing your bot commands and features
    • /unban @username - lifts the ban from the user

    Additional information of the implicit abilities are present in the methods that declare them.

    The two most important handles in the BaseAbilityBot are the DBContext db and the MessageSender sender. All bots extending BaseAbilityBot can use both handles in their update consumers.

    Author:
    Abbas Abou Daya
    • Method Detail

      • creatorId

        public abstract int creatorId()
      • users

        protected Map<Integer,​org.telegram.telegrambots.meta.api.objects.User> users()
        Returns:
        the map of
      • blacklist

        protected Set<Integer> blacklist()
        Returns:
        a blacklist containing all the IDs of the banned users
      • admins

        protected Set<Integer> admins()
        Returns:
        an admin set of all the IDs of bot administrators
      • abilities

        public Map<String,​Ability> abilities()
        Returns:
        the immutable map of
      • replies

        public List<Reply> replies()
        Returns:
        the immutable list carrying the embedded replies
      • onUpdateReceived

        public void onUpdateReceived​(org.telegram.telegrambots.meta.api.objects.Update update)
        This method contains the stream of actions that are applied on any update.

        It will correctly handle addition of users into the DB and the execution of abilities and replies.

        Parameters:
        update - the update received by Telegram's API
      • getBotUsername

        public String getBotUsername()
      • checkGlobalFlags

        protected boolean checkGlobalFlags​(org.telegram.telegrambots.meta.api.objects.Update update)
        Test the update against the provided global flags. The default implementation is a passthrough to all updates.

        This method should be overridden if the user wants to restrict bot usage to only certain updates.

        Parameters:
        update - a Telegram Update
        Returns:
        true if the update satisfies the global flags