Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
import com.pengrad.telegrambot.request.BaseRequest;
import com.pengrad.telegrambot.request.GetUpdates;
import com.pengrad.telegrambot.response.BaseResponse;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;

import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.concurrent.TimeUnit;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;

/**
* Stas Parshin
* 16 October 2015
Expand Down Expand Up @@ -138,6 +139,7 @@ public TelegramBot build() {
private static OkHttpClient client(Interceptor interceptor) {
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.connectTimeout(75, TimeUnit.SECONDS)
.writeTimeout(75, TimeUnit.SECONDS)
.readTimeout(75, TimeUnit.SECONDS);
if (interceptor != null) builder.addInterceptor(interceptor);
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum Type {
private Integer length;
private String url;
private User user;
private String language;

public Type type() {
return type;
Expand All @@ -40,6 +41,10 @@ public User user() {
return user;
}

public String language() {
return language;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -51,8 +56,8 @@ public boolean equals(Object o) {
if (offset != null ? !offset.equals(that.offset) : that.offset != null) return false;
if (length != null ? !length.equals(that.length) : that.length != null) return false;
if (url != null ? !url.equals(that.url) : that.url != null) return false;
return user != null ? user.equals(that.user) : that.user == null;

if (user != null ? !user.equals(that.user) : that.user != null) return false;
return language != null ? language.equals(that.language) : that.language == null;
}

@Override
Expand All @@ -62,6 +67,7 @@ public int hashCode() {
result = 31 * result + (length != null ? length.hashCode() : 0);
result = 31 * result + (url != null ? url.hashCode() : 0);
result = 31 * result + (user != null ? user.hashCode() : 0);
result = 31 * result + (language != null ? language.hashCode() : 0);
return result;
}

Expand All @@ -73,6 +79,7 @@ public String toString() {
", length=" + length +
", url='" + url + '\'' +
", user=" + user +
", language='" + language + '\'' +
'}';
}
}
43 changes: 42 additions & 1 deletion library/src/main/java/com/pengrad/telegrambot/model/Poll.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@
public class Poll implements Serializable {
private final static long serialVersionUID = 0L;

public enum Type {
quiz, regular
}

private String id;
private String question;
private PollOption[] options;
private Integer total_voter_count;
private Boolean is_closed;
private Boolean is_anonymous;
private Type type;
private Boolean allows_multiple_answers;
private Integer correct_option_id;

public String id() {
return id;
Expand All @@ -27,10 +36,30 @@ public PollOption[] options() {
return options;
}

public Integer totalVoterCount() {
return total_voter_count;
}

public Boolean isClosed() {
return is_closed;
}

public Boolean isAnonymous() {
return is_anonymous;
}

public Type type() {
return type;
}

public Boolean allowsMultipleAnswers() {
return allows_multiple_answers;
}

public Integer correctOptionId() {
return correct_option_id;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -42,7 +71,14 @@ public boolean equals(Object o) {
if (question != null ? !question.equals(poll.question) : poll.question != null) return false;
// Probably incorrect - comparing Object[] arrays with Arrays.equals
if (!Arrays.equals(options, poll.options)) return false;
return is_closed != null ? is_closed.equals(poll.is_closed) : poll.is_closed == null;
if (total_voter_count != null ? !total_voter_count.equals(poll.total_voter_count) : poll.total_voter_count != null)
return false;
if (is_closed != null ? !is_closed.equals(poll.is_closed) : poll.is_closed != null) return false;
if (is_anonymous != null ? !is_anonymous.equals(poll.is_anonymous) : poll.is_anonymous != null) return false;
if (type != poll.type) return false;
if (allows_multiple_answers != null ? !allows_multiple_answers.equals(poll.allows_multiple_answers) : poll.allows_multiple_answers != null)
return false;
return correct_option_id != null ? correct_option_id.equals(poll.correct_option_id) : poll.correct_option_id == null;
}

@Override
Expand All @@ -56,7 +92,12 @@ public String toString() {
"id='" + id + '\'' +
", question='" + question + '\'' +
", options=" + Arrays.toString(options) +
", total_voter_count=" + total_voter_count +
", is_closed=" + is_closed +
", is_anonymous=" + is_anonymous +
", type=" + type +
", allows_multiple_answers=" + allows_multiple_answers +
", correct_option_id=" + correct_option_id +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.pengrad.telegrambot.model;

import java.io.Serializable;
import java.util.Arrays;

/**
* Stas Parshin
* 25 January 2020
*/
public class PollAnswer implements Serializable {
private final static long serialVersionUID = 0L;

private String poll_id;
private User user;
private Integer[] option_ids;

public String pollId() {
return poll_id;
}

public User user() {
return user;
}

public Integer[] optionIds() {
return option_ids;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

PollAnswer that = (PollAnswer) o;

if (poll_id != null ? !poll_id.equals(that.poll_id) : that.poll_id != null) return false;
if (user != null ? !user.equals(that.user) : that.user != null) return false;
// Probably incorrect - comparing Object[] arrays with Arrays.equals
return Arrays.equals(option_ids, that.option_ids);
}

@Override
public int hashCode() {
int result = poll_id != null ? poll_id.hashCode() : 0;
result = 31 * result + (user != null ? user.hashCode() : 0);
result = 31 * result + Arrays.hashCode(option_ids);
return result;
}

@Override
public String toString() {
return "PollAnswer{" +
"poll_id='" + poll_id + '\'' +
", user=" + user +
", option_ids=" + Arrays.toString(option_ids) +
'}';
}
}
15 changes: 12 additions & 3 deletions library/src/main/java/com/pengrad/telegrambot/model/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Update implements Serializable {
private ShippingQuery shipping_query;
private PreCheckoutQuery pre_checkout_query;
private Poll poll;
private PollAnswer poll_answer;

public Integer updateId() {
return update_id;
Expand Down Expand Up @@ -65,6 +66,10 @@ public Poll poll() {
return poll;
}

public PollAnswer pollAnswer() {
return poll_answer;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -76,10 +81,12 @@ public boolean equals(Object o) {
if (message != null ? !message.equals(update.message) : update.message != null) return false;
if (edited_message != null ? !edited_message.equals(update.edited_message) : update.edited_message != null)
return false;
if (channel_post != null ? !channel_post.equals(update.channel_post) : update.channel_post != null) return false;
if (channel_post != null ? !channel_post.equals(update.channel_post) : update.channel_post != null)
return false;
if (edited_channel_post != null ? !edited_channel_post.equals(update.edited_channel_post) : update.edited_channel_post != null)
return false;
if (inline_query != null ? !inline_query.equals(update.inline_query) : update.inline_query != null) return false;
if (inline_query != null ? !inline_query.equals(update.inline_query) : update.inline_query != null)
return false;
if (chosen_inline_result != null ? !chosen_inline_result.equals(update.chosen_inline_result) : update.chosen_inline_result != null)
return false;
if (callback_query != null ? !callback_query.equals(update.callback_query) : update.callback_query != null)
Expand All @@ -88,7 +95,8 @@ public boolean equals(Object o) {
return false;
if (pre_checkout_query != null ? !pre_checkout_query.equals(update.pre_checkout_query) : update.pre_checkout_query != null)
return false;
return poll != null ? poll.equals(update.poll) : update.poll == null;
if (poll != null ? !poll.equals(update.poll) : update.poll != null) return false;
return poll_answer != null ? poll_answer.equals(update.poll_answer) : update.poll_answer == null;
}

@Override
Expand All @@ -110,6 +118,7 @@ public String toString() {
", shipping_query=" + shipping_query +
", pre_checkout_query=" + pre_checkout_query +
", poll=" + poll +
", poll_answer=" + poll_answer +
'}';
}
}
26 changes: 25 additions & 1 deletion library/src/main/java/com/pengrad/telegrambot/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class User implements Serializable {
private String last_name;
private String username;
private String language_code;
private Boolean can_join_groups;
private Boolean can_read_all_group_messages;
private Boolean supports_inline_queries;

public Integer id() {
return id;
Expand All @@ -40,6 +43,18 @@ public String languageCode() {
return language_code;
}

public Boolean canJoinGroups() {
return can_join_groups;
}

public Boolean canReadAllGroupMessages() {
return can_read_all_group_messages;
}

public Boolean supportsInlineQueries() {
return supports_inline_queries;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -52,7 +67,13 @@ public boolean equals(Object o) {
if (first_name != null ? !first_name.equals(user.first_name) : user.first_name != null) return false;
if (last_name != null ? !last_name.equals(user.last_name) : user.last_name != null) return false;
if (username != null ? !username.equals(user.username) : user.username != null) return false;
return language_code != null ? language_code.equals(user.language_code) : user.language_code == null;
if (language_code != null ? !language_code.equals(user.language_code) : user.language_code != null)
return false;
if (can_join_groups != null ? !can_join_groups.equals(user.can_join_groups) : user.can_join_groups != null)
return false;
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)
return false;
return supports_inline_queries != null ? supports_inline_queries.equals(user.supports_inline_queries) : user.supports_inline_queries == null;
}

@Override
Expand All @@ -69,6 +90,9 @@ public String toString() {
", last_name='" + last_name + '\'' +
", username='" + username + '\'' +
", language_code='" + language_code + '\'' +
", can_join_groups=" + can_join_groups +
", can_read_all_group_messages=" + can_read_all_group_messages +
", supports_inline_queries=" + supports_inline_queries +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class KeyboardButton implements Serializable {
private String text;
private boolean request_contact;
private boolean request_location;
private KeyboardButtonPollType request_poll;

public KeyboardButton(String text) {
this.text = text;
Expand All @@ -26,4 +27,9 @@ public KeyboardButton requestContact(boolean requestContact) {
request_contact = requestContact;
return this;
}

public KeyboardButton requestPoll(KeyboardButtonPollType poll) {
this.request_poll = poll;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.pengrad.telegrambot.model.request;

import com.pengrad.telegrambot.model.*;

import java.io.Serializable;

/**
* Stas Parshin
* 25 January 2020
*/
public class KeyboardButtonPollType implements Serializable {
private final static long serialVersionUID = 0L;

private String type;

public KeyboardButtonPollType() {
}

public KeyboardButtonPollType(String type) {
this.type = type;
}

public KeyboardButtonPollType(Poll.Type type) {
this(type.name());
}
}
Loading