Skip to content

Commit abbb3e6

Browse files
committed
Added the new object LoginUrl and the new field login_url to the InlineKeyboardButton object
1 parent 5c52f15 commit abbb3e6

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

library/src/main/java/com/pengrad/telegrambot/model/request/InlineKeyboardButton.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class InlineKeyboardButton implements Serializable {
1111

1212
private String text;
1313
private String url;
14+
private LoginUrl login_url;
1415
private String callback_data;
1516
private String switch_inline_query;
1617
private String switch_inline_query_current_chat;
@@ -28,6 +29,11 @@ public InlineKeyboardButton url(String url) {
2829
return this;
2930
}
3031

32+
public InlineKeyboardButton loginUrl(LoginUrl loginUrl) {
33+
login_url = loginUrl;
34+
return this;
35+
}
36+
3137
public InlineKeyboardButton callbackData(String callbackData) {
3238
callback_data = callbackData;
3339
return this;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.pengrad.telegrambot.model.request;
2+
3+
import java.io.Serializable;
4+
5+
/**
6+
* Stas Parshin
7+
* 04 June 2019
8+
*/
9+
public class LoginUrl implements Serializable {
10+
private final static long serialVersionUID = 0L;
11+
12+
private String url;
13+
private String forward_text;
14+
private String bot_username;
15+
private Boolean request_write_access;
16+
17+
public LoginUrl(String url) {
18+
this.url = url;
19+
}
20+
21+
public LoginUrl forwardText(String forwardText) {
22+
forward_text = forwardText;
23+
return this;
24+
}
25+
26+
public LoginUrl botUsername(String botUsername) {
27+
bot_username = botUsername;
28+
return this;
29+
}
30+
31+
public LoginUrl requestWriteAccess(boolean requestWriteAccess) {
32+
request_write_access = requestWriteAccess;
33+
return this;
34+
}
35+
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,4 +1351,21 @@ public void onFailure(GetMe request, IOException e) {
13511351
public void toWebhookResponse() {
13521352
assertEquals("{\"method\":\"getMe\"}", new GetMe().toWebhookResponse());
13531353
}
1354+
1355+
@Test
1356+
public void loginButton() {
1357+
String text = "login";
1358+
String url = "http://pengrad.herokuapp.com/hello";
1359+
SendResponse response = bot.execute(
1360+
new SendMessage(chatId, "Login button").replyMarkup(new InlineKeyboardMarkup(new InlineKeyboardButton[]{
1361+
new InlineKeyboardButton(text).loginUrl(new LoginUrl(url)
1362+
.forwardText("forwarded login")
1363+
.botUsername("pengrad_test_bot")
1364+
.requestWriteAccess(true))
1365+
})));
1366+
assertTrue(response.isOk());
1367+
InlineKeyboardButton button = response.message().replyMarkup().inlineKeyboard()[0][0];
1368+
assertEquals(text, button.text());
1369+
assertEquals(url, button.url());
1370+
}
13541371
}

0 commit comments

Comments
 (0)