Telegram parse_mode Markdown and HTML JAVA

How can i use Markdown OR html at sendMessage?

https://core.telegram.org/bots/api#sendmessage

My code of example is :

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

the result is :

Rusult whith problem

Upvotes: 1

Views: 4877

Answers (3)

Chester mi ni&#241;o
Chester mi ni&#241;o

Reputation: 91

you should to do it this way:



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


this is not working with localhost, then you should to replace localhost to 127.0.0.1

Upvotes: 0

guntarion
guntarion

Reputation: 101

Enable markdown, set to true

SendMessage message = new SendMessage()
                .enableMarkdown(true)
                .setChatId(chat_id)
                .setText(yourMessage);
        try {
            execute(message);
        } catch (TelegramApiException e) {
            e.printStackTrace(); 
        }

Upvotes: 1

Solido
Solido

Reputation: 31

You can call enableMarkdown on SendMessage()

Upvotes: 0

Related Questions