Skip to content

Commit c3c3c70

Browse files
committed
Fix timeout and connectionPool
1 parent 1f7140f commit c3c3c70

File tree

1 file changed

+7
-10
lines changed
  • telebof/src/main/java/io/github/natanimn/telebof/requests

1 file changed

+7
-10
lines changed

telebof/src/main/java/io/github/natanimn/telebof/requests/Api.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@
99
import io.github.natanimn.telebof.exceptions.ConnectionError;
1010
import io.github.natanimn.telebof.exceptions.TelegramError;
1111
import io.github.natanimn.telebof.types.input.InputMedia;
12-
import okhttp3.RequestBody;
13-
import okhttp3.MediaType;
14-
import okhttp3.MultipartBody;
15-
import okhttp3.OkHttpClient;
16-
import okhttp3.Response;
17-
import okhttp3.ResponseBody;
18-
import okhttp3.Request;
12+
import okhttp3.*;
1913
import org.jetbrains.annotations.Nullable;
2014

2115
import java.io.File;
@@ -29,11 +23,11 @@
2923
* A class to interact with telegram server
3024
* @author Natanim
3125
* @since 3 March 2025
32-
* @version 0.9
26+
* @version 1.2.1
3327
*/
3428
public class Api {
3529

36-
protected int TIMEOUT = 120;
30+
protected int TIMEOUT = 70;
3731
private final String URL;
3832
private final String FILE_URL;
3933
private final OkHttpClient client;
@@ -43,11 +37,14 @@ public class Api {
4337

4438
public Api(String botToken, boolean useTestServer, Proxy proxy, @Nullable String localBotAPiUrl){
4539
this.botToken = botToken;
40+
4641
this.client = new OkHttpClient.Builder()
4742
.readTimeout(TIMEOUT, TimeUnit.SECONDS)
4843
.connectTimeout(TIMEOUT, TimeUnit.SECONDS)
4944
.writeTimeout(TIMEOUT, TimeUnit.SECONDS)
5045
.proxy(proxy)
46+
.retryOnConnectionFailure(true)
47+
.connectionPool(new ConnectionPool(20, 5, TimeUnit.MINUTES))
5148
.build();
5249

5350
this.builder = new Request.Builder();
@@ -56,7 +53,7 @@ public Api(String botToken, boolean useTestServer, Proxy proxy, @Nullable String
5653
if (localBotAPiUrl != null && !localBotAPiUrl.isEmpty())
5754
this.URL = localBotAPiUrl;
5855
else
59-
this.URL = "https://api.telegram.org/bot%s" + (useTestServer?"/test/%s":"/%s");
56+
this.URL = "https://api.telegram.org/bot%s" + (useTestServer ? "/test/%s" : "/%s");
6057
}
6158

6259
private RequestBody prepareRequest(AbstractBaseRequest<?, ?> baseRequest) {

0 commit comments

Comments
 (0)