Skip to content

Commit 74ec386

Browse files
authored
Bot API 4.6 (#187)
* Added the ability to send non-anonymous, multiple answer, and quiz-style polls: added the parameters is_anonymous, type, allows_multiple_answers, correct_option_id, is_closed options to the method sendPoll * Added the fields total_voter_count, is_anonymous, type, allows_multiple_answers, correct_option_id to the Poll object * Added the object KeyboardButtonPollType and the field request_poll to the object KeyboardButton * Fix EditMessageMedia test, animation fileId will be changed * Fix test setChatAdministratorCustomTitle, add timeouts * Added updates about changes of user answers in non-anonymous polls, represented by the object PollAnswer and the field poll_answer in the Update object * Added more information about the bot in response to the getMe request: added the fields can_join_groups, can_read_all_group_messages and supports_inline_queries to the User object * Set write timeout to 75 secs * Added the optional field language to the MessageEntity object
1 parent bf2404c commit 74ec386

File tree

11 files changed

+284
-32
lines changed

11 files changed

+284
-32
lines changed

library/src/main/java/com/pengrad/telegrambot/TelegramBot.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
import com.pengrad.telegrambot.request.BaseRequest;
99
import com.pengrad.telegrambot.request.GetUpdates;
1010
import com.pengrad.telegrambot.response.BaseResponse;
11-
import okhttp3.Interceptor;
12-
import okhttp3.OkHttpClient;
13-
import okhttp3.logging.HttpLoggingInterceptor;
1411

1512
import java.io.InputStream;
1613
import java.net.URL;
1714
import java.net.URLConnection;
1815
import java.util.concurrent.TimeUnit;
1916

17+
import okhttp3.Interceptor;
18+
import okhttp3.OkHttpClient;
19+
import okhttp3.logging.HttpLoggingInterceptor;
20+
2021
/**
2122
* Stas Parshin
2223
* 16 October 2015
@@ -138,6 +139,7 @@ public TelegramBot build() {
138139
private static OkHttpClient client(Interceptor interceptor) {
139140
OkHttpClient.Builder builder = new OkHttpClient.Builder()
140141
.connectTimeout(75, TimeUnit.SECONDS)
142+
.writeTimeout(75, TimeUnit.SECONDS)
141143
.readTimeout(75, TimeUnit.SECONDS);
142144
if (interceptor != null) builder.addInterceptor(interceptor);
143145
return builder.build();

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public enum Type {
1919
private Integer length;
2020
private String url;
2121
private User user;
22+
private String language;
2223

2324
public Type type() {
2425
return type;
@@ -40,6 +41,10 @@ public User user() {
4041
return user;
4142
}
4243

44+
public String language() {
45+
return language;
46+
}
47+
4348
@Override
4449
public boolean equals(Object o) {
4550
if (this == o) return true;
@@ -51,8 +56,8 @@ public boolean equals(Object o) {
5156
if (offset != null ? !offset.equals(that.offset) : that.offset != null) return false;
5257
if (length != null ? !length.equals(that.length) : that.length != null) return false;
5358
if (url != null ? !url.equals(that.url) : that.url != null) return false;
54-
return user != null ? user.equals(that.user) : that.user == null;
55-
59+
if (user != null ? !user.equals(that.user) : that.user != null) return false;
60+
return language != null ? language.equals(that.language) : that.language == null;
5661
}
5762

5863
@Override
@@ -62,6 +67,7 @@ public int hashCode() {
6267
result = 31 * result + (length != null ? length.hashCode() : 0);
6368
result = 31 * result + (url != null ? url.hashCode() : 0);
6469
result = 31 * result + (user != null ? user.hashCode() : 0);
70+
result = 31 * result + (language != null ? language.hashCode() : 0);
6571
return result;
6672
}
6773

@@ -73,6 +79,7 @@ public String toString() {
7379
", length=" + length +
7480
", url='" + url + '\'' +
7581
", user=" + user +
82+
", language='" + language + '\'' +
7683
'}';
7784
}
7885
}

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,19 @@
1010
public class Poll implements Serializable {
1111
private final static long serialVersionUID = 0L;
1212

13+
public enum Type {
14+
quiz, regular
15+
}
16+
1317
private String id;
1418
private String question;
1519
private PollOption[] options;
20+
private Integer total_voter_count;
1621
private Boolean is_closed;
22+
private Boolean is_anonymous;
23+
private Type type;
24+
private Boolean allows_multiple_answers;
25+
private Integer correct_option_id;
1726

1827
public String id() {
1928
return id;
@@ -27,10 +36,30 @@ public PollOption[] options() {
2736
return options;
2837
}
2938

39+
public Integer totalVoterCount() {
40+
return total_voter_count;
41+
}
42+
3043
public Boolean isClosed() {
3144
return is_closed;
3245
}
3346

47+
public Boolean isAnonymous() {
48+
return is_anonymous;
49+
}
50+
51+
public Type type() {
52+
return type;
53+
}
54+
55+
public Boolean allowsMultipleAnswers() {
56+
return allows_multiple_answers;
57+
}
58+
59+
public Integer correctOptionId() {
60+
return correct_option_id;
61+
}
62+
3463
@Override
3564
public boolean equals(Object o) {
3665
if (this == o) return true;
@@ -42,7 +71,14 @@ public boolean equals(Object o) {
4271
if (question != null ? !question.equals(poll.question) : poll.question != null) return false;
4372
// Probably incorrect - comparing Object[] arrays with Arrays.equals
4473
if (!Arrays.equals(options, poll.options)) return false;
45-
return is_closed != null ? is_closed.equals(poll.is_closed) : poll.is_closed == null;
74+
if (total_voter_count != null ? !total_voter_count.equals(poll.total_voter_count) : poll.total_voter_count != null)
75+
return false;
76+
if (is_closed != null ? !is_closed.equals(poll.is_closed) : poll.is_closed != null) return false;
77+
if (is_anonymous != null ? !is_anonymous.equals(poll.is_anonymous) : poll.is_anonymous != null) return false;
78+
if (type != poll.type) return false;
79+
if (allows_multiple_answers != null ? !allows_multiple_answers.equals(poll.allows_multiple_answers) : poll.allows_multiple_answers != null)
80+
return false;
81+
return correct_option_id != null ? correct_option_id.equals(poll.correct_option_id) : poll.correct_option_id == null;
4682
}
4783

4884
@Override
@@ -56,7 +92,12 @@ public String toString() {
5692
"id='" + id + '\'' +
5793
", question='" + question + '\'' +
5894
", options=" + Arrays.toString(options) +
95+
", total_voter_count=" + total_voter_count +
5996
", is_closed=" + is_closed +
97+
", is_anonymous=" + is_anonymous +
98+
", type=" + type +
99+
", allows_multiple_answers=" + allows_multiple_answers +
100+
", correct_option_id=" + correct_option_id +
60101
'}';
61102
}
62103
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.pengrad.telegrambot.model;
2+
3+
import java.io.Serializable;
4+
import java.util.Arrays;
5+
6+
/**
7+
* Stas Parshin
8+
* 25 January 2020
9+
*/
10+
public class PollAnswer implements Serializable {
11+
private final static long serialVersionUID = 0L;
12+
13+
private String poll_id;
14+
private User user;
15+
private Integer[] option_ids;
16+
17+
public String pollId() {
18+
return poll_id;
19+
}
20+
21+
public User user() {
22+
return user;
23+
}
24+
25+
public Integer[] optionIds() {
26+
return option_ids;
27+
}
28+
29+
@Override
30+
public boolean equals(Object o) {
31+
if (this == o) return true;
32+
if (o == null || getClass() != o.getClass()) return false;
33+
34+
PollAnswer that = (PollAnswer) o;
35+
36+
if (poll_id != null ? !poll_id.equals(that.poll_id) : that.poll_id != null) return false;
37+
if (user != null ? !user.equals(that.user) : that.user != null) return false;
38+
// Probably incorrect - comparing Object[] arrays with Arrays.equals
39+
return Arrays.equals(option_ids, that.option_ids);
40+
}
41+
42+
@Override
43+
public int hashCode() {
44+
int result = poll_id != null ? poll_id.hashCode() : 0;
45+
result = 31 * result + (user != null ? user.hashCode() : 0);
46+
result = 31 * result + Arrays.hashCode(option_ids);
47+
return result;
48+
}
49+
50+
@Override
51+
public String toString() {
52+
return "PollAnswer{" +
53+
"poll_id='" + poll_id + '\'' +
54+
", user=" + user +
55+
", option_ids=" + Arrays.toString(option_ids) +
56+
'}';
57+
}
58+
}

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class Update implements Serializable {
2020
private ShippingQuery shipping_query;
2121
private PreCheckoutQuery pre_checkout_query;
2222
private Poll poll;
23+
private PollAnswer poll_answer;
2324

2425
public Integer updateId() {
2526
return update_id;
@@ -65,6 +66,10 @@ public Poll poll() {
6566
return poll;
6667
}
6768

69+
public PollAnswer pollAnswer() {
70+
return poll_answer;
71+
}
72+
6873
@Override
6974
public boolean equals(Object o) {
7075
if (this == o) return true;
@@ -76,10 +81,12 @@ public boolean equals(Object o) {
7681
if (message != null ? !message.equals(update.message) : update.message != null) return false;
7782
if (edited_message != null ? !edited_message.equals(update.edited_message) : update.edited_message != null)
7883
return false;
79-
if (channel_post != null ? !channel_post.equals(update.channel_post) : update.channel_post != null) return false;
84+
if (channel_post != null ? !channel_post.equals(update.channel_post) : update.channel_post != null)
85+
return false;
8086
if (edited_channel_post != null ? !edited_channel_post.equals(update.edited_channel_post) : update.edited_channel_post != null)
8187
return false;
82-
if (inline_query != null ? !inline_query.equals(update.inline_query) : update.inline_query != null) return false;
88+
if (inline_query != null ? !inline_query.equals(update.inline_query) : update.inline_query != null)
89+
return false;
8390
if (chosen_inline_result != null ? !chosen_inline_result.equals(update.chosen_inline_result) : update.chosen_inline_result != null)
8491
return false;
8592
if (callback_query != null ? !callback_query.equals(update.callback_query) : update.callback_query != null)
@@ -88,7 +95,8 @@ public boolean equals(Object o) {
8895
return false;
8996
if (pre_checkout_query != null ? !pre_checkout_query.equals(update.pre_checkout_query) : update.pre_checkout_query != null)
9097
return false;
91-
return poll != null ? poll.equals(update.poll) : update.poll == null;
98+
if (poll != null ? !poll.equals(update.poll) : update.poll != null) return false;
99+
return poll_answer != null ? poll_answer.equals(update.poll_answer) : update.poll_answer == null;
92100
}
93101

94102
@Override
@@ -110,6 +118,7 @@ public String toString() {
110118
", shipping_query=" + shipping_query +
111119
", pre_checkout_query=" + pre_checkout_query +
112120
", poll=" + poll +
121+
", poll_answer=" + poll_answer +
113122
'}';
114123
}
115124
}

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public class User implements Serializable {
1515
private String last_name;
1616
private String username;
1717
private String language_code;
18+
private Boolean can_join_groups;
19+
private Boolean can_read_all_group_messages;
20+
private Boolean supports_inline_queries;
1821

1922
public Integer id() {
2023
return id;
@@ -40,6 +43,18 @@ public String languageCode() {
4043
return language_code;
4144
}
4245

46+
public Boolean canJoinGroups() {
47+
return can_join_groups;
48+
}
49+
50+
public Boolean canReadAllGroupMessages() {
51+
return can_read_all_group_messages;
52+
}
53+
54+
public Boolean supportsInlineQueries() {
55+
return supports_inline_queries;
56+
}
57+
4358
@Override
4459
public boolean equals(Object o) {
4560
if (this == o) return true;
@@ -52,7 +67,13 @@ public boolean equals(Object o) {
5267
if (first_name != null ? !first_name.equals(user.first_name) : user.first_name != null) return false;
5368
if (last_name != null ? !last_name.equals(user.last_name) : user.last_name != null) return false;
5469
if (username != null ? !username.equals(user.username) : user.username != null) return false;
55-
return language_code != null ? language_code.equals(user.language_code) : user.language_code == null;
70+
if (language_code != null ? !language_code.equals(user.language_code) : user.language_code != null)
71+
return false;
72+
if (can_join_groups != null ? !can_join_groups.equals(user.can_join_groups) : user.can_join_groups != null)
73+
return false;
74+
if (can_read_all_group_messages != null ? !can_read_all_group_messages.equals(user.can_read_all_group_messages) : user.can_read_all_group_messages != null)
75+
return false;
76+
return supports_inline_queries != null ? supports_inline_queries.equals(user.supports_inline_queries) : user.supports_inline_queries == null;
5677
}
5778

5879
@Override
@@ -69,6 +90,9 @@ public String toString() {
6990
", last_name='" + last_name + '\'' +
7091
", username='" + username + '\'' +
7192
", language_code='" + language_code + '\'' +
93+
", can_join_groups=" + can_join_groups +
94+
", can_read_all_group_messages=" + can_read_all_group_messages +
95+
", supports_inline_queries=" + supports_inline_queries +
7296
'}';
7397
}
7498
}

library/src/main/java/com/pengrad/telegrambot/model/request/KeyboardButton.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class KeyboardButton implements Serializable {
1212
private String text;
1313
private boolean request_contact;
1414
private boolean request_location;
15+
private KeyboardButtonPollType request_poll;
1516

1617
public KeyboardButton(String text) {
1718
this.text = text;
@@ -26,4 +27,9 @@ public KeyboardButton requestContact(boolean requestContact) {
2627
request_contact = requestContact;
2728
return this;
2829
}
30+
31+
public KeyboardButton requestPoll(KeyboardButtonPollType poll) {
32+
this.request_poll = poll;
33+
return this;
34+
}
2935
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.pengrad.telegrambot.model.request;
2+
3+
import com.pengrad.telegrambot.model.*;
4+
5+
import java.io.Serializable;
6+
7+
/**
8+
* Stas Parshin
9+
* 25 January 2020
10+
*/
11+
public class KeyboardButtonPollType implements Serializable {
12+
private final static long serialVersionUID = 0L;
13+
14+
private String type;
15+
16+
public KeyboardButtonPollType() {
17+
}
18+
19+
public KeyboardButtonPollType(String type) {
20+
this.type = type;
21+
}
22+
23+
public KeyboardButtonPollType(Poll.Type type) {
24+
this(type.name());
25+
}
26+
}

0 commit comments

Comments
 (0)