diff --git a/src/main/java/org/telegram/telegrambots/api/methods/AnswerCallbackQuery.java b/src/main/java/org/telegram/telegrambots/api/methods/AnswerCallbackQuery.java index 933a1bc2..9f7d61b6 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/AnswerCallbackQuery.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/AnswerCallbackQuery.java @@ -1,5 +1,6 @@ package org.telegram.telegrambots.api.methods; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; @@ -24,8 +25,11 @@ public class AnswerCallbackQuery extends BotApiMethod { private static final String TEXT_FIELD = "text"; private static final String SHOWALERT_FIELD = "show_alert"; + @JsonProperty(CALLBACKQUERYID_FIELD) private String callbackQueryId; ///< Unique identifier for the query to be answered + @JsonProperty(TEXT_FIELD) private String text; ///< Text of the notification. If not specified, nothing will be shown to the user + @JsonProperty(SHOWALERT_FIELD) private Boolean showAlert; ///< Optional. If true, an alert will be shown by the client instead of a notificaiton at the top of the chat screen. Defaults to false. @@ -33,6 +37,30 @@ public class AnswerCallbackQuery extends BotApiMethod { super(); } + public String getCallbackQueryId() { + return this.callbackQueryId; + } + + public void setCallbackQueryId(String callbackQueryId) { + this.callbackQueryId = callbackQueryId; + } + + public String getText() { + return this.text; + } + + public void setText(String text) { + this.text = text; + } + + public Boolean getShowAlert() { + return this.showAlert; + } + + public void setShowAlert(Boolean showAlert) { + this.showAlert = showAlert; + } + @Override public JSONObject toJson() { JSONObject jsonObject = new JSONObject(); diff --git a/src/main/java/org/telegram/telegrambots/api/objects/CallbackQuery.java b/src/main/java/org/telegram/telegrambots/api/objects/CallbackQuery.java index 13ea8a33..b0cbbc89 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/CallbackQuery.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/CallbackQuery.java @@ -51,6 +51,22 @@ public class CallbackQuery implements IBotApiObject { super(); } + public String getId() { + return this.id; + } + + public User getFrom() { + return this.from; + } + + public Message getMessage() { + return this.getMessage(); + } + + public String getInlineMessageId() { + return this.inlineMessageId; + } + public CallbackQuery(JSONObject jsonObject) { super(); this.id = jsonObject.getString(ID_FIELD); diff --git a/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/InlineKeyboardMarkup.java b/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/InlineKeyboardMarkup.java index 7531621c..90dd0ae9 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/InlineKeyboardMarkup.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/replykeyboard/InlineKeyboardMarkup.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import org.json.JSONArray; import org.json.JSONObject; +import org.telegram.telegrambots.api.objects.replykeyboard.buttons.InlineKeyboardButton; import java.io.IOException; import java.util.ArrayList; @@ -23,107 +24,42 @@ import java.util.List; */ public class InlineKeyboardMarkup implements ReplyKeyboard { - private static final String KEYBOARD_FIELD = "keyboard"; - private static final String RESIZEKEYBOARD_FIELD = "resize_keyboard"; - private static final String ONETIMEKEYBOARD_FIELD = "one_time_keyboard"; - private static final String SELECTIVE_FIELD = "selective"; + private static final String KEYBOARD_FIELD = "inline_keyboard"; @JsonProperty(KEYBOARD_FIELD) - private List> keyboard; ///< Array of button rows, each represented by an Array of Strings - @JsonProperty(RESIZEKEYBOARD_FIELD) - private Boolean resizeKeyboard; ///< Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false. - @JsonProperty(ONETIMEKEYBOARD_FIELD) - private Boolean oneTimeKeyboad; ///< Optional. Requests clients to hide the keyboard as soon as it's been used. Defaults to false. - /** - * Optional. Use this parameter if you want to show the keyboard to specific users only. - * Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's - * message is a reply (has reply_to_message_id), sender of the original message. - */ - private Boolean selective; + private List> keyboard; ///< Array of button rows, each represented by an Array of Strings public InlineKeyboardMarkup() { super(); - keyboard = new ArrayList>(); + keyboard = new ArrayList<>(); } public InlineKeyboardMarkup(JSONObject jsonObject) { super(); - this.keyboard = new ArrayList>(); - JSONArray keyboard = jsonObject.getJSONArray(KEYBOARD_FIELD); - for (int i = 0; i < keyboard.length(); i++) { - JSONArray keyboardRow = keyboard.getJSONArray(i); - List row = new ArrayList(); - for (int j = 0; j < keyboardRow.length(); j++) { - row.add(keyboardRow.getString(j)); - } - this.keyboard.add(row); - } - if (jsonObject.has(RESIZEKEYBOARD_FIELD)) { - this.resizeKeyboard = jsonObject.getBoolean(RESIZEKEYBOARD_FIELD); - } - if (jsonObject.has(ONETIMEKEYBOARD_FIELD)) { - this.oneTimeKeyboad = jsonObject.getBoolean(ONETIMEKEYBOARD_FIELD); - } - if (jsonObject.has(SELECTIVE_FIELD)) { - this.selective = jsonObject.getBoolean(SELECTIVE_FIELD); - } + this.keyboard = new ArrayList<>(); } - public List> getKeyboard() { + public List> getKeyboard() { return keyboard; } - public void setKeyboard(List> keyboard) { + public void setKeyboard(List> keyboard) { this.keyboard = keyboard; } - public Boolean getResizeKeyboard() { - return resizeKeyboard; - } - - public void setResizeKeyboard(Boolean resizeKeyboard) { - this.resizeKeyboard = resizeKeyboard; - } - - public Boolean getOneTimeKeyboad() { - return oneTimeKeyboad; - } - - public void setOneTimeKeyboad(Boolean oneTimeKeyboad) { - this.oneTimeKeyboad = oneTimeKeyboad; - } - - public Boolean getSelective() { - return selective; - } - - public void setSelective(Boolean selective) { - this.selective = selective; - } - @Override public JSONObject toJson() { JSONObject jsonObject = new JSONObject(); JSONArray jsonkeyboard = new JSONArray(); - for (List innerRow : this.keyboard) { + for (List innerRow : this.keyboard) { JSONArray innerJSONKeyboard = new JSONArray(); - for (String element : innerRow) { - innerJSONKeyboard.put(element); + for (InlineKeyboardButton element : innerRow) { + innerJSONKeyboard.put(element.toJson()); } jsonkeyboard.put(innerJSONKeyboard); } jsonObject.put(InlineKeyboardMarkup.KEYBOARD_FIELD, jsonkeyboard); - if (this.oneTimeKeyboad != null) { - jsonObject.put(InlineKeyboardMarkup.ONETIMEKEYBOARD_FIELD, this.oneTimeKeyboad); - } - if (this.resizeKeyboard != null) { - jsonObject.put(InlineKeyboardMarkup.RESIZEKEYBOARD_FIELD, this.resizeKeyboard); - } - if (this.selective != null) { - jsonObject.put(InlineKeyboardMarkup.SELECTIVE_FIELD, this.selective); - } - return jsonObject; } @@ -131,23 +67,14 @@ public class InlineKeyboardMarkup implements ReplyKeyboard { public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { gen.writeStartObject(); gen.writeArrayFieldStart(KEYBOARD_FIELD); - for (List innerRow : keyboard) { + for (List innerRow : keyboard) { gen.writeStartArray(); - for (String element : innerRow) { - gen.writeString(element); + for (InlineKeyboardButton element : innerRow) { + gen.writeObject(element); } gen.writeEndArray(); } gen.writeEndArray(); - if (this.oneTimeKeyboad != null) { - gen.writeBooleanField(ONETIMEKEYBOARD_FIELD, oneTimeKeyboad); - } - if (this.resizeKeyboard != null) { - gen.writeBooleanField(RESIZEKEYBOARD_FIELD, resizeKeyboard); - } - if (this.selective != null) { - gen.writeBooleanField(SELECTIVE_FIELD, selective); - } gen.writeEndObject(); gen.flush(); } @@ -159,11 +86,8 @@ public class InlineKeyboardMarkup implements ReplyKeyboard { @Override public String toString() { - return "ReplyKeyboardMarkup{" + - "keyboard=" + keyboard + - ", resizeKeyboard=" + resizeKeyboard + - ", oneTimeKeyboad=" + oneTimeKeyboad + - ", selective=" + selective + + return "InlineKeyboardMarkup{" + + "inline_keyboard=" + keyboard + '}'; } }