Improve example result handler
This commit is contained in:
parent
250dfa3a89
commit
4999183324
@ -152,19 +152,16 @@ public final class Example {
|
||||
long chatId = update.message.chatId;
|
||||
|
||||
// Get the chat title
|
||||
client.send(new TdApi.GetChat(chatId))
|
||||
.thenApply(chatIdResult -> {
|
||||
// Get the chat name
|
||||
return chatIdResult.title;
|
||||
})
|
||||
.whenComplete((chatTitle, error) -> {
|
||||
client.send(new TdApi.GetChat(chatId)).whenCompleteAsync((chatIdResult, error) -> {
|
||||
if (error != null) {
|
||||
// Print error
|
||||
System.err.printf("Can't get chat title of chat %s%n", chatId);
|
||||
error.printStackTrace(System.err);
|
||||
} else {
|
||||
// Get the chat name
|
||||
String title = chatIdResult.title;
|
||||
// Print the message
|
||||
System.out.printf("Received new message from chat %s (%s): %s%n", chatTitle, chatId, text);
|
||||
System.out.printf("Received new message from chat %s (%s): %s%n", title, chatId, text);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user