【问题标题】:Telegram bot - answer inline query with plain text?Telegram bot - 用纯文本回答内联查询?
【发布时间】:2020-05-04 22:57:03
【问题描述】:

我正在尝试制作一个内联电报机器人,它会以某种方式修改用户输入。因此,我想用简单的文本回答查询,但这似乎不可能,我想知道是不是真的不是,或者我错过了什么。

根据 Telegram,有 20 handy result types,但似乎没有简单的纯文本。真的是这样吗?那我怎样才能达到我想要的结果呢?

【问题讨论】:

    标签: telegram


    【解决方案1】:

    我遇到了同样的问题,并通过InlineQueryResultArticle 解决了它。

    OnInlineQuery 方法的示例代码:

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

    【讨论】:

    • 这是什么语言?
    • @FerranMaylinch 那是 C#
    【解决方案2】:

    使用“InlineQueryResultArticle”并将“url”的值设置为未定义或不设置“url”fileld。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-27
      • 1970-01-01
      • 2021-02-09
      • 2018-11-17
      • 2021-11-08
      • 2020-06-27
      • 2021-07-12
      • 2017-06-18
      相关资源
      最近更新 更多