Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
Minor bug fixes to inline keyboard button declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
Shibly Meeran committed Nov 15, 2016
1 parent 62815fb commit ea6713e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 44 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>me.shib.java.lib</groupId>
<artifactId>jtelebot</artifactId>
<version>2.1.0</version>
<version>2.1.1</version>
<name>JTeleBot</name>
<description>A Java library for Telegram Bot API</description>
<url>https://github.com/shibme/jtelebot</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,34 @@ public final class InlineKeyboardButton {
private String url;
private String callback_data;
private String switch_inline_query;
private String switch_inline_query_current_chat;

public enum InlineKeyboardButtonType {
url, callback_data, switch_inline_query, switch_inline_query_current_chat
}

/**
* Initializes a new ReplyKeyboardMarkup object
*
* @param text Label text on the button
* @param buttonType The type of the Inline Keyboard Button based on what it has to do
* @param buttonValue the value corresponding to the button type
*/
public InlineKeyboardButton(String text) {
public InlineKeyboardButton(String text, InlineKeyboardButtonType buttonType, String buttonValue) {
this.text = text;
}

/**
* Sets the HTTP url to be opened when button is pressed
*
* @param url HTTP url to be opened when button is pressed
*/
public void setUrl(String url) {
this.url = url;
}

/**
* Sets the Data to be sent in a callback query to the bot when button is pressed
*
* @param callback_data Data to be sent in a callback query to the bot when button is pressed
*/
public void setCallback_data(String callback_data) {
this.callback_data = callback_data;
}

/**
* If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot‘s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
*
* @param switch_inline_query If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot‘s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
*/
public void setSwitch_inline_query(String switch_inline_query) {
this.switch_inline_query = switch_inline_query;
switch (buttonType) {
case url:
this.url = buttonValue;
break;
case callback_data:
this.callback_data = buttonValue;
break;
case switch_inline_query:
this.switch_inline_query = buttonValue;
break;
case switch_inline_query_current_chat:
this.switch_inline_query_current_chat = buttonValue;
break;
}
}
}
39 changes: 24 additions & 15 deletions src/me/shib/java/lib/jtelebot/models/types/KeyboardButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,39 @@ public final class KeyboardButton {
private boolean request_contact;
private boolean request_location;

public enum KeyboardButtonRequest {
request_contact, request_location
}

/**
* Initializes a new KeyboardButton object
*
* @param text Text of the button. If none of the optional fields are used, it will be sent to the bot as a message when the button is pressed
*/
public KeyboardButton(String text) {
this.text = text;
this.request_contact = false;
this.request_location = false;
this(text, null);
}

/**
* If set, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only
*/
public void requestContact() {
this.request_contact = true;
this.request_location = false;
}

/**
* If set, the user's current location will be sent when the button is pressed. Available in private chats only
* Initializes a new KeyboardButton object
*
* @param text Text of the button. If none of the optional fields are used, it will be sent to the bot as a message when the button is pressed
* @param keyboardButtonRequest the content that has to be sent when pressing the button - contact/location
*/
public void requestLocation() {
this.request_location = true;
this.request_contact = false;
public KeyboardButton(String text, KeyboardButtonRequest keyboardButtonRequest) {
this.text = text;
switch (keyboardButtonRequest) {
case request_contact:
this.request_contact = true;
this.request_location = false;
break;
case request_location:
this.request_contact = false;
this.request_location = true;
break;
default:
this.request_contact = false;
this.request_location = false;
}
}
}

0 comments on commit ea6713e

Please sign in to comment.