Skip to content

Commit 4e2e360

Browse files
committed
Add fields max_connections, allowed_updates in WebhookInfo
1 parent bd09a52 commit 4e2e360

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

library/src/main/java/com/pengrad/telegrambot/model/WebhookInfo.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.pengrad.telegrambot.model;
22

33
import java.io.Serializable;
4+
import java.util.Arrays;
45

56
/**
67
* Stas Parshin
@@ -14,6 +15,8 @@ public class WebhookInfo implements Serializable {
1415
private Integer pending_update_count;
1516
private Integer last_error_date;
1617
private String last_error_message;
18+
private Integer max_connections;
19+
private String[] allowed_updates;
1720

1821
public String url() {
1922
return url;
@@ -35,6 +38,14 @@ public String lastErrorMessage() {
3538
return last_error_message;
3639
}
3740

41+
public Integer maxConnections() {
42+
return max_connections;
43+
}
44+
45+
public String[] allowedUpdates() {
46+
return allowed_updates;
47+
}
48+
3849
@Override
3950
public boolean equals(Object o) {
4051
if (this == o) return true;
@@ -49,7 +60,12 @@ public boolean equals(Object o) {
4960
return false;
5061
if (last_error_date != null ? !last_error_date.equals(that.last_error_date) : that.last_error_date != null)
5162
return false;
52-
return last_error_message != null ? last_error_message.equals(that.last_error_message) : that.last_error_message == null;
63+
if (last_error_message != null ? !last_error_message.equals(that.last_error_message) : that.last_error_message != null)
64+
return false;
65+
if (max_connections != null ? !max_connections.equals(that.max_connections) : that.max_connections != null)
66+
return false;
67+
// Probably incorrect - comparing Object[] arrays with Arrays.equals
68+
return Arrays.equals(allowed_updates, that.allowed_updates);
5369
}
5470

5571
@Override
@@ -59,6 +75,8 @@ public int hashCode() {
5975
result = 31 * result + (pending_update_count != null ? pending_update_count.hashCode() : 0);
6076
result = 31 * result + (last_error_date != null ? last_error_date.hashCode() : 0);
6177
result = 31 * result + (last_error_message != null ? last_error_message.hashCode() : 0);
78+
result = 31 * result + (max_connections != null ? max_connections.hashCode() : 0);
79+
result = 31 * result + Arrays.hashCode(allowed_updates);
6280
return result;
6381
}
6482

@@ -70,6 +88,8 @@ public String toString() {
7088
", pending_update_count=" + pending_update_count +
7189
", last_error_date=" + last_error_date +
7290
", last_error_message='" + last_error_message + '\'' +
91+
", max_connections=" + max_connections +
92+
", allowed_updates=" + Arrays.toString(allowed_updates) +
7393
'}';
7494
}
7595
}

library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,19 +515,30 @@ public void getWebhookInfo() {
515515

516516
@Test
517517
public void setWebhook() throws IOException, InterruptedException {
518-
BaseResponse response = bot.execute(new SetWebhook().url("https://google.com").certificate(new File(certificateFile))
519-
.maxConnections(100).allowedUpdates("message", "callback_query"));
518+
String url = "https://google.com";
519+
Integer maxConnections = 100;
520+
String[] allowedUpdates = {"message", "callback_query"};
521+
BaseResponse response = bot.execute(new SetWebhook().url(url).certificate(new File(certificateFile))
522+
.maxConnections(100).allowedUpdates(allowedUpdates));
520523
assertTrue(response.isOk());
521524

522525
Thread.sleep(1000);
523526

527+
WebhookInfo webhookInfo = bot.execute(new GetWebhookInfo()).webhookInfo();
528+
assertEquals(url, webhookInfo.url());
529+
assertTrue(webhookInfo.hasCustomCertificate());
530+
assertEquals(maxConnections, webhookInfo.maxConnections());
531+
assertEquals(allowedUpdates, webhookInfo.allowedUpdates());
532+
assertNotNull(webhookInfo.lastErrorDate());
533+
assertNotNull(webhookInfo.lastErrorMessage());
534+
524535
response = bot.execute(new SetWebhook().url("https://google.com")
525536
.certificate(Files.readAllBytes(new File(certificateFile).toPath())).allowedUpdates(""));
526537
assertTrue(response.isOk());
527538

528539
Thread.sleep(1000);
529540

530-
response = bot.execute(new SetWebhook().allowedUpdates(new String[0]));
541+
response = bot.execute(new SetWebhook());
531542
assertTrue(response.isOk());
532543
}
533544

0 commit comments

Comments
 (0)