Skip to content

Commit 9bec91c

Browse files
committed
Supported timed polls that automatically close at a certain date and time. Set up by specifying the parameter open_period or close_date in the method sendPoll
1 parent 2a78b2a commit 9bec91c

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

library/src/main/java/com/pengrad/telegrambot/request/SendPoll.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,12 @@ public SendPoll type(Poll.Type type) {
2727
return add("type", type);
2828
}
2929

30-
public SendPoll correctOptionId(int correctOptionId) {
31-
return add("correct_option_id", correctOptionId);
32-
}
33-
3430
public SendPoll allowsMultipleAnswers(boolean allowsMultipleAnswers) {
3531
return add("allows_multiple_answers", allowsMultipleAnswers);
3632
}
3733

38-
public SendPoll isClosed(boolean isClosed) {
39-
return add("is_closed", isClosed);
34+
public SendPoll correctOptionId(int correctOptionId) {
35+
return add("correct_option_id", correctOptionId);
4036
}
4137

4238
public SendPoll explanation(String explanation) {
@@ -46,4 +42,16 @@ public SendPoll explanation(String explanation) {
4642
public SendPoll explanationParseMode(ParseMode parseMode) {
4743
return add("explanation_parse_mode", parseMode);
4844
}
45+
46+
public SendPoll openPeriod(int openPeriod) {
47+
return add("open_period", openPeriod);
48+
}
49+
50+
public SendPoll closeDate(long closeDate) {
51+
return add("close_date", closeDate);
52+
}
53+
54+
public SendPoll isClosed(boolean isClosed) {
55+
return add("is_closed", isClosed);
56+
}
4957
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,9 +1672,10 @@ public void sendPoll() {
16721672
.type(Poll.Type.quiz)
16731673
.allowsMultipleAnswers(false)
16741674
.correctOptionId(1)
1675-
.isClosed(true)
1675+
.isClosed(false)
16761676
.explanation("Some __explanation__ of poll")
16771677
.explanationParseMode(ParseMode.MarkdownV2)
1678+
.openPeriod(500)
16781679
);
16791680
Poll poll = sendResponse.message().poll();
16801681
assertFalse(poll.id().isEmpty());
@@ -1690,7 +1691,7 @@ public void sendPoll() {
16901691
assertFalse(poll.allowsMultipleAnswers());
16911692
assertEquals(poll.totalVoterCount(), Integer.valueOf(0));
16921693
assertEquals(poll.correctOptionId(), Integer.valueOf(1));
1693-
assertTrue(poll.isClosed());
1694+
assertFalse(poll.isClosed());
16941695
assertEquals("Some explanation of poll", poll.explanation());
16951696
assertEquals(1, poll.explanationEntities().length);
16961697
assertEquals(MessageEntity.Type.underline, poll.explanationEntities()[0].type());
@@ -1700,6 +1701,7 @@ public void sendPoll() {
17001701
public void sendPollWithKeyboard() {
17011702
String question = "Question ?";
17021703
String[] answers = {"Answer 1", "Answer 2"};
1704+
long closeDate = System.currentTimeMillis() / 1000 + 500;
17031705
SendResponse sendResponse = bot.execute(
17041706
new SendPoll(chatId, question, answers)
17051707
.type("regular")
@@ -1709,6 +1711,7 @@ public void sendPollWithKeyboard() {
17091711
new KeyboardButton("quiz").requestPoll(new KeyboardButtonPollType(Poll.Type.quiz)),
17101712
new KeyboardButton("regular").requestPoll(new KeyboardButtonPollType("regular"))
17111713
}))
1714+
.closeDate(closeDate)
17121715
);
17131716
Poll poll = sendResponse.message().poll();
17141717
assertEquals(question, poll.question());

0 commit comments

Comments
 (0)