From 8658de9b94ff4c79eb13a10d7390067a3fd1e749 Mon Sep 17 00:00:00 2001 From: nicetryzz <11810115@mail.sustech.edu.cn> Date: Sat, 24 Apr 2021 21:36:26 +0800 Subject: [PATCH] Inline Model add in Wiki --- TelegramBots.wiki/FAQ.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/TelegramBots.wiki/FAQ.md b/TelegramBots.wiki/FAQ.md index a296ec59..6364d558 100644 --- a/TelegramBots.wiki/FAQ.md +++ b/TelegramBots.wiki/FAQ.md @@ -225,6 +225,46 @@ Custom keyboards can be appended to messages using the `setReplyMarkup`. In this } ``` +[InlineKeyboardMarkup](https://core.telegram.org/bots/api#inlinekeyboardmarkup) use list to capture the buttons instead of KeyboardRow. + +```java + public void sendInlineKeyboard(String chatId) { + SendMessage message = new SendMessage(); + message.setChatId(chatId); + message.setText("Inline model below."); + + // Create InlineKeyboardMarkup object + InlineKeyboardMarkup inlineKeyboardMarkup = new InlineKeyboardMarkup(); + // Create the keyboard (list of InlineKeyboardButton list) + List> keyboard = new ArrayList<>(); + // Create a list for buttons + List Buttons = new ArrayList(); + // Initialize each button, the text must be written + InlineKeyboardButton youtube= new InlineKeyboardButton("youtube"); + // Also must use exactly one of the optional fields,it can edit by set method + youtube.setUrl("https://www.youtube.com"); + // Add button to the list + Buttons.add(youtube); + // Initialize each button, the text must be written + InlineKeyboardButton github= new InlineKeyboardButton("github"); + // Also must use exactly one of the optional fields,it can edit by set method + github.setUrl("https://github.com"); + // Add button to the list + Buttons.add(github); + keyboard.add(Buttons); + inlineKeyboardMarkup.setKeyboard(keyboard); + // Add it to the message + message.setReplyMarkup(inlineKeyboardMarkup); + + try { + // Send the message + execute(message); + } catch (TelegramApiException e) { + e.printStackTrace(); + } + } +``` + ## How can I run my bot? ## You don't need to spend a lot of money into hosting your own telegram bot. Basically, there are two options around how to host: