63.10. 自定义键盘
您可以自定义用户键盘,而不是要求他写一个选项。OutgoingTextMessage
具有属性 ReplyMarkup
,可用于此类操作。
from("telegram:bots?authorizationToken=123456789:insertYourAuthorizationTokenHere") .process(exchange -> { OutgoingTextMessage msg = new OutgoingTextMessage(); msg.setText("Choose one option!"); InlineKeyboardButton buttonOptionOneI = InlineKeyboardButton.builder() .text("Option One - I").build(); InlineKeyboardButton buttonOptionOneII = InlineKeyboardButton.builder() .text("Option One - II").build(); InlineKeyboardButton buttonOptionTwoI = InlineKeyboardButton.builder() .text("Option Two - I").build(); ReplyKeyboardMarkup replyMarkup = ReplyKeyboardMarkup.builder() .keyboard() .addRow(Arrays.asList(buttonOptionOneI, buttonOptionOneII)) .addRow(Arrays.asList(buttonOptionTwoI)) .close() .oneTimeKeyboard(true) .build(); msg.setReplyMarkup(replyMarkup); exchange.getIn().setBody(msg); }) .to("telegram:bots?authorizationToken=123456789:insertYourAuthorizationTokenHere");
如果要禁用它,下一个消息必须在 ReplyKeyboardMarkup
对象上设置属性 removeKeyboard
Markup。
from("telegram:bots?authorizationToken=123456789:insertYourAuthorizationTokenHere") .process(exchange -> { OutgoingTextMessage msg = new OutgoingTextMessage(); msg.setText("Your answer was accepted!"); ReplyKeyboardMarkup replyMarkup = ReplyKeyboardMarkup.builder() .removeKeyboard(true) .build(); msg.setReplyKeyboardMarkup(replyMarkup); exchange.getIn().setBody(msg); }) .to("telegram:bots?authorizationToken=123456789:insertYourAuthorizationTokenHere");