344.10. 自定义键盘
您可以自定义用户键盘,而不是询问他写出一个选项。OutgoingTextMessage
具有属性 ReplyKeyboardMarkup
,可用于此类事情。
from("telegram:bots/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.setReplyKeyboardMarkup(replyMarkup); exchange.getIn().setBody(msg); }) .to("telegram:bots/123456789:insertYourAuthorizationTokenHere");
如果要禁用它,下一个消息必须具有 ReplyKeyboardMarkup
对象上的属性 removeKeyboard
设置。
from("telegram:bots/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/123456789:insertYourAuthorizationTokenHere");