Hello! He began to gradually master the bots in the telegraph. I know a little java. Now the bot is working, which through the switch passes through the necessary answers and gives out what it has been given. Added 4 buttons: command 1, command 2, command 3 and command 4. They perform their function. For any answer, these fields remain, but I would like them to change. Suppose a user chose the "Command 1" button, and in response he was offered 2 question variants, for example, "command 1-1", "command 1-2", command "3-1" etc.
Code:
import org.omg.CORBA.PUBLIC_MEMBER; import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboardMarkup; import org.telegram.telegrambots.api.objects.replykeyboard.buttons.KeyboardRow; import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.ApiContextInitializer; import org.telegram.telegrambots.TelegramBotsApi; import org.telegram.telegrambots.api.methods.send.SendMessage; import org.telegram.telegrambots.api.objects.Message; import org.telegram.telegrambots.api.objects.Update; import org.telegram.telegrambots.bots.TelegramLongPollingBot; import java.security.Key; import java.util.ArrayList; import java.util.List; public class SimpleBot extends TelegramLongPollingBot { public static void main(String[] args) { ApiContextInitializer.init(); TelegramBotsApi telegramBotsApi = new TelegramBotsApi(); try { telegramBotsApi.registerBot(new SimpleBot()); } catch (TelegramApiException e) { e.printStackTrace(); } } @Override public String getBotUsername() { return "botname"; } @Override public String getBotToken() { return "bottoken"; } public void onUpdateReceived(Update update) { Message message = update.getMessage(); if (message != null && message.hasText()) { switch (message.getText()) { case "/start": sendMsg(message, "Это команда старт!"); System.out.println(message.getText()); break; case "Команда 1": sendMsg(message, "Это команда 1"); System.out.println(message.getText()); break; case "Команда 2": sendMsg(message, "Это команда 2"); System.out.println(message.getText()); break; default: sendMsg(message, "Это дефолт! Брейк!"); System.out.println(message.getText()); break; } } } public void sendMsg (Message message, String text) { SendMessage sendMessage = new SendMessage(); sendMessage.enableMarkdown(true); // Создаем клавиуатуру ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup(); sendMessage.setReplyMarkup(replyKeyboardMarkup); replyKeyboardMarkup.setSelective(true); replyKeyboardMarkup.setResizeKeyboard(true); replyKeyboardMarkup.setOneTimeKeyboard(false); // Создаем список строк клавиатуры List<KeyboardRow> keyboard = new ArrayList<>(); // Первая строчка клавиатуры KeyboardRow keyboardFirstRow = new KeyboardRow(); // Добавляем кнопки в первую строчку клавиатуры keyboardFirstRow.add("Команда 1"); keyboardFirstRow.add("Команда 2"); // Вторая строчка клавиатуры KeyboardRow keyboardSecondRow = new KeyboardRow(); // Добавляем кнопки во вторую строчку клавиатуры keyboardSecondRow.add("Команда 3"); keyboardSecondRow.add("Команда 4"); // Добавляем все строчки клавиатуры в список keyboard.add(keyboardFirstRow); keyboard.add(keyboardSecondRow); // и устанваливаем этот список нашей клавиатуре replyKeyboardMarkup.setKeyboard(keyboard); sendMessage.setChatId(message.getChatId().toString()); sendMessage.setReplyToMessageId(message.getMessageId()); sendMessage.setText(text); try { sendMessage(sendMessage); } catch (TelegramApiException e) { e.printStackTrace(); } } }