简体   繁体   English

使用 java.netbeans 在电报机器人上发送粗体文本

[英]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:我的电报机器人正在工作,但我想对发送的消息进行一些修改,例如以粗体、斜体或删除线发送文本,我尝试使用 Unicode 中的“代码”(因为那样我发送的表情符号如“ \ uD83D \ uDEA8“警笛表情符号)为粗体但它不起作用,这是我的代码:

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. Telegram 允许您使用Markdown进行文本格式化。

You can make your text bold by surrounding it with * , for example: *bold text*您可以将文本用*包围起来,使其变为粗体,例如: *bold text*

Note that you have to switch parse_mode to Markdown or MarkdownV2 for this to work.请注意,您必须将parse_mode切换为MarkdownMarkdownV2才能正常工作。

More info: core.telegram.org/bots/api#formatting-options更多信息: core.telegram.org/bots/api#formatting-options

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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