Telegram bot - answer inline query with plain text?

≯℡__Kan透↙ 提交于 2020-05-15 09:50:33

问题


I'm trying to make an inline Telegram bot that would modify user input in a certain way. Because of that I wanted to answer the query with simple text, but that doesn't seem possible and I'm wondering if it's really not or I'm missing something.

According to Telegram, there's 20 handy result types, yet there doesn't seem to be simple plain text. Is that really the case? How can I achieve my desired result then?


回答1:


I had the same exact issue and solved it with the InlineQueryResultArticle.

Example code for your OnInlineQuery Method:

// Check for invalid queries
if (e.InlineQuery.Query == null)
    return;
if (e.InlineQuery.Query == "")
    return;


InlineQueryResultBase[] results = {
    new InlineQueryResultArticle(
        // id's should be unique for each type of response
        id: "1",
        // Title of the option
        title: "sample title",
        // This is what is returned
        new InputTextMessageContent("text that is returned") {ParseMode = Telegram.Bot.Types.Enums.ParseMode.Default })
    {
        // This is just the description shown for the option
        Description = "You could also put your output text for a preview here too."
    }
};

// Send the response
try
{
    // If your method is not async you have to remove the await
    await client.AnswerInlineQueryAsync(e.InlineQuery.Id, results);
}
catch (Exception ex)
{
    Console.ForegroundColor = ConsoleColor.Red;
    Console.WriteLine($"Error responding to Inline Query! {ex.Message}");
}



回答2:


Use "InlineQueryResultArticle" and either set the value of "url" to undefined or do not set "url" fileld.



来源:https://stackoverflow.com/questions/57119776/telegram-bot-answer-inline-query-with-plain-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!