Class ATelegramBot

java.lang.Object
host.anzo.commons.socials.telegram.ATelegramBot
All Implemented Interfaces:
org.telegram.telegrambots.longpolling.interfaces.LongPollingUpdateConsumer, org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer

public abstract class ATelegramBot extends Object implements org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
     
    protected org.telegram.telegrambots.meta.generics.TelegramClient
     
    protected static Font
     
    protected static Font
     
    protected boolean
     
    protected static final int
     
    protected static final int
     
    protected String
     

    Fields inherited from interface org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer

    updatesProcessorExecutor
  • Constructor Summary

    Constructors
    Constructor
    Description
    ATelegramBot(String botName, String token, boolean isAsync)
    Telegram bot default constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    addResendTask(Runnable runnable, int retryAfterSeconds)
    Add specified runnable to resend list (a message will be resent after specified seconds passed)
    void
    consume(org.telegram.telegrambots.meta.api.objects.Update update)
    Called when bot receives an update message
    protected void
    deleteMessage(long chatId, int messageId)
    Delete a message from channel with specified chatId
    protected void
    deleteMessage(String chatId, int messageId)
    Delete a message from channel with specified chatId
    protected void
    deleteMessage(String chatId, @NotNull org.telegram.telegrambots.meta.api.objects.message.Message message)
    Delete a message from channel with specified chatId
    protected abstract String
     
    protected abstract org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup
    getInlineKeyboardMarkup(org.telegram.telegrambots.meta.api.objects.Update update)
    Attach keyboard to a specified update message
    protected abstract org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardMarkup
     
    abstract boolean
     
    abstract void
    Called when server going shutdown
    void
     
    protected void
    sendMessage(long chatId, String messageText)
    Send text message to specified chat
    protected void
    sendMessage(Long chatId, String title, String messageText, String additionalImagePath)
    Create image with specified text and additional image
    protected void
    sendMessage(Long chatId, String title, String messageText, String caption, String additionalImagePath)
    Send a message with image to the channel with specified chatId
    protected void
    sendMessage(String chatId, String messageText)
    Send text message to specified chat
    protected void
    sendMessage(String chatId, String title, String messageText, String caption, String additionalImagePath)
    Send a message with image to the channel with specified chatId
    protected void
    sendMessage(org.telegram.telegrambots.meta.api.methods.send.SendMessage message)
    Send a message asynchronously
    protected void
    sendMessage(org.telegram.telegrambots.meta.api.objects.Update update, Long chatId, String messageText, boolean withInlineKeyboard)
    Send a text message to specified chat with the possibility to attach inline keyboard
    protected int
    sendMessageWithResult(org.telegram.telegrambots.meta.api.methods.send.SendMessage message)
    Send a message synchronously

    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.longpolling.util.LongPollingSingleThreadUpdateConsumer

    consume
  • Field Details

    • client

      protected org.telegram.telegrambots.meta.generics.TelegramClient client
    • botName

      protected String botName
    • token

      protected String token
    • isAsync

      protected boolean isAsync
    • FONT_TITLE

      protected static Font FONT_TITLE
    • FONT_CONTENT

      protected static Font FONT_CONTENT
    • MAX_MESSAGE_SIZE

      protected static final int MAX_MESSAGE_SIZE
      See Also:
    • MAX_CAPTION_SIZE

      protected static final int MAX_CAPTION_SIZE
      See Also:
  • Constructor Details

    • ATelegramBot

      public ATelegramBot(String botName, String token, boolean isAsync)
      Telegram bot default constructor
      Parameters:
      botName - bot name
      token - bot token
  • Method Details

    • onTick

      public void onTick()
    • getInlineKeyboardMarkup

      protected abstract org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup getInlineKeyboardMarkup(org.telegram.telegrambots.meta.api.objects.Update update)
      Attach keyboard to a specified update message
      Parameters:
      update - update message
      Returns:
      inline keyboard markup will be attached to the update message
    • getReplyKeyboardMarkup

      protected abstract org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardMarkup getReplyKeyboardMarkup()
      Returns:
      inline keyboard markup used for current bot
    • getDefaultBackgroundImagePath

      protected abstract String getDefaultBackgroundImagePath()
      Returns:
      local path to image will be used as background for photo messages
    • onServerShutdown

      public abstract void onServerShutdown()
      Called when server going shutdown
    • isEnabled

      public abstract boolean isEnabled()
      Returns:
      true if bot enabled, false otherwise
    • sendMessageWithResult

      protected int sendMessageWithResult(org.telegram.telegrambots.meta.api.methods.send.SendMessage message)
      Send a message synchronously
      Parameters:
      message - message to send
      Returns:
      sent message id, 0 if message failed to send
    • sendMessage

      protected void sendMessage(org.telegram.telegrambots.meta.api.methods.send.SendMessage message)
      Send a message asynchronously
      Parameters:
      message - message to send
    • sendMessage

      protected void sendMessage(String chatId, String messageText)
      Send text message to specified chat
      Parameters:
      chatId - symbolical chat name
      messageText - message text
    • sendMessage

      protected void sendMessage(long chatId, String messageText)
      Send text message to specified chat
      Parameters:
      chatId - symbolical chat name
      messageText - message text
    • sendMessage

      protected void sendMessage(org.telegram.telegrambots.meta.api.objects.Update update, Long chatId, String messageText, boolean withInlineKeyboard)
      Send a text message to specified chat with the possibility to attach inline keyboard
      Parameters:
      update - update object
      chatId - channel chat id
      messageText - message text
      withInlineKeyboard - true if need attach inline keyboard, false otherwise
    • sendMessage

      protected void sendMessage(Long chatId, String title, String messageText, String additionalImagePath)
      Create image with specified text and additional image
      Parameters:
      chatId - chat id where need a post created message
      title - message title
      messageText - message text
      additionalImagePath - additional image displayed on the right side
    • sendMessage

      protected void sendMessage(Long chatId, String title, String messageText, String caption, String additionalImagePath)
      Send a message with image to the channel with specified chatId
      Parameters:
      chatId - channel chat id
      title - message title
      messageText - message text
      caption - image caption
      additionalImagePath - local path to image
    • sendMessage

      protected void sendMessage(String chatId, String title, String messageText, String caption, String additionalImagePath)
      Send a message with image to the channel with specified chatId
      Parameters:
      chatId - channel chat id
      title - message title
      messageText - message text
      caption - image caption
      additionalImagePath - local path to image
    • deleteMessage

      protected void deleteMessage(String chatId, @NotNull @NotNull org.telegram.telegrambots.meta.api.objects.message.Message message)
      Delete a message from channel with specified chatId
      Parameters:
      chatId - channel chat id
      message - message to delete
    • deleteMessage

      protected void deleteMessage(String chatId, int messageId)
      Delete a message from channel with specified chatId
      Parameters:
      chatId - channel chat id
      messageId - message ID to delete
    • deleteMessage

      protected void deleteMessage(long chatId, int messageId)
      Delete a message from channel with specified chatId
      Parameters:
      chatId - channel chat id
      messageId - message to delete
    • addResendTask

      protected void addResendTask(Runnable runnable, int retryAfterSeconds)
      Add specified runnable to resend list (a message will be resent after specified seconds passed)
      Parameters:
      runnable - runnable with a message send task
      retryAfterSeconds - seconds to resend
    • consume

      public void consume(org.telegram.telegrambots.meta.api.objects.Update update)
      Called when bot receives an update message
      Specified by:
      consume in interface org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer
      Parameters:
      update - update message