skip to Main Content

I have not that much experience with java but I’m trying to make a telegram bot.
I want to create a button which opens a link when you click on it but I don’t know how.
This is my code:

import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.exceptions.TelegramApiException;
import org.telegram.telegrambots.api.objects.replykeyboard.InlineKeyboardMarkup;
import.org.telegram.telegrambots.api.objects.replykeyboard.buttons.InlineKeyboardButton;
import java.util.ArrayList;
import java.util.List;

if (message_text.equals("test")) {
  InlineKeyboardMarkup markupInline = new InlineKeyboardMarkup();


  List < List < InlineKeyboardButton >> rowsInline = new ArrayList < > ();
  List < InlineKeyboardButton > rowInline = new ArrayList < > ();
  rowInline.add(new InlineKeyboardButton().setText("https://www.google.com/").setCallbackData("I don't know what to put in here"));
  rowsInline.add(rowInline);
  markupInline.setKeyboard(rowsInline);
  message.setReplyMarkup(markupInline);

} else if (update.hasCallbackQuery()) {
  String call_data = update.getCallbackQuery().getData();
  long message_id = update.getCallbackQuery().getMessage().getMessageId();
  long chat_id = update.getCallbackQuery().getMessage().getChatId();


}

2

Answers


  1. Chosen as BEST ANSWER

    I solved the problem by myself:

    import org.telegram.telegrambots.api.methods.send.SendMessage;
    import org.telegram.telegrambots.api.objects.Update;
    import org.telegram.telegrambots.bots.TelegramLongPollingBot;
    import org.telegram.telegrambots.exceptions.TelegramApiException;
    import org.telegram.telegrambots.api.objects.replykeyboard.InlineKeyboardMarkup;
    import.org.telegram.telegrambots.api.objects.replykeyboard.buttons.InlineKeyboardButton;
    import java.util.ArrayList;
    import java.util.List;
    
    if (message_text.equals("test")) 
        {InlineKeyboardMarkup markupInline = new InlineKeyboardMarkup();
                List < List < InlineKeyboardButton >> rowsInline = new ArrayList < > ();
                List < InlineKeyboardButton > rowInline = new ArrayList < > ();
                rowInline.add(new InlineKeyboardButton().setText("Open Browser").setUrl("https://www.google.com/"));
                rowsInline.add(rowInline);
                markupInline.setKeyboard(rowsInline);
                message.setReplyMarkup(markupInline);
            }


  2. InlineKeyboardMarkup markupInline = new InlineKeyboardMarkup();
    
    List < List < InlineKeyboardButton >> rowsInline = new ArrayList < > ();
    List < InlineKeyboardButton > rowInline = new ArrayList < > ();
    
    InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
    inlineKeyboardButton.setUrl("https://google.com");
    inlineKeyboardButton.setText("Blabla")
    inlineKeyboardButton.setCallbackData("Call back data");
    
    rowInline.add(inlineKeyboardButton);
    
    rowsInline.add(rowInline);
    markupInline.setKeyboard(rowsInline);
    
    message.setReplyMarkup(markupInline);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search