rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.79k stars 1.23k forks source link

SetWebhook with custom certificate is broken in 7.x #1366

Closed valkuc closed 4 months ago

valkuc commented 5 months ago

Describe the bug OkHttpTelegramClient does not have special implementation for SetWebhook, as result webhook with custom cert is sent as JSON without file content itself.

To Reproduce

try (var is = new ByteArrayInputStream("pem.file")) {
    var webhook = SetWebhook.builder()
            .certificate(new InputFile(is, "certificate"))
            .url("https://url")
            .build();
    new OkHttpTelegramClient("TOKEN").execute(webhook);
} catch (TelegramApiException | IOException e) {
    throw new RuntimeException("Failed to setup webhook", e);
}

or, just try your own example https://github.com/rubenlagus/TelegramBotsExample/blob/master/src/main/java/org/telegram/updateshandlers/WebHookExampleHandlers.java but add custom certificate to SetWebhook.

Expected behavior Certificate file should be sent.

aNNiMON commented 5 months ago

@valkuc try to set webhook option useHttps to true. According to:

https://github.com/rubenlagus/TelegramBots/blame/31832c85d2e58e1f034895390e0d0dfeb2bd58d7/telegrambots-webhook/src/main/java/org/telegram/telegrambots/webhook/TelegramBotsWebhookApplication.java#L159-L169

the SSL plugin for Javalin is only initialized when this flag is enabled.

try (final var webhookApplication = new TelegramBotsWebhookApplication(WebhookOptions.builder().useHttps(true).enableRequestLogging(true).build())) {
valkuc commented 5 months ago

@valkuc try to set webhook option useHttps to true. According to:

https://github.com/rubenlagus/TelegramBots/blame/31832c85d2e58e1f034895390e0d0dfeb2bd58d7/telegrambots-webhook/src/main/java/org/telegram/telegrambots/webhook/TelegramBotsWebhookApplication.java#L159-L169

the SSL plugin for Javalin is only initialized when this flag is enabled.

try (final var webhookApplication = new TelegramBotsWebhookApplication(WebhookOptions.builder().useHttps(true).enableRequestLogging(true).build())) {

I'm not using Javalin part of the project. And I don't need HTTP/HTTPS server functionality (i.e. I don't want for TelegramBots lib to serve HTTPS requests for my bot). I just need the library to make call to Telegram servers and set up a webhook. The only dependency I use is a telegrambots-client. That's it.