简体   繁体   中英

send bold text on telegram bot with java-netbeans

I have my telegram bot working, but I want to make some modifications to the messages I am sending, such as sending text in bold, italics or strikethrough, I tried using the "code" in Unicode (because that way I send emojis like "\ uD83D \ uDEA8 "for the police siren emoji) for bold but it doesn't work, this is my code:

String startBold = "\\033[1m";
String endBold = "\\033[0;0m";
String msg = "The" + startBold + " text" + endBold + " is bold.";

String json = "{\"chatId\":\"<<chatId>>\",\"key\":\"<<key>>\",\"botId\":\"<<botId>>\",\"msg\":\" " + msg + " \",\"username\":\"<<username>>\"}";


String url = "https://sendMessage.com/rest-messaging/service/bot/sendMessage";

StringEntity body = new StringEntity(json.toString());
String result = sendMessage.telegramNotifications(url, json);

Telegram allows you to use Markdown for text formatting.

You can make your text bold by surrounding it with * , for example: *bold text*

Note that you have to switch parse_mode to Markdown or MarkdownV2 for this to work.

More info: core.telegram.org/bots/api#formatting-options

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM