From 91f7ae244072ef5de4a3d39686b0c88ad46b975b Mon Sep 17 00:00:00 2001 From: ruben Date: Sun, 7 Jul 2024 13:26:16 +0100 Subject: [PATCH] Fix #1320 --- .../client/okhttp/OkHttpTelegramClient.java | 14 ++++++++++---- .../telegrambots/longpolling/BotSession.java | 14 ++++++++++---- .../telegram/telegrambots/meta/TelegramUrl.java | 3 ++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/telegrambots-client/src/main/java/org/telegram/telegrambots/client/okhttp/OkHttpTelegramClient.java b/telegrambots-client/src/main/java/org/telegram/telegrambots/client/okhttp/OkHttpTelegramClient.java index 65180a9d7..76b069750 100644 --- a/telegrambots-client/src/main/java/org/telegram/telegrambots/client/okhttp/OkHttpTelegramClient.java +++ b/telegrambots-client/src/main/java/org/telegram/telegrambots/client/okhttp/OkHttpTelegramClient.java @@ -572,14 +572,20 @@ private > Completab } private HttpUrl buildUrl(String methodPath) { - return new HttpUrl + HttpUrl.Builder builder = new HttpUrl .Builder() .scheme(telegramUrl.getSchema()) .host(telegramUrl.getHost()) .port(telegramUrl.getPort()) - .addPathSegment("bot" + botToken) - .addPathSegment(methodPath) - .build(); + .addPathSegment("bot" + botToken); + + if (telegramUrl.isTestServer()) { + builder.addPathSegment("test"); + } + + builder.addPathSegment(methodPath); + + return builder.build(); } private void addInputData(TelegramMultipartBuilder builder, String mediaField, InputMedia media, boolean addField) throws IOException { diff --git a/telegrambots-longpolling/src/main/java/org/telegram/telegrambots/longpolling/BotSession.java b/telegrambots-longpolling/src/main/java/org/telegram/telegrambots/longpolling/BotSession.java index 62e8ec18c..6edb5d975 100644 --- a/telegrambots-longpolling/src/main/java/org/telegram/telegrambots/longpolling/BotSession.java +++ b/telegrambots-longpolling/src/main/java/org/telegram/telegrambots/longpolling/BotSession.java @@ -197,13 +197,19 @@ private Request createRequest(TelegramUrl telegramUrl, BotApiMethod apiMethod @NonNull private HttpUrl buildUrl(TelegramUrl telegramUrl, String methodPath) { - return new HttpUrl + HttpUrl.Builder builder = new HttpUrl .Builder() .scheme(telegramUrl.getSchema()) .host(telegramUrl.getHost()) .port(telegramUrl.getPort()) - .addPathSegment("bot" + botToken) - .addPathSegment(methodPath) - .build(); + .addPathSegment("bot" + botToken); + + if (telegramUrl.isTestServer()) { + builder.addPathSegment("test"); + } + + builder.addPathSegment(methodPath); + + return builder.build(); } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/TelegramUrl.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/TelegramUrl.java index 5648a3763..9540a5e77 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/TelegramUrl.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/TelegramUrl.java @@ -13,6 +13,7 @@ public class TelegramUrl { private String schema; private String host; private int port; + private boolean testServer; - public static final TelegramUrl DEFAULT_URL = new TelegramUrl("https", "api.telegram.org", 443); + public static final TelegramUrl DEFAULT_URL = new TelegramUrl("https", "api.telegram.org", 443, false); }