为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用java为电报机器人制作一个url按钮

如何使用java为电报机器人制作一个url按钮

茅侃侃 2024-01-28 20:31:08
我对java没有太多经验,但我正在尝试制作一个电报机器人。我想创建一个按钮,当您单击它时打开一个链接,但我不知道如何操作。这是我的代码: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 回答

?
隔江千里

TA贡献1906条经验 获得超10个赞

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);


查看完整回答
反对 回复 2024-01-28
?
幕布斯6054654

TA贡献1876条经验 获得超7个赞

我自己解决了这个问题:


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);

        }


查看完整回答
反对 回复 2024-01-28
  • 2 回答
  • 0 关注
  • 37 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信