我的电报客户端上仅呈现第一个初始结果。第二个响应甚至从未发生。 是否可以将多个连续结果发送到一次调用?
if (update.InlineQuery != null)
{
if (update.InlineQuery.Query.Count() > 3)
{
var inlineQuery = update.InlineQuery;
try
{
var initialResult = new InlineQueryResult[]
{
new InlineQueryResultArticle
(
id: "1",
title: $"Loading...",
inputMessageContent: new InputTextMessageContent("test")
),
};
await Bot.AnswerInlineQueryAsync(inlineQuery.Id, initialResult, isPersonal: true, cacheTime: 0, nextOffset: null);
var realResponse = new InlineQueryResult[]
{
new InlineQueryResultArticle
(
id: "2",
title: $"this is real content",
inputMessageContent: new InputTextMessageContent("test2")
),
};
await Bot.AnswerInlineQueryAsync(inlineQuery.Id, realResponse, isPersonal: true, cacheTime: 0, nextOffset: null);
}
catch(Exception ex)
{
}
finally
{
}
}
}
是否可以将多个连续结果发送到单个调用?
不可能使用一次尝试向 Telegram 中的单个内联查询发送两个单独的响应。每次调用
AnswerInlineQueryAsync
方法时,它都会为该特定内联查询提供单个响应。
InlineQueryResult[]
数组将在一次调用中将其发送到 AnswerInlineQueryAsync
。数组中的每个元素代表可以向用户显示的单个项目。
使用下面的代码是获得连续响应的一种方法。
if (update.InlineQuery != null)
{
var inlineQuery = update.InlineQuery;
try
{
var multipleResults = new InlineQueryResult[]
{
new InlineQueryResultArticle
(
id: "1",
title: $"Loading...",
inputMessageContent: new InputTextMessageContent("test")
),
new InlineQueryResultArticle
(
id: "2",
title: $"this is real content",
inputMessageContent: new InputTextMessageContent("test2")
),
// Add more InlineQueryResultArticle objects if needed...
};
await Bot.AnswerInlineQueryAsync(inlineQuery.Id, multipleResults, isPersonal: true, cacheTime: 0, nextOffset: null);
}
catch(Exception ex)
{
// Handle exceptions
}
}
使用下面的代码是获得连续响应的另一种方法。
if (update.InlineQuery != null)
{
if (update.InlineQuery.Query.Count() > 3)
{
var inlineQuery = update.InlineQuery;
try
{
var initialResult = new InlineQueryResult[]
{
new InlineQueryResultArticle
(
id: "1",
title: $"Loading...",
inputMessageContent: new InputTextMessageContent("test")
),
};
await Bot.AnswerInlineQueryAsync(inlineQuery.Id, initialResult, isPersonal: true, cacheTime: 0, nextOffset: "offset_for_pagination");
var realResponse = new InlineQueryResult[]
{
new InlineQueryResultArticle
(
id: "2",
title: $"this is real content",
inputMessageContent: new InputTextMessageContent("test2")
),
};
await Bot.AnswerInlineQueryAsync(inlineQuery.Id, realResponse, isPersonal: true, cacheTime: 0, nextOffset: null);
}
catch(Exception ex)
{
// Handle exceptions
}
finally
{
// Any cleanup or final operations
}
}
}
通过将
null
传递给 nextOffset
,您可能会阻止显示第二组结果。要纠正此问题:
nextOffset
设置有效的 AnswerInlineQueryAsync
值。