Better Example client comments

This commit is contained in:
Andrea Cavalli 2023-09-11 01:48:16 +02:00
parent 4999183324
commit f11518af2e

View File

@ -37,7 +37,9 @@ public final class Example {
// Set the log level
Log.setLogMessageHandler(1, new Slf4JLogMessageHandler());
// Create the client factory
// Create the client factory (You can create more than one client,
// BUT only a single instance of ClientFactory is allowed globally!
// You must reuse it if you want to create more than one client!)
try (SimpleTelegramClientFactory clientFactory = new SimpleTelegramClientFactory()) {
// Obtain the API token
//
@ -49,7 +51,10 @@ public final class Example {
// Configure the client
TDLibSettings settings = TDLibSettings.create(apiToken);
// Configure the session directory
// Configure the session directory.
// After you authenticate into a session, the authentication will be skipped from the next restart!
// If you want to ensure to match the authentication supplier user/bot with your session user/bot,
// you can name your session directory after your user id, for example: "tdlib-session-id12345"
Path sessionPath = Paths.get("example-tdlight-session");
settings.setDatabaseDirectoryPath(sessionPath.resolve("data"));
settings.setDownloadedFilesDirectoryPath(sessionPath.resolve("downloads"));
@ -152,7 +157,9 @@ public final class Example {
long chatId = update.message.chatId;
// Get the chat title
client.send(new TdApi.GetChat(chatId)).whenCompleteAsync((chatIdResult, error) -> {
client.send(new TdApi.GetChat(chatId))
// Use the async completion handler, to avoid blocking the TDLib response thread accidentally
.whenCompleteAsync((chatIdResult, error) -> {
if (error != null) {
// Print error
System.err.printf("Can't get chat title of chat %s%n", chatId);