Class TelegramClient
java.lang.Object
dev.voroby.springframework.telegram.client.TelegramClient
Telegram client component. Wrapper of native
Client
with authorization logic and notification handlers.- Author:
- Pavel Vorobyev
-
Constructor Summary
ConstructorDescriptionTelegramClient
(TelegramProperties properties, Collection<UpdateNotificationListener<?>> notificationHandlers, Client.ResultHandler defaultHandler, ClientAuthorizationState clientAuthorizationState) -
Method Summary
Modifier and TypeMethodDescription<T extends TdApi.Object>
Response<T>send
(TdApi.Function<T> query) Sends a request to the TDLib.<T extends TdApi.Object>
CompletableFuture<Response<T>>sendAsync
(TdApi.Function<T> query) Sends a request to the TDLib asynchronously.<T extends TdApi.Object>
TsendSync
(TdApi.Function<T> query) Deprecated.Because of this method throws a RuntimeException when we get an error from TDLib.<T extends TdApi.Object>
voidsendWithCallback
(TdApi.Function<T> query, QueryResultHandler<T> resultHandler) Sends a request to the TDLib with callback.
-
Constructor Details
-
TelegramClient
public TelegramClient(TelegramProperties properties, Collection<UpdateNotificationListener<?>> notificationHandlers, Client.ResultHandler defaultHandler, ClientAuthorizationState clientAuthorizationState) - Parameters:
properties
- TDlib client propertiesnotificationHandlers
- registered notifications handlersdefaultHandler
- default handler for unhandled eventsclientAuthorizationState
- authorization state of the client
-
-
Method Details
-
sendSync
Deprecated.Because of this method throws a RuntimeException when we get an error from TDLib. It's better to return a value object. Can be replaced bytelegramClient.send(TdApi.Function<T> query)
Sends a request to the TDLib.- Parameters:
query
- object representing a query to the TDLib.- Returns:
- response from TDLib.
- Throws:
NullPointerException
- if query is null.TelegramClientTdApiException
- for TDLib request timeout or returnedTdApi.Error
.
-
send
Sends a request to the TDLib.- Parameters:
query
- object representing a query to the TDLib.- Returns:
Response<T extends TdApi.Object>
response.- Throws:
NullPointerException
- if query is null.
-
sendAsync
Sends a request to the TDLib asynchronously. If this stage completes exceptionally you can handle causeTelegramClientTdApiException
- Parameters:
query
- object representing a query to the TDLib.- Returns:
CompletableFuture<Response>
response from TDLib.- Throws:
NullPointerException
- if query is null.
-
sendWithCallback
public <T extends TdApi.Object> void sendWithCallback(TdApi.Function<T> query, QueryResultHandler<T> resultHandler) Sends a request to the TDLib with callback.- Type Parameters:
T
- The object type that is returned by the function- Parameters:
query
- object representing a query to the TDLibresultHandler
- Result handler for results of queries with callback to TDLib
-