skip to Main Content

In my Telegram Bot I need to show HTML formatted view in my inline query:

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

I tried this code but I got this result:

enter image description here

I need an output like this:

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    I found the solution:

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

    and the result as below: enter image description here


  2. If you can use SendTextMessageAsync then you could specify the parse mode parameter to use either markdown or HTML, here is an example using 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
            );
        }
    }
    

    More info here: https://core.telegram.org/bots/api#sendmessage

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search