Closed Mark1708 closed 2 years ago
Solved the problem by making the sendDocument
method in the TelegramBot
class
FileRequestHandler.java
public BotApiMethod<?> handle(SendMessage sendMessage, Client client) {
try {
InputFile document = fileService.generateClientDataCsv();
SendDocument sendDocument = SendDocument.builder()
.chatId(client.getChatId())
.document(document)
.caption("Список пользователей с подписками")
.parseMode(ParseMode.MARKDOWN)
.build();
telegramBot.sendDocument(sendDocument);
sendMessage.setText("Файл успешно сгенерирован");
} catch (Exception e) {
sendMessage.setText("При генерации файла произошла ошибка");
e.printStackTrace();
}
return sendMessage;
}
TelegramBot.java
public void sendDocument(SendDocument sendDocument) {
try {
execute(sendDocument);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
Hi! Please tell me what the problem is.
When trying to send a document (not empty, 250 bytes), I catch a NullPointerException. As you can see, I have done validation checks on both InputFile and SendDocument. At the same time, there is no problem with sending text messages using the execute method.
I use telegrambots-spring-boot-starter 6.1.0 and Java 8.
StackTrace