Как я могу добавить клавиатуры (InlineKeyboard и ReplyKeyboard) в telegram bot?

Я пытаюсь добавить два вида клавиатур в телеграмм бот, чтобы при нажатии на ReplyKeyboard вызывался InlineKeyboard. И при этом не сбивалась диалоговое состояние бота. Когда я кое-как добавил InlineKeyboard бот отвечал только на кнопку, а остальные запросы игнорировал.
Как мне интегрировать кнопки чтобы всё не сломалась ?
На картинке как по идее должно быть.
60acdc88347b8250572745.png
Вот исходник в котором я зашел в тупик(
import java.io.*;
import wiki_work.SearchWiki;
import com.vdurmont.emoji.EmojiParser;
import org.alicebot.ab.*;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import java.util.*;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.exceptions.TelegramApiException;
class BotHandler extends TelegramLongPollingBot
{
    private static final boolean TRACE_MODE = false;
    private final static int SIZE = 2000;
    private String smiley_emoji = EmojiParser.parseToUnicode(":smiley:");
    private String wink_emoji = EmojiParser.parseToUnicode(":wink:");
    private String share_number_emoji = EmojiParser.parseToUnicode(":phone: share your number");
    private String money_emoji = EmojiParser.parseToUnicode(":moneybag:");
    static String botName = "super";
    String response;
    String textLine;
    Bot bot;
    Chat chatSession;
    String resourcesPath;
    public BotHandler()
    {
        String resourcesPath = getResourcesPath();
        bot = new Bot("super", resourcesPath);
        chatSession = new Chat(bot);
        bot.brain.nodeStats();
        MagicBooleans.trace_mode = TRACE_MODE;
    }
    public void onUpdateReceived(Update update)
    {
        if (update.hasMessage() && update.getMessage().hasText())
        {

            String textLine = update.getMessage().getText();
            long chat_id = update.getMessage().getChatId();
            if ((textLine == null) || (textLine.length() < 1))
                textLine = MagicStrings.null_input;
            String request = textLine;
            
            if (MagicBooleans.trace_mode)
                System.out.println("STATE=" + request + ":THAT=" + ((History) chatSession.thatHistory.get(0)).get(0) + ":TOPIC=" + chatSession.predicates.get("topic"));

            if(request.equals("/start"))
            {
                Random randseed=new Random();
                int briseed=randseed.nextInt(2);
                String[] welcomemsg=new String[2];
                welcomemsg[0]="Hello!";
                welcomemsg[1]="Hi!";
                response = welcomemsg[briseed];
            }
            else if(request.contains("Wiki") ||request.contains("Wikipedia"))
            {
                String query = update.getMessage().getText();
                SearchWiki searchWiki = new SearchWiki();
                String messageText = searchWiki.run(query);
                long chatId = update.getMessage().getChatId();

                if(messageText.length() > SIZE)
                    messageText = Redactor.cut(messageText, SIZE);

                SendMessage message = new SendMessage()
                        .setChatId(chatId)
                        .setText(messageText);
            }
            else if(request.equals("/joke"))
            {
                response="Try to don't talk :)";
            }else if(request.equals("/help"))
            {
                response="What's wrong?";
            }
            else
            {
                response = chatSession.multisentenceRespond(request);
                if(response.contains("<"))
                {
                    response="Mmmmm"+ wink_emoji;
                }

            }
            SendMessage message = new SendMessage().setChatId(chat_id).setText(response);
            try {
                execute(message);
            }
            catch (TelegramApiException e)
            {
                e.printStackTrace();
            }
        }
    }
    public String getBotUsername()
    {
        return "Bot_Bot-Bot";
    }

    @Override
    public String getBotToken()
    {
        return "56565595+5+55";
    }
    private static String getResourcesPath()
    {
        File currDir = new File(".");
        String path = currDir.getAbsolutePath();
        path = path.substring(0, path.length() - 2);
        System.out.println(path);
        String resourcesPath = path + File.separator + "src" + File.separator + "main" + File.separator + "resources";
        return resourcesPath;
    }
}
  • Вопрос задан
  • 835 просмотров
Решения вопроса 1
@Ezekiel4
Охотник на пиратов и сборщик монолитов
Когда пользователь нажимает на кнопку (reply keyboard), она отправляет в чат сообщение, текст которого указан на кнопке. На текущий момент эти кнопки других функций не имеют.

Далее вам нужно просто сделать проверку наподобии того, как вы проверяли команды /start, /joke и т.д. для фразы "Feed Back", в которой сделайте отправку сообщения ботом. В отправляемом сообщении установите кнопку с ссылкой, как на иллюстрации и всё.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы