Package io.github.natanimn.telebof
Class BotClient
java.lang.Object
io.github.natanimn.telebof.BotClient
Main class of Telebof library
- Since:
- 3 March 2025
- Author:
- Natanim
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA builder of BotClient class.(package private) static final record -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Userfinal BotContextprivate final Dispatcherprivate final ExecutorServiceprivate final GetUpdatesprivate Booleanprivate Integerprivate final ExecutorServiceprivate booleanprivate final AtomicBooleanprivate final StateMemoryStorageprivate static final Map<Function<Update, TelegramUpdate>, Updates> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddBusinessConnectionHandler(BusinessConnectionHandler handler, MethodHandle method) private voidaddBusinessMessageHandler(BusinessMessageHandler handler, MethodHandle method) private voidaddCallbackHandler(CallbackHandler handler, MethodHandle method) private voidaddChannelPostHandler(ChannelPostHandler handler, MethodHandle method) private voidaddChatBoostHandler(ChatBoostHandler handler, MethodHandle method) private voidaddChatJoinRequestHandler(ChatJoinRequestHandler handler, MethodHandle method) private voidaddChatMemberHandler(ChatMemberHandler handler, MethodHandle method) private voidaddChosenInlineHandler(ChosenInlineHandler handler, MethodHandle method) private voidaddDeletedBusinessMessageHandler(DeletedBusinessMessageHandler handler, MethodHandle method) private voidaddEditedBusinessMessageHandler(EditedBusinessMessageHandler handler, MethodHandle method) private voidaddEditedChannelPostHandler(EditedChannelPostHandler handler, MethodHandle method) private voidaddEditedMessageHandler(EditedMessageHandler handler, MethodHandle method) voidaddHandler(Object object) private voidaddInlineHandler(InlineHandler handler, MethodHandle method) private voidaddMessageHandler(MessageHandler handler, MethodHandle method) private voidaddMyChatMemberHandler(MyChatMemberHandler handler, MethodHandle method) private voidaddPollAnswerHandler(PollAnswerHandler handler, MethodHandle method) private voidaddPollHandler(PollHandler handler, MethodHandle method) private voidaddPreCheckoutHandler(PreCheckoutHandler handler, MethodHandle method) private voidaddPurchasedPaidMediaHandler(PurchasedPaidMediaHandler handler, MethodHandle method) private voidaddReactionCountHandler(ReactionCountHandler handler, MethodHandle method) private voidaddReactionHandler(ReactionHandler handler, MethodHandle method) private voidaddRemovedChatBoostHandler(RemovedChatBoostHandler handler, MethodHandle method) private voidaddShippingHandler(ShippingHandler handler, MethodHandle method) private voidaddToList(MethodHandle handle, Method method, List<AnnotatedHandler> annotatedMethods) private <T extends TelegramUpdate>
voidexecuteUpdate(Updates updateName, Filter filter, TelegramUpdate update) private BotClient.UpdateInfogetInfoFromUpdate(Update update) me()voidonBusinessConnection(FilterExecutor executor, UpdateHandler<BusinessConnection> handler) Use this method to register new handler for incomingUpdate.getBusinessConnection()update.voidonBusinessMessage(FilterExecutor executor, UpdateHandler<Message> handler) Use this method to register new handler for incomingUpdate.getBusinessMessage()update.voidonCallback(FilterExecutor executor, UpdateHandler<CallbackQuery> handler) Use this method to register new handler for incomingUpdate.getCallbackQuery()update.voidonChannelPost(FilterExecutor executor, UpdateHandler<Message> handler) Use this method to register new handler for incomingUpdate.getChannelPost()update.voidonChatBoost(FilterExecutor executor, UpdateHandler<ChatBoostUpdated> handler) Use this method to register new handler for incomingUpdate.getChatBoost()update.voidonChatJoinRequest(FilterExecutor executor, UpdateHandler<ChatJoinRequest> handler) Use this method to register new handler for incomingUpdate.getChatJoinRequest()update.voidonChatMember(FilterExecutor executor, UpdateHandler<ChatMemberUpdated> handler) Use this method to register new handler for incomingUpdate.getChatMember()update.voidonChosenInlineResult(FilterExecutor executor, UpdateHandler<ChosenInlineResult> handler) Use this method to register new handler for incomingUpdate.getChosenInlineResult()update.voidonDeletedBusinessMessage(FilterExecutor executor, UpdateHandler<BusinessMessagesDeleted> handler) Use this method to register new handler for incomingUpdate.getDeletedBusinessMessages()update.voidonEditedBusinessMessage(FilterExecutor executor, UpdateHandler<Message> handler) Use this method to register new handler for incomingUpdate.getEditedBusinessMessage()update.voidonEditedChannelPost(FilterExecutor executor, UpdateHandler<Message> handler) Use this method to register new handler for incomingUpdate.getEditedChannelPost()update.voidonEditedMessage(FilterExecutor executor, UpdateHandler<Message> handler) Use this method to register new handler for incomingUpdate.getEditedMessage()update.voidonInline(FilterExecutor executor, UpdateHandler<InlineQuery> handler) Use this method to register new handler for incomingUpdate.getInlineQuery()update.voidonMessage(FilterExecutor executor, UpdateHandler<Message> handler) Use this method to register new handler for incomingUpdate.getMessage()update.voidonMyChatMember(FilterExecutor executor, UpdateHandler<ChatMemberUpdated> handler) Use this method to register new handler for incomingUpdate.getMyChatMember()update.voidonPoll(FilterExecutor executor, UpdateHandler<Poll> handler) Use this method to register new handler for incomingUpdate.getPoll()update.voidonPollAnswer(FilterExecutor executor, UpdateHandler<PollAnswer> handler) Use this method to register new handler for incomingUpdate.getPollAnswer()update.voidonPreCheckout(FilterExecutor executor, UpdateHandler<PreCheckoutQuery> handler) Use this method to register new handler for incomingUpdate.getPreCheckoutQuery()update.voidonPurchasedPaidMedia(FilterExecutor executor, UpdateHandler<PaidMediaPurchased> handler) Use this method to register new handler for incomingUpdate.getPurchasedPaidMedia()update.voidonReaction(FilterExecutor executor, UpdateHandler<MessageReactionUpdated> handler) Use this method to register new handler for incomingUpdate.getMessageReaction()update.voidonReactionCount(FilterExecutor executor, UpdateHandler<MessageReactionCountUpdated> handler) Use this method to register new handler for incomingUpdate.getMessageReactionCount()update.voidonRemovedChatBoost(FilterExecutor executor, UpdateHandler<ChatBoostRemoved> handler) Use this method to register new handler for incomingUpdate.getRemovedChatBoost()update.voidonShipping(FilterExecutor executor, UpdateHandler<ShippingQuery> handler) Use this method to register new handler for incomingUpdate.getShippingQuery()update.voidprocessUpdates(List<Update> updates) Process updates retrieved from long polling or webhookprivate voidRetrieve updatesprivate voidprivate voidsetOffset(int offset) private voidshutDown()private voidsleep(int seconds) voidUse this method to run the bot using long pollingvoidstop()Stop the bot
-
Field Details
-
offset
-
stopPolling
-
skipOldUpdates
private boolean skipOldUpdates -
executor
-
bot
-
storage
-
dispatcher
-
context
-
isConnected
-
pollingExecutor
-
getUpdates
-
updateMap
-
-
Constructor Details
-
BotClient
private BotClient(String botToken, boolean skipOldUpdates, int limit, Integer offset, int timeout, Updates[] allowedUpdates, Proxy proxy, String localBotApiUrl, boolean useTestServer, int numThreads) - Parameters:
botToken- bot token obtained from @BotFatherskipOldUpdates- skip last 24 hours update(supported on long polling)limit- number of updates to receive(supported on long polling)offset- offset (supported on long polling)timeout- timeout (supported on long polling)allowedUpdates- allowed updates to receiveproxy- custom proxylocalBotApiUrl- local bot api urluseTestServer- test servernumThreads- number of threads to run handlers parallel
-
BotClient
-
-
Method Details
-
onMessage
Use this method to register new handler for incomingUpdate.getMessage()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onCallback
Use this method to register new handler for incomingUpdate.getCallbackQuery()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onInline
Use this method to register new handler for incomingUpdate.getInlineQuery()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onPoll
Use this method to register new handler for incomingUpdate.getPoll()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onMyChatMember
Use this method to register new handler for incomingUpdate.getMyChatMember()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onPollAnswer
Use this method to register new handler for incomingUpdate.getPollAnswer()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onPreCheckout
Use this method to register new handler for incomingUpdate.getPreCheckoutQuery()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onChatMember
Use this method to register new handler for incomingUpdate.getChatMember()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onEditedMessage
Use this method to register new handler for incomingUpdate.getEditedMessage()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onChannelPost
Use this method to register new handler for incomingUpdate.getChannelPost()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onEditedChannelPost
Use this method to register new handler for incomingUpdate.getEditedChannelPost()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onChatJoinRequest
Use this method to register new handler for incomingUpdate.getChatJoinRequest()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onChosenInlineResult
public void onChosenInlineResult(FilterExecutor executor, UpdateHandler<ChosenInlineResult> handler) Use this method to register new handler for incomingUpdate.getChosenInlineResult()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onShipping
Use this method to register new handler for incomingUpdate.getShippingQuery()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onReaction
Use this method to register new handler for incomingUpdate.getMessageReaction()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onReactionCount
public void onReactionCount(FilterExecutor executor, UpdateHandler<MessageReactionCountUpdated> handler) Use this method to register new handler for incomingUpdate.getMessageReactionCount()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onChatBoost
Use this method to register new handler for incomingUpdate.getChatBoost()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onRemovedChatBoost
Use this method to register new handler for incomingUpdate.getRemovedChatBoost()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onBusinessConnection
public void onBusinessConnection(FilterExecutor executor, UpdateHandler<BusinessConnection> handler) Use this method to register new handler for incomingUpdate.getBusinessConnection()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onBusinessMessage
Use this method to register new handler for incomingUpdate.getBusinessMessage()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onEditedBusinessMessage
Use this method to register new handler for incomingUpdate.getEditedBusinessMessage()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onDeletedBusinessMessage
public void onDeletedBusinessMessage(FilterExecutor executor, UpdateHandler<BusinessMessagesDeleted> handler) Use this method to register new handler for incomingUpdate.getDeletedBusinessMessages()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
onPurchasedPaidMedia
public void onPurchasedPaidMedia(FilterExecutor executor, UpdateHandler<PaidMediaPurchased> handler) Use this method to register new handler for incomingUpdate.getPurchasedPaidMedia()update.- Parameters:
executor- pre-defined or user-defined filterhandler- a handler to be executed
-
addMessageHandler
-
addEditedMessageHandler
-
addCallbackHandler
-
addChannelPostHandler
-
addEditedChannelPostHandler
-
addInlineHandler
-
addPollHandler
-
addPollAnswerHandler
-
addReactionHandler
-
addReactionCountHandler
-
addChatJoinRequestHandler
-
addPurchasedPaidMediaHandler
-
addPreCheckoutHandler
-
addShippingHandler
-
addChatBoostHandler
-
addChatMemberHandler
-
addMyChatMemberHandler
-
addRemovedChatBoostHandler
-
addBusinessMessageHandler
-
addBusinessConnectionHandler
-
addDeletedBusinessMessageHandler
private void addDeletedBusinessMessageHandler(DeletedBusinessMessageHandler handler, MethodHandle method) -
addEditedBusinessMessageHandler
private void addEditedBusinessMessageHandler(EditedBusinessMessageHandler handler, MethodHandle method) -
addChosenInlineHandler
-
addToList
-
addHandler
-
executeUpdate
private <T extends TelegramUpdate> void executeUpdate(Updates updateName, Filter filter, TelegramUpdate update) -
stop
public void stop()Stop the bot -
me
-
getInfoFromUpdate
-
processUpdates
Process updates retrieved from long polling or webhook- Parameters:
updates- array ofUpdate
-
retrieveUpdates
Retrieve updates- Throws:
InterruptedException- exception
-
shutDown
private void shutDown() -
runOnNewThread
private void runOnNewThread() -
startPolling
public void startPolling()Use this method to run the bot using long polling -
setOffset
private void setOffset(int offset) -
sleep
private void sleep(int seconds)
-