diff --git a/library/src/main/java/com/pengrad/telegrambot/model/Invoice.java b/library/src/main/java/com/pengrad/telegrambot/model/Invoice.java new file mode 100644 index 00000000..f4d69120 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/Invoice.java @@ -0,0 +1,71 @@ +package com.pengrad.telegrambot.model; + +import java.io.Serializable; + +/** + * Stas Parshin + * 24 May 2017 + */ +public class Invoice implements Serializable { + private final static long serialVersionUID = 0L; + + private String title, description, start_parameter, currency; + private Integer total_amount; + + public String title() { + return title; + } + + public String description() { + return description; + } + + public String startParameter() { + return start_parameter; + } + + public String currency() { + return currency; + } + + public Integer totalAmount() { + return total_amount; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Invoice invoice = (Invoice) o; + + if (title != null ? !title.equals(invoice.title) : invoice.title != null) return false; + if (description != null ? !description.equals(invoice.description) : invoice.description != null) return false; + if (start_parameter != null ? !start_parameter.equals(invoice.start_parameter) : invoice.start_parameter != null) + return false; + if (currency != null ? !currency.equals(invoice.currency) : invoice.currency != null) return false; + return total_amount != null ? total_amount.equals(invoice.total_amount) : invoice.total_amount == null; + + } + + @Override + public int hashCode() { + int result = title != null ? title.hashCode() : 0; + result = 31 * result + (description != null ? description.hashCode() : 0); + result = 31 * result + (start_parameter != null ? start_parameter.hashCode() : 0); + result = 31 * result + (currency != null ? currency.hashCode() : 0); + result = 31 * result + (total_amount != null ? total_amount.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "Invoice{" + + "title='" + title + '\'' + + ", description='" + description + '\'' + + ", start_parameter='" + start_parameter + '\'' + + ", currency='" + currency + '\'' + + ", total_amount=" + total_amount + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/Message.java b/library/src/main/java/com/pengrad/telegrambot/model/Message.java index 41e7bde5..1b655551 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/Message.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/Message.java @@ -29,6 +29,8 @@ public class Message implements Serializable { private Sticker sticker; private Video video; private Voice voice; + private VideoNote video_note; + private User[] new_chat_members; private String caption; private Contact contact; private Location location; @@ -44,6 +46,8 @@ public class Message implements Serializable { private Long migrate_to_chat_id; private Long migrate_from_chat_id; private Message pinned_message; + private Invoice invoice; + private SuccessfulPayment successful_payment; public Integer messageId() { return message_id; @@ -121,6 +125,14 @@ public Voice voice() { return voice; } + public VideoNote videoNote() { + return video_note; + } + + public User[] newChatMembers() { + return new_chat_members; + } + public String caption() { return caption; } @@ -137,6 +149,10 @@ public Venue venue() { return venue; } + /** + * @deprecated Replaced with new_chat_members + */ + @Deprecated public User newChatMember() { return new_chat_member; } @@ -181,6 +197,14 @@ public Message pinnedMessage() { return pinned_message; } + public Invoice invoice() { + return invoice; + } + + public SuccessfulPayment successfulPayment() { + return successful_payment; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -192,14 +216,12 @@ public boolean equals(Object o) { if (from != null ? !from.equals(message.from) : message.from != null) return false; if (date != null ? !date.equals(message.date) : message.date != null) return false; if (chat != null ? !chat.equals(message.chat) : message.chat != null) return false; - if (forward_from != null ? !forward_from.equals(message.forward_from) : message.forward_from != null) - return false; + if (forward_from != null ? !forward_from.equals(message.forward_from) : message.forward_from != null) return false; if (forward_from_chat != null ? !forward_from_chat.equals(message.forward_from_chat) : message.forward_from_chat != null) return false; if (forward_from_message_id != null ? !forward_from_message_id.equals(message.forward_from_message_id) : message.forward_from_message_id != null) return false; - if (forward_date != null ? !forward_date.equals(message.forward_date) : message.forward_date != null) - return false; + if (forward_date != null ? !forward_date.equals(message.forward_date) : message.forward_date != null) return false; if (reply_to_message != null ? !reply_to_message.equals(message.reply_to_message) : message.reply_to_message != null) return false; if (edit_date != null ? !edit_date.equals(message.edit_date) : message.edit_date != null) return false; @@ -214,6 +236,9 @@ public boolean equals(Object o) { if (sticker != null ? !sticker.equals(message.sticker) : message.sticker != null) return false; if (video != null ? !video.equals(message.video) : message.video != null) return false; if (voice != null ? !voice.equals(message.voice) : message.voice != null) return false; + if (video_note != null ? !video_note.equals(message.video_note) : message.video_note != null) return false; + // Probably incorrect - comparing Object[] arrays with Arrays.equals + if (!Arrays.equals(new_chat_members, message.new_chat_members)) return false; if (caption != null ? !caption.equals(message.caption) : message.caption != null) return false; if (contact != null ? !contact.equals(message.contact) : message.contact != null) return false; if (location != null ? !location.equals(message.location) : message.location != null) return false; @@ -238,8 +263,10 @@ public boolean equals(Object o) { return false; if (migrate_from_chat_id != null ? !migrate_from_chat_id.equals(message.migrate_from_chat_id) : message.migrate_from_chat_id != null) return false; - return pinned_message != null ? pinned_message.equals(message.pinned_message) : message.pinned_message == null; - + if (pinned_message != null ? !pinned_message.equals(message.pinned_message) : message.pinned_message != null) + return false; + if (invoice != null ? !invoice.equals(message.invoice) : message.invoice != null) return false; + return successful_payment != null ? successful_payment.equals(message.successful_payment) : message.successful_payment == null; } @Override @@ -269,6 +296,8 @@ public String toString() { ", sticker=" + sticker + ", video=" + video + ", voice=" + voice + + ", video_note=" + video_note + + ", new_chat_members=" + Arrays.toString(new_chat_members) + ", caption='" + caption + '\'' + ", contact=" + contact + ", location=" + location + @@ -284,6 +313,8 @@ public String toString() { ", migrate_to_chat_id=" + migrate_to_chat_id + ", migrate_from_chat_id=" + migrate_from_chat_id + ", pinned_message=" + pinned_message + + ", invoice=" + invoice + + ", successful_payment=" + successful_payment + '}'; } } diff --git a/library/src/main/java/com/pengrad/telegrambot/model/OrderInfo.java b/library/src/main/java/com/pengrad/telegrambot/model/OrderInfo.java new file mode 100644 index 00000000..fd057391 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/OrderInfo.java @@ -0,0 +1,63 @@ +package com.pengrad.telegrambot.model; + +import java.io.Serializable; + +/** + * Stas Parshin + * 24 May 2017 + */ +public class OrderInfo implements Serializable { + private final static long serialVersionUID = 0L; + + private String name, phone_number, email; + private ShippingAddress shipping_address; + + public String name() { + return name; + } + + public String phoneNumber() { + return phone_number; + } + + public String email() { + return email; + } + + public ShippingAddress shippingAddress() { + return shipping_address; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + OrderInfo orderInfo = (OrderInfo) o; + + if (name != null ? !name.equals(orderInfo.name) : orderInfo.name != null) return false; + if (phone_number != null ? !phone_number.equals(orderInfo.phone_number) : orderInfo.phone_number != null) return false; + if (email != null ? !email.equals(orderInfo.email) : orderInfo.email != null) return false; + return shipping_address != null ? shipping_address.equals(orderInfo.shipping_address) : orderInfo.shipping_address == null; + + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (phone_number != null ? phone_number.hashCode() : 0); + result = 31 * result + (email != null ? email.hashCode() : 0); + result = 31 * result + (shipping_address != null ? shipping_address.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "OrderInfo{" + + "name='" + name + '\'' + + ", phone_number='" + phone_number + '\'' + + ", email='" + email + '\'' + + ", shipping_address=" + shipping_address + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/PreCheckoutQuery.java b/library/src/main/java/com/pengrad/telegrambot/model/PreCheckoutQuery.java new file mode 100644 index 00000000..d956397a --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/PreCheckoutQuery.java @@ -0,0 +1,83 @@ +package com.pengrad.telegrambot.model; + +import java.io.Serializable; + +/** + * Stas Parshin + * 24 May 2017 + */ +public class PreCheckoutQuery implements Serializable { + private final static long serialVersionUID = 0L; + + private String id; + private User from; + private String currency; + private Integer total_amount; + private String invoice_payload; + private String shipping_option_id; + private OrderInfo order_info; + + public String id() { + return id; + } + + public User from() { + return from; + } + + public String currency() { + return currency; + } + + public Integer totalAmount() { + return total_amount; + } + + public String invoicePayload() { + return invoice_payload; + } + + public String shippingOptionId() { + return shipping_option_id; + } + + public OrderInfo orderInfo() { + return order_info; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + PreCheckoutQuery that = (PreCheckoutQuery) o; + + if (id != null ? !id.equals(that.id) : that.id != null) return false; + if (from != null ? !from.equals(that.from) : that.from != null) return false; + if (currency != null ? !currency.equals(that.currency) : that.currency != null) return false; + if (total_amount != null ? !total_amount.equals(that.total_amount) : that.total_amount != null) return false; + if (invoice_payload != null ? !invoice_payload.equals(that.invoice_payload) : that.invoice_payload != null) + return false; + if (shipping_option_id != null ? !shipping_option_id.equals(that.shipping_option_id) : that.shipping_option_id != null) + return false; + return order_info != null ? order_info.equals(that.order_info) : that.order_info == null; + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + @Override + public String toString() { + return "PreCheckoutQuery{" + + "id='" + id + '\'' + + ", from=" + from + + ", currency='" + currency + '\'' + + ", total_amount=" + total_amount + + ", invoice_payload='" + invoice_payload + '\'' + + ", shipping_option_id='" + shipping_option_id + '\'' + + ", order_info=" + order_info + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/ShippingAddress.java b/library/src/main/java/com/pengrad/telegrambot/model/ShippingAddress.java new file mode 100644 index 00000000..f2e5a609 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/ShippingAddress.java @@ -0,0 +1,76 @@ +package com.pengrad.telegrambot.model; + +import java.io.Serializable; + +/** + * Stas Parshin + * 24 May 2017 + */ +public class ShippingAddress implements Serializable { + private final static long serialVersionUID = 0L; + + private String country_code, state, city, street_line1, street_line2, post_code; + + public String countryCode() { + return country_code; + } + + public String state() { + return state; + } + + public String city() { + return city; + } + + public String streetLine1() { + return street_line1; + } + + public String streetLine2() { + return street_line2; + } + + public String postCode() { + return post_code; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ShippingAddress that = (ShippingAddress) o; + + if (country_code != null ? !country_code.equals(that.country_code) : that.country_code != null) return false; + if (state != null ? !state.equals(that.state) : that.state != null) return false; + if (city != null ? !city.equals(that.city) : that.city != null) return false; + if (street_line1 != null ? !street_line1.equals(that.street_line1) : that.street_line1 != null) return false; + if (street_line2 != null ? !street_line2.equals(that.street_line2) : that.street_line2 != null) return false; + return post_code != null ? post_code.equals(that.post_code) : that.post_code == null; + + } + + @Override + public int hashCode() { + int result = country_code != null ? country_code.hashCode() : 0; + result = 31 * result + (state != null ? state.hashCode() : 0); + result = 31 * result + (city != null ? city.hashCode() : 0); + result = 31 * result + (street_line1 != null ? street_line1.hashCode() : 0); + result = 31 * result + (street_line2 != null ? street_line2.hashCode() : 0); + result = 31 * result + (post_code != null ? post_code.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "ShippingAddress{" + + "country_code='" + country_code + '\'' + + ", state='" + state + '\'' + + ", city='" + city + '\'' + + ", street_line1='" + street_line1 + '\'' + + ", street_line2='" + street_line2 + '\'' + + ", post_code='" + post_code + '\'' + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/ShippingQuery.java b/library/src/main/java/com/pengrad/telegrambot/model/ShippingQuery.java new file mode 100644 index 00000000..3fc95f6a --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/ShippingQuery.java @@ -0,0 +1,61 @@ +package com.pengrad.telegrambot.model; + +import java.io.Serializable; + +/** + * Stas Parshin + * 24 May 2017 + */ +public class ShippingQuery implements Serializable { + private final static long serialVersionUID = 0L; + + private String id; + private User from; + private String invoice_payload; + private ShippingAddress shipping_address; + + public String id() { + return id; + } + + public User from() { + return from; + } + + public String invoicePayload() { + return invoice_payload; + } + + public ShippingAddress shippingAddress() { + return shipping_address; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ShippingQuery that = (ShippingQuery) o; + + if (id != null ? !id.equals(that.id) : that.id != null) return false; + if (from != null ? !from.equals(that.from) : that.from != null) return false; + if (invoice_payload != null ? !invoice_payload.equals(that.invoice_payload) : that.invoice_payload != null) + return false; + return shipping_address != null ? shipping_address.equals(that.shipping_address) : that.shipping_address == null; + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } + + @Override + public String toString() { + return "ShippingQuery{" + + "id='" + id + '\'' + + ", from=" + from + + ", invoice_payload='" + invoice_payload + '\'' + + ", shipping_address=" + shipping_address + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/SuccessfulPayment.java b/library/src/main/java/com/pengrad/telegrambot/model/SuccessfulPayment.java new file mode 100644 index 00000000..64e81c31 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/SuccessfulPayment.java @@ -0,0 +1,92 @@ +package com.pengrad.telegrambot.model; + +import java.io.Serializable; + +/** + * Stas Parshin + * 24 May 2017 + */ +public class SuccessfulPayment implements Serializable { + private final static long serialVersionUID = 0L; + + private String currency; + private Integer total_amount; + private String invoice_payload; + private String shipping_option_id; + private OrderInfo order_info; + private String telegram_payment_charge_id; + private String provider_payment_charge_id; + + public String currency() { + return currency; + } + + public Integer totalAmount() { + return total_amount; + } + + public String invoicePayload() { + return invoice_payload; + } + + public String shippingOptionId() { + return shipping_option_id; + } + + public OrderInfo orderInfo() { + return order_info; + } + + public String telegramPaymentChargeId() { + return telegram_payment_charge_id; + } + + public String providerPaymentChargeId() { + return provider_payment_charge_id; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + SuccessfulPayment that = (SuccessfulPayment) o; + + if (currency != null ? !currency.equals(that.currency) : that.currency != null) return false; + if (total_amount != null ? !total_amount.equals(that.total_amount) : that.total_amount != null) return false; + if (invoice_payload != null ? !invoice_payload.equals(that.invoice_payload) : that.invoice_payload != null) + return false; + if (shipping_option_id != null ? !shipping_option_id.equals(that.shipping_option_id) : that.shipping_option_id != null) + return false; + if (order_info != null ? !order_info.equals(that.order_info) : that.order_info != null) return false; + if (telegram_payment_charge_id != null ? !telegram_payment_charge_id.equals(that.telegram_payment_charge_id) : that.telegram_payment_charge_id != null) + return false; + return provider_payment_charge_id != null ? provider_payment_charge_id.equals(that.provider_payment_charge_id) : that.provider_payment_charge_id == null; + + } + + @Override + public int hashCode() { + int result = currency != null ? currency.hashCode() : 0; + result = 31 * result + (total_amount != null ? total_amount.hashCode() : 0); + result = 31 * result + (invoice_payload != null ? invoice_payload.hashCode() : 0); + result = 31 * result + (shipping_option_id != null ? shipping_option_id.hashCode() : 0); + result = 31 * result + (order_info != null ? order_info.hashCode() : 0); + result = 31 * result + (telegram_payment_charge_id != null ? telegram_payment_charge_id.hashCode() : 0); + result = 31 * result + (provider_payment_charge_id != null ? provider_payment_charge_id.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "SuccessfulPayment{" + + "currency='" + currency + '\'' + + ", total_amount=" + total_amount + + ", invoice_payload='" + invoice_payload + '\'' + + ", shipping_option_id='" + shipping_option_id + '\'' + + ", order_info=" + order_info + + ", telegram_payment_charge_id='" + telegram_payment_charge_id + '\'' + + ", provider_payment_charge_id='" + provider_payment_charge_id + '\'' + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/Update.java b/library/src/main/java/com/pengrad/telegrambot/model/Update.java index 17bc1e44..d20770c1 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/Update.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/Update.java @@ -17,6 +17,8 @@ public class Update implements Serializable { private InlineQuery inline_query; private ChosenInlineResult chosen_inline_result; private CallbackQuery callback_query; + private ShippingQuery shipping_query; + private PreCheckoutQuery pre_checkout_query; public Integer updateId() { return update_id; @@ -50,6 +52,14 @@ public CallbackQuery callbackQuery() { return callback_query; } + public ShippingQuery shippingQuery() { + return shipping_query; + } + + public PreCheckoutQuery preCheckoutQuery() { + return pre_checkout_query; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -61,16 +71,17 @@ 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; - return callback_query != null ? callback_query.equals(update.callback_query) : update.callback_query == null; - + if (callback_query != null ? !callback_query.equals(update.callback_query) : update.callback_query != null) + return false; + if (shipping_query != null ? !shipping_query.equals(update.shipping_query) : update.shipping_query != null) + return false; + return pre_checkout_query != null ? pre_checkout_query.equals(update.pre_checkout_query) : update.pre_checkout_query == null; } @Override @@ -89,6 +100,8 @@ public String toString() { ", inline_query=" + inline_query + ", chosen_inline_result=" + chosen_inline_result + ", callback_query=" + callback_query + + ", shipping_query=" + shipping_query + + ", pre_checkout_query=" + pre_checkout_query + '}'; } } diff --git a/library/src/main/java/com/pengrad/telegrambot/model/User.java b/library/src/main/java/com/pengrad/telegrambot/model/User.java index 4c61af2f..c3630b0b 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/User.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/User.java @@ -13,6 +13,7 @@ public class User implements Serializable { private String first_name; private String last_name; private String username; + private String language_code; public Integer id() { return id; @@ -30,6 +31,10 @@ public String username() { return username; } + public String languageCode() { + return language_code; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -41,8 +46,7 @@ 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 true; + return language_code != null ? language_code.equals(user.language_code) : user.language_code == null; } @Override @@ -57,6 +61,7 @@ public String toString() { ", first_name='" + first_name + '\'' + ", last_name='" + last_name + '\'' + ", username='" + username + '\'' + + ", language_code='" + language_code + '\'' + '}'; } } \ No newline at end of file diff --git a/library/src/main/java/com/pengrad/telegrambot/model/VideoNote.java b/library/src/main/java/com/pengrad/telegrambot/model/VideoNote.java new file mode 100644 index 00000000..9a486375 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/model/VideoNote.java @@ -0,0 +1,67 @@ +package com.pengrad.telegrambot.model; + +import java.io.Serializable; + +/** + * Stas Parshin + * 23 May 2017 + */ +public class VideoNote implements Serializable { + private final static long serialVersionUID = 0L; + + private String file_id; + private Integer length; + private Integer duration; + private PhotoSize thumb; + private Integer file_size; + + public String fileId() { + return file_id; + } + + public Integer length() { + return length; + } + + public Integer duration() { + return duration; + } + + public PhotoSize thumb() { + return thumb; + } + + public Integer fileSize() { + return file_size; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + VideoNote videoNote = (VideoNote) o; + + if (file_id != null ? !file_id.equals(videoNote.file_id) : videoNote.file_id != null) return false; + if (length != null ? !length.equals(videoNote.length) : videoNote.length != null) return false; + if (duration != null ? !duration.equals(videoNote.duration) : videoNote.duration != null) return false; + if (thumb != null ? !thumb.equals(videoNote.thumb) : videoNote.thumb != null) return false; + return file_size != null ? file_size.equals(videoNote.file_size) : videoNote.file_size == null; + } + + @Override + public int hashCode() { + return file_id != null ? file_id.hashCode() : 0; + } + + @Override + public String toString() { + return "VideoNote{" + + "file_id='" + file_id + '\'' + + ", length=" + length + + ", duration=" + duration + + ", thumb=" + thumb + + ", file_size=" + file_size + + '}'; + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/model/request/ChatAction.java b/library/src/main/java/com/pengrad/telegrambot/model/request/ChatAction.java index ca2776d5..af6cc89a 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/request/ChatAction.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/request/ChatAction.java @@ -5,5 +5,6 @@ * 10/21/15. */ public enum ChatAction { - typing, upload_photo, record_video, upload_video, record_audio, upload_audio, upload_document, find_location + typing, upload_photo, record_video, upload_video, record_audio, upload_audio, upload_document, find_location, + record_video_note, upload_video_note } diff --git a/library/src/main/java/com/pengrad/telegrambot/model/request/InlineKeyboardButton.java b/library/src/main/java/com/pengrad/telegrambot/model/request/InlineKeyboardButton.java index 4b01141b..de0988d9 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/request/InlineKeyboardButton.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/request/InlineKeyboardButton.java @@ -15,6 +15,9 @@ public class InlineKeyboardButton implements Serializable { private String switch_inline_query; private String switch_inline_query_current_chat; private String callback_game; + private Boolean pay; + + //todo can use only one optional field, make different constructors or static methods public InlineKeyboardButton(String text) { this.text = text; @@ -44,4 +47,9 @@ public InlineKeyboardButton callbackGame(String callbackGame) { callback_game = callbackGame; return this; } + + public InlineKeyboardButton pay() { + this.pay = true; + return this; + } } diff --git a/library/src/main/java/com/pengrad/telegrambot/model/request/InlineQueryResultGif.java b/library/src/main/java/com/pengrad/telegrambot/model/request/InlineQueryResultGif.java index fc47994a..a0116a91 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/request/InlineQueryResultGif.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/request/InlineQueryResultGif.java @@ -14,6 +14,7 @@ public class InlineQueryResultGif extends InlineQueryResult { + + public AnswerPreCheckoutQuery(String preCheckoutQueryId) { + super(BaseResponse.class); + add("pre_checkout_query_id", preCheckoutQueryId).add("ok", true); + } + + public AnswerPreCheckoutQuery(String preCheckoutQueryId, String errorMessage) { + super(BaseResponse.class); + add("pre_checkout_query_id", preCheckoutQueryId).add("ok", false).add("error_message", errorMessage); + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/request/AnswerShippingQuery.java b/library/src/main/java/com/pengrad/telegrambot/request/AnswerShippingQuery.java new file mode 100644 index 00000000..6bca9b0f --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/AnswerShippingQuery.java @@ -0,0 +1,24 @@ +package com.pengrad.telegrambot.request; + +import com.google.gson.Gson; +import com.pengrad.telegrambot.model.request.ShippingOption; +import com.pengrad.telegrambot.response.BaseResponse; + +/** + * Stas Parshin + * 25 May 2017 + */ +public class AnswerShippingQuery extends BaseRequest { + + private static Gson gson = new Gson(); + + public AnswerShippingQuery(String shippingQueryId, ShippingOption... shippingOptions) { + super(BaseResponse.class); + add("shipping_query_id", shippingQueryId).add("ok", true).add("shipping_options", gson.toJson(shippingOptions)); + } + + public AnswerShippingQuery(String shippingQueryId, String errorMessage) { + super(BaseResponse.class); + add("shipping_query_id", shippingQueryId).add("ok", false).add("error_message", errorMessage); + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/request/DeleteMessage.java b/library/src/main/java/com/pengrad/telegrambot/request/DeleteMessage.java new file mode 100644 index 00000000..db33176d --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/DeleteMessage.java @@ -0,0 +1,15 @@ +package com.pengrad.telegrambot.request; + +import com.pengrad.telegrambot.response.BaseResponse; + +/** + * Stas Parshin + * 22 May 2017 + */ +public class DeleteMessage extends BaseRequest { + + public DeleteMessage(Object chatId, int messageId) { + super(BaseResponse.class); + add("chat_id", chatId).add("message_id", messageId); + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/request/SendChatAction.java b/library/src/main/java/com/pengrad/telegrambot/request/SendChatAction.java index 20143814..e910e106 100644 --- a/library/src/main/java/com/pengrad/telegrambot/request/SendChatAction.java +++ b/library/src/main/java/com/pengrad/telegrambot/request/SendChatAction.java @@ -1,5 +1,6 @@ package com.pengrad.telegrambot.request; +import com.pengrad.telegrambot.model.request.ChatAction; import com.pengrad.telegrambot.response.BaseResponse; /** @@ -12,4 +13,9 @@ public SendChatAction(Object chatId, String action) { super(BaseResponse.class); add("chat_id", chatId).add("action", action); } + + public SendChatAction(Object chatId, ChatAction action) { + super(BaseResponse.class); + add("chat_id", chatId).add("action", action.name()); + } } diff --git a/library/src/main/java/com/pengrad/telegrambot/request/SendInvoice.java b/library/src/main/java/com/pengrad/telegrambot/request/SendInvoice.java new file mode 100644 index 00000000..0581014a --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/SendInvoice.java @@ -0,0 +1,57 @@ +package com.pengrad.telegrambot.request; + +import com.google.gson.Gson; +import com.pengrad.telegrambot.model.request.LabeledPrice; + +/** + * Stas Parshin + * 24 May 2017 + */ +public class SendInvoice extends AbstractSendRequest { + + // todo remove gson + private static Gson gson = new Gson(); + + public SendInvoice(Integer chatId, String title, String description, String payload, String providerToken, + String startParameter, String currency, LabeledPrice... prices) { + super(chatId); + add("title", title).add("description", description).add("payload", payload).add("provider_token", providerToken) + .add("start_parameter", startParameter).add("currency", currency).add("prices", gson.toJson(prices)); + } + + public SendInvoice photoUrl(String photoUrl) { + return add("photo_url", photoUrl); + } + + public SendInvoice photoSize(Integer photoSize) { + return add("photo_size", photoSize); + } + + public SendInvoice photoWidth(Integer photoWidth) { + return add("photo_width", photoWidth); + } + + public SendInvoice photoHeight(Integer photoHeight) { + return add("photo_height", photoHeight); + } + + public SendInvoice needName(boolean needName) { + return add("need_name", needName); + } + + public SendInvoice needPhoneNumber(boolean needPhoneNumber) { + return add("need_phone_number", needPhoneNumber); + } + + public SendInvoice needEmail(boolean needEmail) { + return add("need_email", needEmail); + } + + public SendInvoice needShippingAddress(boolean needShippingAddress) { + return add("need_shipping_address", needShippingAddress); + } + + public SendInvoice isFlexible(boolean isFlexible) { + return add("is_flexible", isFlexible); + } +} diff --git a/library/src/main/java/com/pengrad/telegrambot/request/SendVideoNote.java b/library/src/main/java/com/pengrad/telegrambot/request/SendVideoNote.java new file mode 100644 index 00000000..f618ec27 --- /dev/null +++ b/library/src/main/java/com/pengrad/telegrambot/request/SendVideoNote.java @@ -0,0 +1,45 @@ +package com.pengrad.telegrambot.request; + +import java.io.File; + +/** + * Stas Parshin + * 24 May 2017 + */ +public class SendVideoNote extends AbstractMultipartRequest { + + public SendVideoNote(Object chatId, String videoNote) { + super(chatId, videoNote); + } + + public SendVideoNote(Object chatId, File videoNote) { + super(chatId, videoNote); + } + + public SendVideoNote(Object chatId, byte[] videoNote) { + super(chatId, videoNote); + } + + public SendVideoNote duration(int duration) { + return add("duration", duration); + } + + public SendVideoNote length(int length) { + return add("length", length); + } + + @Override + protected String getFileParamName() { + return "video_note"; + } + + @Override + public String getContentType() { + return ContentTypes.VIDEO_MIME_TYPE; + } + + @Override + protected String getDefaultFileName() { + return ContentTypes.VIDEO_FILE_NAME; + } +} diff --git a/library/src/test/java/com/pengrad/telegrambot/ChatMemberTest.java b/library/src/test/java/com/pengrad/telegrambot/ChatMemberTest.java index 3b2dd8d4..7256c8a1 100644 --- a/library/src/test/java/com/pengrad/telegrambot/ChatMemberTest.java +++ b/library/src/test/java/com/pengrad/telegrambot/ChatMemberTest.java @@ -13,7 +13,7 @@ public class ChatMemberTest { public static void check(ChatMember chatMember) { assertNotNull(chatMember.user()); assertNotNull(chatMember.status()); - UserTest.checkUser(chatMember.user()); + UserTest.checkUser(chatMember.user(), chatMember.status() == ChatMember.Status.creator); } diff --git a/library/src/test/java/com/pengrad/telegrambot/InvoiceCheck.java b/library/src/test/java/com/pengrad/telegrambot/InvoiceCheck.java new file mode 100644 index 00000000..a3390b2a --- /dev/null +++ b/library/src/test/java/com/pengrad/telegrambot/InvoiceCheck.java @@ -0,0 +1,21 @@ +package com.pengrad.telegrambot; + +import com.pengrad.telegrambot.model.Invoice; + +import static org.junit.Assert.assertNotNull; + +/** + * Stas Parshin + * 25 May 2017 + */ +public class InvoiceCheck { + + public static void check(Invoice invoice) { + assertNotNull(invoice.title()); + assertNotNull(invoice.description()); + assertNotNull(invoice.startParameter()); + assertNotNull(invoice.currency()); + assertNotNull(invoice.totalAmount()); + } + +} diff --git a/library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java b/library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java index 61fa4db4..18a82ff1 100644 --- a/library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java +++ b/library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java @@ -64,7 +64,7 @@ public void getMe() { @Test public void getUpdates() { - GetUpdatesResponse response = bot.execute(new GetUpdates().offset(279824711).allowedUpdates("callback_query")); + GetUpdatesResponse response = bot.execute(new GetUpdates().allowedUpdates("")); System.out.println(response); } @@ -274,4 +274,117 @@ public void sendGame() { SendResponse response = bot.execute(new SendGame(chatId, "pengrad_test_game")); MessageTest.checkGameMessage(response.message()); } + + @Test + public void deleteMessage() { + Message message = bot.execute(new SendMessage(chatId, "message for delete")).message(); + BaseResponse response = bot.execute(new DeleteMessage(chatId, message.messageId())); + assertTrue(response.isOk()); + } + + @Test + public void sendChatAction() { + assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.typing)).isOk()); + assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.upload_photo)).isOk()); + assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.record_video)).isOk()); + assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.upload_video)).isOk()); + assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.record_audio)).isOk()); + assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.upload_audio)).isOk()); + assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.upload_document)).isOk()); + assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.find_location)).isOk()); + assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.record_video_note)).isOk()); + assertTrue(bot.execute(new SendChatAction(chatId, ChatAction.upload_video_note)).isOk()); + } + + @Test + public void sendVideoNote() { + SendResponse response = bot.execute(new SendVideoNote(chatId, "DQADAgADmQADYgwpSbum1JrxPsbmAg")); + VideoNoteCheck.check(response.message().videoNote()); + } + + @Test + public void sendVideoNoteFile() { + SendResponse response = bot.execute(new SendVideoNote(chatId, new File(videoFile)).length(20).duration(30)); + VideoNoteCheck.check(response.message().videoNote(), true); + } + + @Test + public void sendInvoice() { + SendResponse response = bot.execute(new SendInvoice(chatId, "title", "desc", "my_payload", + "284685063:TEST:NThlNWQ3NDk0ZDQ5", "my_start_param", "USD", new LabeledPrice("label", 200)) + .needPhoneNumber(true) + .needShippingAddress(true) + .isFlexible(true) + .replyMarkup(new InlineKeyboardMarkup(new InlineKeyboardButton[]{ + new InlineKeyboardButton("just pay").pay(), + new InlineKeyboardButton("google it").url("www.google.com") + + })) + ); + InvoiceCheck.check(response.message().invoice()); + } + + @Test + public void answerShippingQuery() { + ShippingQuery shippingQuery = getLastShippingQuery(); + if (shippingQuery == null) return; + + String shippingQueryId = shippingQuery.id(); + BaseResponse response = bot.execute(new AnswerShippingQuery(shippingQueryId, + new ShippingOption("1", "VNPT", new LabeledPrice("delivery", 100), new LabeledPrice("tips", 50)), + new ShippingOption("2", "FREE", new LabeledPrice("free delivery", 0)) + )); + } + + @Test + public void answerShippingQueryError() { + ShippingQuery shippingQuery = getLastShippingQuery(); + if (shippingQuery == null) return; + + String shippingQueryId = shippingQuery.id(); + BaseResponse response = bot.execute(new AnswerShippingQuery(shippingQueryId, "cant delivery so far")); + } + + private ShippingQuery getLastShippingQuery() { + GetUpdatesResponse updatesResponse = bot.execute(new GetUpdates()); + List updates = updatesResponse.updates(); + Collections.reverse(updates); + for (Update update : updates) { + if (update.shippingQuery() != null) { + return update.shippingQuery(); + } + } + return null; + } + + @Test + public void answerPreCheckoutQuery() { + PreCheckoutQuery preCheckoutQuery = getLastPreCheckoutQuery(); + if (preCheckoutQuery == null) return; + + String preCheckoutQueryId = preCheckoutQuery.id(); + BaseResponse response = bot.execute(new AnswerPreCheckoutQuery(preCheckoutQueryId)); + } + + @Test + public void answerPreCheckoutQueryError() { + PreCheckoutQuery preCheckoutQuery = getLastPreCheckoutQuery(); + if (preCheckoutQuery == null) return; + + String preCheckoutQueryId = preCheckoutQuery.id(); + BaseResponse response = bot.execute(new AnswerPreCheckoutQuery(preCheckoutQueryId, "cant sell to you")); + } + + private PreCheckoutQuery getLastPreCheckoutQuery() { + GetUpdatesResponse updatesResponse = bot.execute(new GetUpdates()); + List updates = updatesResponse.updates(); + Collections.reverse(updates); + for (Update update : updates) { + if (update.preCheckoutQuery() != null) { + return update.preCheckoutQuery(); + } + } + return null; + } + } diff --git a/library/src/test/java/com/pengrad/telegrambot/UserTest.java b/library/src/test/java/com/pengrad/telegrambot/UserTest.java index d5d61928..491858d6 100644 --- a/library/src/test/java/com/pengrad/telegrambot/UserTest.java +++ b/library/src/test/java/com/pengrad/telegrambot/UserTest.java @@ -12,9 +12,17 @@ public class UserTest { public static void checkUser(User user) { + checkUser(user, false); + } + + public static void checkUser(User user, boolean full) { assertNotNull(user.id()); assertNotNull(user.firstName()); assertNotNull(user.username()); + if (full) { + assertNotNull(user.lastName()); + assertNotNull(user.languageCode()); + } } } diff --git a/library/src/test/java/com/pengrad/telegrambot/VideoNoteCheck.java b/library/src/test/java/com/pengrad/telegrambot/VideoNoteCheck.java new file mode 100644 index 00000000..b7f2c6a1 --- /dev/null +++ b/library/src/test/java/com/pengrad/telegrambot/VideoNoteCheck.java @@ -0,0 +1,27 @@ +package com.pengrad.telegrambot; + +import com.pengrad.telegrambot.model.VideoNote; + +import static org.junit.Assert.assertNotNull; + +/** + * Stas Parshin + * 24 May 2017 + */ +public class VideoNoteCheck { + + public static void check(VideoNote videoNote) { + check(videoNote, false); + } + + public static void check(VideoNote videoNote, boolean full) { + assertNotNull(videoNote.fileId()); + assertNotNull(videoNote.length()); + assertNotNull(videoNote.duration()); + PhotoSizeTest.checkPhotos(videoNote.thumb()); + if (full) { + assertNotNull(videoNote.fileSize()); + } + } + +}