Skip to content

Commit 1e7b2e9

Browse files
committed
Bot API 9.6
- Added support for managed bots with getManagedBotToken and replaceManagedBotToken methods - Added the classes ManagedBotCreated and ManagedBotUpdated - Added the field managed_bot to Update - Added the field managed_bot_created to Message - Added the class KeyboardButtonRequestManagedBot and the field request_managed_bot to KeyboardButton - Added the class PreparedKeyboardButton and the method savePreparedKeyboardButton - Added the field can_manage_bots to User - Changed the field correct_option_id to correct_option_ids (array) in Poll - Added the fields allows_revoting, description and description_entities to Poll - Added the fields persistent_id, added_by_user, added_by_chat and addition_date to PollOption - Added the field option_persistent_ids to PollAnswer - Added the classes PollOptionAdded and PollOptionDeleted - Added the fields poll_option_added, poll_option_deleted and reply_to_poll_option_id to Message - Added the field poll_option_id to ReplyParameters - Added parameters allowsRevoting, shuffleOptions, allowAddingOptions, hideResultsUntilCloses, description, descriptionParseMode and descriptionEntities to SendPoll
1 parent c607c79 commit 1e7b2e9

19 files changed

+470
-15
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.pengrad.telegrambot.model;
2+
3+
import java.io.Serializable;
4+
import java.util.Objects;
5+
6+
public class ManagedBotCreated implements Serializable {
7+
private final static long serialVersionUID = 0L;
8+
9+
private User bot;
10+
11+
public User bot() {
12+
return bot;
13+
}
14+
15+
@Override
16+
public boolean equals(Object o) {
17+
if (this == o) return true;
18+
if (o == null || getClass() != o.getClass()) return false;
19+
ManagedBotCreated that = (ManagedBotCreated) o;
20+
return Objects.equals(bot, that.bot);
21+
}
22+
23+
@Override
24+
public int hashCode() {
25+
return Objects.hash(bot);
26+
}
27+
28+
@Override
29+
public String toString() {
30+
return "ManagedBotCreated{" +
31+
"bot=" + bot +
32+
'}';
33+
}
34+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.pengrad.telegrambot.model;
2+
3+
import java.io.Serializable;
4+
import java.util.Objects;
5+
6+
public class ManagedBotUpdated implements Serializable {
7+
private final static long serialVersionUID = 0L;
8+
9+
private User user;
10+
private User bot;
11+
12+
public User user() {
13+
return user;
14+
}
15+
16+
public User bot() {
17+
return bot;
18+
}
19+
20+
@Override
21+
public boolean equals(Object o) {
22+
if (this == o) return true;
23+
if (o == null || getClass() != o.getClass()) return false;
24+
ManagedBotUpdated that = (ManagedBotUpdated) o;
25+
return Objects.equals(user, that.user) &&
26+
Objects.equals(bot, that.bot);
27+
}
28+
29+
@Override
30+
public int hashCode() {
31+
return Objects.hash(user, bot);
32+
}
33+
34+
@Override
35+
public String toString() {
36+
return "ManagedBotUpdated{" +
37+
"user=" + user +
38+
", bot=" + bot +
39+
'}';
40+
}
41+
}

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ public class Message extends MaybeInaccessibleMessage implements Serializable {
136136
private Integer paid_star_count;
137137
private ChatOwnerLeft chat_owner_left;
138138
private ChatOwnerChanged chat_owner_changed;
139+
private ManagedBotCreated managed_bot_created;
140+
private PollOptionAdded poll_option_added;
141+
private PollOptionDeleted poll_option_deleted;
142+
private String reply_to_poll_option_id;
139143

140144
public Long messageThreadId() {
141145
return message_thread_id;
@@ -550,6 +554,22 @@ public ChatOwnerChanged chatOwnerChanged() {
550554
return chat_owner_changed;
551555
}
552556

557+
public ManagedBotCreated managedBotCreated() {
558+
return managed_bot_created;
559+
}
560+
561+
public PollOptionAdded pollOptionAdded() {
562+
return poll_option_added;
563+
}
564+
565+
public PollOptionDeleted pollOptionDeleted() {
566+
return poll_option_deleted;
567+
}
568+
569+
public String replyToPollOptionId() {
570+
return reply_to_poll_option_id;
571+
}
572+
553573
/**
554574
* Only for backwards-compatibility with MaybeInaccessibleMessage
555575
*/
@@ -681,7 +701,11 @@ public boolean equals(Object o) {
681701
Objects.equals(direct_message_price_changed, message.direct_message_price_changed) &&
682702
Objects.equals(paid_star_count, message.paid_star_count) &&
683703
Objects.equals(chat_owner_left, message.chat_owner_left) &&
684-
Objects.equals(chat_owner_changed, message.chat_owner_changed);
704+
Objects.equals(chat_owner_changed, message.chat_owner_changed) &&
705+
Objects.equals(managed_bot_created, message.managed_bot_created) &&
706+
Objects.equals(poll_option_added, message.poll_option_added) &&
707+
Objects.equals(poll_option_deleted, message.poll_option_deleted) &&
708+
Objects.equals(reply_to_poll_option_id, message.reply_to_poll_option_id);
685709
}
686710

687711
@Override
@@ -798,6 +822,10 @@ public String toString() {
798822
", paid_star_count=" + paid_star_count +
799823
", chat_owner_left=" + chat_owner_left +
800824
", chat_owner_changed=" + chat_owner_changed +
825+
", managed_bot_created=" + managed_bot_created +
826+
", poll_option_added=" + poll_option_added +
827+
", poll_option_deleted=" + poll_option_deleted +
828+
", reply_to_poll_option_id='" + reply_to_poll_option_id + '\'' +
801829
'}';
802830
}
803831
}

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

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ public enum Type {
2323
private Boolean is_anonymous;
2424
private Type type;
2525
private Boolean allows_multiple_answers;
26-
private Integer correct_option_id;
26+
private Integer[] correct_option_ids;
27+
private Boolean allows_revoting;
2728
private String explanation;
2829
private MessageEntity[] explanation_entities;
2930
private Integer open_period;
3031
private Integer close_date;
32+
private String description;
33+
private MessageEntity[] description_entities;
3134

3235
public String id() {
3336
return id;
@@ -66,7 +69,15 @@ public Boolean allowsMultipleAnswers() {
6669
}
6770

6871
public Integer correctOptionId() {
69-
return correct_option_id;
72+
return correct_option_ids != null && correct_option_ids.length > 0 ? correct_option_ids[0] : null;
73+
}
74+
75+
public Integer[] correctOptionIds() {
76+
return correct_option_ids;
77+
}
78+
79+
public Boolean allowsRevoting() {
80+
return allows_revoting;
7081
}
7182

7283
public String explanation() {
@@ -85,6 +96,14 @@ public Integer closeDate() {
8596
return close_date;
8697
}
8798

99+
public String description() {
100+
return description;
101+
}
102+
103+
public MessageEntity[] descriptionEntities() {
104+
return description_entities;
105+
}
106+
88107
@Override
89108
public boolean equals(Object o) {
90109
if (this == o) return true;
@@ -103,12 +122,15 @@ public boolean equals(Object o) {
103122
if (type != poll.type) return false;
104123
if (allows_multiple_answers != null ? !allows_multiple_answers.equals(poll.allows_multiple_answers) : poll.allows_multiple_answers != null)
105124
return false;
106-
if (correct_option_id != null ? !correct_option_id.equals(poll.correct_option_id) : poll.correct_option_id != null)
125+
if (!Arrays.equals(correct_option_ids, poll.correct_option_ids)) return false;
126+
if (allows_revoting != null ? !allows_revoting.equals(poll.allows_revoting) : poll.allows_revoting != null)
107127
return false;
108128
if (explanation != null ? !explanation.equals(poll.explanation) : poll.explanation != null) return false;
109129
if (!Arrays.equals(explanation_entities, poll.explanation_entities)) return false;
110130
if (open_period != null ? !open_period.equals(poll.open_period) : poll.open_period != null) return false;
111-
return close_date != null ? close_date.equals(poll.close_date) : poll.close_date == null;
131+
if (close_date != null ? !close_date.equals(poll.close_date) : poll.close_date != null) return false;
132+
if (description != null ? !description.equals(poll.description) : poll.description != null) return false;
133+
return Arrays.equals(description_entities, poll.description_entities);
112134
}
113135

114136
@Override
@@ -128,11 +150,14 @@ public String toString() {
128150
", is_anonymous=" + is_anonymous +
129151
", type=" + type +
130152
", allows_multiple_answers=" + allows_multiple_answers +
131-
", correct_option_id=" + correct_option_id +
153+
", correct_option_ids=" + Arrays.toString(correct_option_ids) +
154+
", allows_revoting=" + allows_revoting +
132155
", explanation='" + explanation + '\'' +
133156
", explanation_entities=" + Arrays.toString(explanation_entities) +
134157
", open_period=" + open_period +
135158
", close_date=" + close_date +
159+
", description='" + description + '\'' +
160+
", description_entities=" + Arrays.toString(description_entities) +
136161
'}';
137162
}
138163
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class PollAnswer implements Serializable {
1515
private Chat voter_chat;
1616
private User user;
1717
private Integer[] option_ids;
18+
private String[] option_persistent_ids;
1819

1920
public String pollId() {
2021
return poll_id;
@@ -32,6 +33,10 @@ public Integer[] optionIds() {
3233
return option_ids;
3334
}
3435

36+
public String[] optionPersistentIds() {
37+
return option_persistent_ids;
38+
}
39+
3540
@Override
3641
public boolean equals(Object o) {
3742
if (this == o) return true;
@@ -40,18 +45,20 @@ public boolean equals(Object o) {
4045
return Objects.equals(poll_id, that.poll_id) &&
4146
Objects.equals(voter_chat, that.voter_chat) &&
4247
Objects.equals(user, that.user) &&
43-
Arrays.equals(option_ids, that.option_ids);
48+
Arrays.equals(option_ids, that.option_ids) &&
49+
Arrays.equals(option_persistent_ids, that.option_persistent_ids);
4450
}
4551

4652
@Override
4753
public int hashCode() {
4854
int result = Objects.hash(poll_id, voter_chat, user);
4955
result = 31 * result + Arrays.hashCode(option_ids);
56+
result = 31 * result + Arrays.hashCode(option_persistent_ids);
5057
return result;
5158
}
5259

5360
@Override
5461
public String toString() {
55-
return "PollAnswer{" + "poll_id='" + poll_id + '\'' + ", voter_chat=" + voter_chat + ", user=" + user + ", option_ids=" + Arrays.toString(option_ids) + '}';
62+
return "PollAnswer{" + "poll_id='" + poll_id + '\'' + ", voter_chat=" + voter_chat + ", user=" + user + ", option_ids=" + Arrays.toString(option_ids) + ", option_persistent_ids=" + Arrays.toString(option_persistent_ids) + '}';
5663
}
5764
}

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.Serializable;
44
import java.util.Arrays;
5+
import java.util.Objects;
56

67
/**
78
* Stas Parshin
@@ -10,9 +11,17 @@
1011
public class PollOption implements Serializable {
1112
private final static long serialVersionUID = 0L;
1213

14+
private String persistent_id;
1315
private String text;
1416
private Integer voter_count;
1517
private MessageEntity[] text_entities;
18+
private User added_by_user;
19+
private Chat added_by_chat;
20+
private Integer addition_date;
21+
22+
public String persistentId() {
23+
return persistent_id;
24+
}
1625

1726
public String text() {
1827
return text;
@@ -26,6 +35,18 @@ public MessageEntity[] textEntities() {
2635
return text_entities;
2736
}
2837

38+
public User addedByUser() {
39+
return added_by_user;
40+
}
41+
42+
public Chat addedByChat() {
43+
return added_by_chat;
44+
}
45+
46+
public Integer additionDate() {
47+
return addition_date;
48+
}
49+
2950
@Override
3051
public boolean equals(Object o) {
3152
if (this == o) return true;
@@ -35,23 +56,35 @@ public boolean equals(Object o) {
3556

3657
if (!Arrays.equals(text_entities, that.text_entities)) return false;
3758

59+
if (!Objects.equals(persistent_id, that.persistent_id)) return false;
3860
if (text != null ? !text.equals(that.text) : that.text != null) return false;
39-
return voter_count != null ? voter_count.equals(that.voter_count) : that.voter_count == null;
61+
if (voter_count != null ? !voter_count.equals(that.voter_count) : that.voter_count != null) return false;
62+
if (!Objects.equals(added_by_user, that.added_by_user)) return false;
63+
if (!Objects.equals(added_by_chat, that.added_by_chat)) return false;
64+
return Objects.equals(addition_date, that.addition_date);
4065
}
4166

4267
@Override
4368
public int hashCode() {
44-
int result = text != null ? text.hashCode() : 0;
69+
int result = persistent_id != null ? persistent_id.hashCode() : 0;
70+
result = 31 * result + (text != null ? text.hashCode() : 0);
4571
result = 31 * result + (voter_count != null ? voter_count.hashCode() : 0);
72+
result = 31 * result + (added_by_user != null ? added_by_user.hashCode() : 0);
73+
result = 31 * result + (added_by_chat != null ? added_by_chat.hashCode() : 0);
74+
result = 31 * result + (addition_date != null ? addition_date.hashCode() : 0);
4675
return result;
4776
}
4877

4978
@Override
5079
public String toString() {
5180
return "PollOption{" +
52-
"text='" + text + '\'' +
81+
"persistent_id='" + persistent_id + '\'' +
82+
", text='" + text + '\'' +
5383
", voter_count=" + voter_count +
5484
", text_entities=" + Arrays.toString(text_entities) +
85+
", added_by_user=" + added_by_user +
86+
", added_by_chat=" + added_by_chat +
87+
", addition_date=" + addition_date +
5588
'}';
5689
}
5790
}

0 commit comments

Comments
 (0)