问题
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