如何在sendMessage中使用Markdown或html?
https://core.telegram.org/bots/api#sendmessage
我的示例代码是:
public void onUpdateReceived(Update update) {
// We check if the update has a message and the message has text
SendMessage sendMessage = new SendMessage().setChatId(update.getMessage().getChatId());
sendMessage.setText("Mensaje Recibido ...." + update.getMessage().getText());
sendMessage.setText("<a href="+"http://www.example.com/"+">inline URL</a>");
try {
sendMessage(sendMessage);
} catch (TelegramApiException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
结果是:
答案 0 :(得分:1)
启用降价功能,设置为true
SendMessage message = new SendMessage()
.enableMarkdown(true)
.setChatId(chat_id)
.setText(yourMessage);
try {
execute(message);
} catch (TelegramApiException e) {
e.printStackTrace();
}
答案 1 :(得分:0)
您可以在SendMessage()
上调用enableMarkdown答案 2 :(得分:0)
您应该这样做:
SendMessage message = new SendMessage()
.enableMarkdown(true)
.setChatId(chat_id)
.setText("[url name](http://www.url_name.com/)");
try {
execute(message);
} catch (TelegramApiException e) {
e.printStackTrace();
}
这不适用于localhost,那么您应该将localhost替换为127.0.0.1