javatelegramtelegram-bot

TelegramBot. SenDocument pdf


I send file pdf through custom app telegramBot to client in telegram. Client get .txt (default type)

// file = "application/pdf;base64,JVBERi0xLjMN...DAwMT=="

private String sendFileToClient(String clientExtId, String file) {
    String fileLink;
    byte[] data = DatatypeConverter.parseBase64Binary(file);
    SendDocument sendDocument = new SendDocument(clientExtId, data);
    try {
        SendResponse execute = telegramBot.execute(sendDocument);
        Document document = execute.message().document();
        final String documentId = document.fileId();
        fileLink = getFileLink(documentId);
        return fileLink;
    } catch (Exception e) {
        ....
    }
}

public String getFileLink(String fileId) {
    GetFile getFile = new GetFile(fileId);
    GetFileResponse fileResponse = telegramBot.execute(getFile);
    File file = fileResponse.file();
    log.info("getRelativeFilePath filePath : {}", file.filePath()); // documents/file_203.txt ????
    return telegramBot.getFullFilePath(file);
}

Why my file return .txt not pdf?

when I send photo, return - photos/file_202.jpg

What problem? Pls help)

UP: compile('com.github.pengrad:java-telegram-bot-api:X.X.X')


Solution

  • solution:

    new SendDocument(clientExtId, data).fileName(fileName.pdf);