Created
October 21, 2023 21:29
-
-
Save centralhardware/04a5fb45c47dc7a22eeca7bd112ab92b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InlineKeyboardBuilder { | |
private final List<List<InlineKeyboardButton>> keyboard = new ArrayList<>(); | |
private String text; | |
private List<InlineKeyboardButton> row = null; | |
private InlineKeyboardBuilder() { } | |
public static InlineKeyboardBuilder create() { | |
return new InlineKeyboardBuilder(); | |
} | |
public InlineKeyboardBuilder setText( String text) { | |
this.text = text; | |
return this; | |
} | |
public InlineKeyboardBuilder row() { | |
row = new ArrayList<>(); | |
return this; | |
} | |
public InlineKeyboardBuilder button( String text, String callbackData) { | |
row.add(InlineKeyboardButton. | |
builder(). | |
text(text). | |
callbackData(callbackData). | |
build()); | |
return this; | |
} | |
public InlineKeyboardBuilder webApp(String url, String text){ | |
row.add(InlineKeyboardButton | |
.builder() | |
.text(text) | |
.webApp(WebAppInfo | |
.builder() | |
.url(url) | |
.build()) | |
.build()); | |
return this; | |
} | |
public InlineKeyboardBuilder switchToInline(){ | |
row.add(InlineKeyboardButton | |
.builder() | |
.text("inline") | |
.switchInlineQueryCurrentChat("") | |
.build()); | |
return this; | |
} | |
public InlineKeyboardBuilder endRow() { | |
keyboard.add(row); | |
row = null; | |
return this; | |
} | |
public InlineKeyboardMarkup build(){ | |
return InlineKeyboardMarkup. | |
builder(). | |
keyboard(keyboard). | |
build(); | |
} | |
public SendMessage build(Long chatId) { | |
return SendMessage. | |
builder(). | |
chatId(chatId). | |
text(text). | |
replyMarkup(InlineKeyboardMarkup. | |
builder(). | |
keyboard(keyboard). | |
build()). | |
build(); | |
} | |
public EditMessageText build(CallbackQuery callbackQuery) { | |
return EditMessageText | |
.builder() | |
.chatId(callbackQuery.getMessage().getChatId()) | |
.inlineMessageId(callbackQuery.getInlineMessageId()) | |
.text(text) | |
.messageId(callbackQuery.getMessage().getMessageId()) | |
.replyMarkup(InlineKeyboardMarkup | |
.builder() | |
.keyboard(keyboard) | |
.build()) | |
.build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment