Support custom getupdates url

This commit is contained in:
Andrea Cavalli 2022-05-23 15:38:32 +02:00
parent 06b8250325
commit 96114e1f72
4 changed files with 23 additions and 3 deletions

View File

@ -2,9 +2,10 @@ package org.telegram.telegrambots.meta.generics;
/**
* @author Ruben Bermudez
* @version 1.0
* @version 1.1
* Bot options
*/
public interface BotOptions {
String getBaseUrl();
String getCustomGetUpdatesPath();
}

View File

@ -106,7 +106,11 @@ public abstract class DefaultAbsSender extends AbsSender {
}
public String getBaseUrl() {
return options.getBaseUrl() + getBotToken() + "/";
if (options.getCustomGetUpdatesPath() != null) {
return options.getBaseUrl();
} else {
return options.getBaseUrl() + getBotToken() + "/";
}
}
// Send Requests

View File

@ -22,6 +22,7 @@ public class DefaultBotOptions implements BotOptions {
private BackOff backOff;
private Integer maxWebhookConnections;
private String baseUrl;
private String customGetUpdatesPath;
private List<String> allowedUpdates;
private ProxyType proxyType;
private String proxyHost;
@ -39,6 +40,7 @@ public class DefaultBotOptions implements BotOptions {
public DefaultBotOptions() {
maxThreads = 1;
baseUrl = ApiConstants.BASE_URL;
customGetUpdatesPath = null;
httpContext = HttpClientContext.create();
proxyType = ProxyType.NO_PROXY;
getUpdatesTimeout = ApiConstants.GETUPDATES_TIMEOUT;
@ -54,6 +56,14 @@ public class DefaultBotOptions implements BotOptions {
this.baseUrl = baseUrl;
}
public String getCustomGetUpdatesPath() {
return customGetUpdatesPath;
}
public void setCustomGetUpdatesPath(String customGetUpdatesPath) {
this.customGetUpdatesPath = customGetUpdatesPath;
}
public void setMaxThreads(int maxThreads) {
this.maxThreads = maxThreads;
}

View File

@ -240,7 +240,12 @@ public class DefaultBotSession implements BotSession {
request.setAllowedUpdates(options.getAllowedUpdates());
}
String url = options.getBaseUrl() + token + "/" + GetUpdates.PATH;
String url;
if (options.getCustomGetUpdatesPath() != null) {
url = options.getBaseUrl() + options.getCustomGetUpdatesPath();
} else {
url = options.getBaseUrl() + token + "/" + GetUpdates.PATH;
}
//http client
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("charset", StandardCharsets.UTF_8.name());