.net 如何显示HTML格式的内联查询
在我的电报机器人中,我需要在内联查询中显示HTML格式的视图:.net 如何显示HTML格式的内联查询,.net,.net-core,telegram-bot,.net,.net Core,Telegram Bot,在我的电报机器人中,我需要在内联查询中显示HTML格式的视图: private static async void BotOnInlineQueryReceived( object sender, InlineQueryEventArgs inlineQueryEventArgs) { Console.WriteLine( $"Received inline query from: {inlineQueryEventArgs.InlineQuery.Fr
private static async void BotOnInlineQueryReceived(
object sender,
InlineQueryEventArgs inlineQueryEventArgs)
{
Console.WriteLine(
$"Received inline query from: {inlineQueryEventArgs.InlineQuery.From.Id}");
InlineQueryResultBase[] results = {
new InlineQueryResultArticle(
id: "1",
title : "<b>Test</b>",
inputMessageContent : new InputTextMessageContent("<b>Test</b>"))
};
await Bot.AnswerInlineQueryAsync(
inlineQueryEventArgs.InlineQuery.Id,
results,
isPersonal: true,
cacheTime: 0
);
}
private static async void BotOnInlineQueryReceived(
对象发送器,
InlineQueryEventArgs InlineQueryEventArgs)
{
控制台写入线(
$“从以下位置接收内联查询:{inlineQueryEventArgs.InlineQuery.from.Id}”);
InlineQueryResultBase[]结果={
新的InlineQueryResultArticle(
id:“1”,
标题:“测试”,
inputMessageContent:new InputExtMessageContent(“测试”))
};
等待Bot.AnswerInlineQueryAsync(
inlineQueryEventArgs.InlineQuery.Id,
结果,
个人:是的,
缓存时间:0
);
}
我尝试了此代码,但得到了以下结果:
我需要这样的输出:
如果您可以使用
SendTextMessageAsync
,那么您可以指定parse mode参数来使用markdown或HTML,下面是一个使用HTML的示例:
private static TelegramBotClient botClient;
static void Main()
{
botClient = new TelegramBotClient("YOUR_TOKEN");
var me = botClient.GetMeAsync().Result;
Console.WriteLine(
$"Hello, World! I am user {me.Id} and my name is {me.FirstName}."
);
botClient.OnMessage += Bot_OnMessage;
botClient.StartReceiving();
Thread.Sleep(int.MaxValue);
}
static async void Bot_OnMessage(object sender, MessageEventArgs e)
{
if (e.Message.Text != null)
{
Console.WriteLine($"Received a text message in chat {e.Message.Chat.Id}.");
await botClient.SendTextMessageAsync(
chatId: e.Message.Chat,
text: $"You said: <b>{e.Message.Text}</b>",
parseMode: Telegram.Bot.Types.Enums.ParseMode.Html
);
}
}
私有静态电报botClient botClient;
静态void Main()
{
botClient=新电报botClient(“您的_令牌”);
var me=botClient.GetMeAsync().Result;
控制台写入线(
$“你好,世界!我是用户{me.Id},我的名字是{me.FirstName}。”
);
botClient.OnMessage+=Bot_OnMessage;
botClient.StartReceiving();
Thread.Sleep(int.MaxValue);
}
静态异步void Bot_OnMessage(对象发送方,MessageEventArgs e)
{
如果(e.Message.Text!=null)
{
Console.WriteLine($“在chat{e.message.chat.Id}中收到一条文本消息。”);
等待botClient.SendTextMessageAsync(
聊天ID:e.Message.Chat,
text:$“你说:{e.Message.text}”,
parseMode:Telegrame.Bot.Types.Enums.parseMode.Html
);
}
}
更多信息请点击此处:我找到了解决方案:
private static async void BotOnInlineQueryReceived(object sender, InlineQueryEventArgs inlineQueryEventArgs)
{
Console.WriteLine($"Received inline query from: {inlineQueryEventArgs.InlineQuery.From.Id}");
InlineQueryResultBase[] results = {
new InlineQueryResultArticle(
id: "1",
title : "Received *new data*",
inputMessageContent : new InputTextMessageContent("Received \n Content")
)
{
ReplyMarkup = new InlineKeyboardButton {
Text = "select",
CallbackData = "Some Callback Data",
},
ThumbUrl = "https://photo.venus.com/im/18062700.jpg?preset=product",
Description = "The coolest dress ever seen!",
}
};
await Bot.AnswerInlineQueryAsync(
inlineQueryEventArgs.InlineQuery.Id,
cacheTime:0,
isPersonal: false,
results: results
);
}
结果如下:
是否适用于内联查询中显示的弹出菜单?