* Added missing XML summaries to new CallbackQuery methods

* Fixed CallbackQuery's origin message resolving inside Callbback query container extension methods
This commit is contained in:
2025-08-02 21:01:29 +04:00
parent bb5ca1daad
commit 18e361322e
2 changed files with 86 additions and 42 deletions
+13 -17
View File
@@ -28,6 +28,19 @@ namespace Telegrator.Handlers
/// </summary> /// </summary>
public abstract class CallbackQueryHandler() : AbstractUpdateHandler<CallbackQuery>(UpdateType.CallbackQuery) public abstract class CallbackQueryHandler() : AbstractUpdateHandler<CallbackQuery>(UpdateType.CallbackQuery)
{ {
/// <summary>
/// Gets the type-specific data from the callback query.
/// Returns the data string, chat instance, or game short name depending on the callback query type.
/// </summary>
protected string TypeData
{
get => Input switch
{
{ Data: { } data } => data,
{ ChatInstance: { } chatInstance } => chatInstance,
{ GameShortName: { } gameShortName } => gameShortName
};
}
/// <summary> /// <summary>
/// Sends a response message to the current chat. /// Sends a response message to the current chat.
@@ -76,7 +89,6 @@ namespace Telegrator.Handlers
/// <param name="replyMarkup">The reply markup for the message.</param> /// <param name="replyMarkup">The reply markup for the message.</param>
/// <param name="entities">The message entities to include.</param> /// <param name="entities">The message entities to include.</param>
/// <param name="linkPreviewOptions">Options for link preview generation.</param> /// <param name="linkPreviewOptions">Options for link preview generation.</param>
/// <param name="messageEffectId">The message effect ID.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The edited message.</returns> /// <returns>The edited message.</returns>
protected async Task<Message> EditMessage( protected async Task<Message> EditMessage(
@@ -106,21 +118,5 @@ namespace Telegrator.Handlers
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
=> await Container.AnswerCallbackQuery( => await Container.AnswerCallbackQuery(
text, showAlert, url, cacheTime, cancellationToken); text, showAlert, url, cacheTime, cancellationToken);
/// <summary>
/// Gets the type-specific data from the callback query.
/// Returns the data string, chat instance, or game short name depending on the callback query type.
/// </summary>
protected string TypeData
{
get => Input switch
{
{ Data: { } data } => data,
{ ChatInstance: { } chatInstance } => chatInstance,
{ GameShortName: { } gameShortName } => gameShortName
};
}
} }
} }
+63 -15
View File
@@ -180,6 +180,25 @@ namespace Telegrator
messageEffectId, businessConnectionId, messageEffectId, businessConnectionId,
allowPaidBroadcast, cancellationToken); allowPaidBroadcast, cancellationToken);
/// <summary>
/// Responnces to message that this CallbackQuery was originated from
/// </summary>
/// <param name="container"></param>
/// <param name="text"></param>
/// <param name="parseMode"></param>
/// <param name="replyParameters"></param>
/// <param name="replyMarkup"></param>
/// <param name="linkPreviewOptions"></param>
/// <param name="messageThreadId"></param>
/// <param name="entities"></param>
/// <param name="disableNotification"></param>
/// <param name="protectContent"></param>
/// <param name="messageEffectId"></param>
/// <param name="businessConnectionId"></param>
/// <param name="allowPaidBroadcast"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static async Task<Message> Responce( public static async Task<Message> Responce(
this IAbstractHandlerContainer<CallbackQuery> container, this IAbstractHandlerContainer<CallbackQuery> container,
string text, string text,
@@ -195,14 +214,32 @@ namespace Telegrator
string? businessConnectionId = null, string? businessConnectionId = null,
bool allowPaidBroadcast = false, bool allowPaidBroadcast = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
=> await container.Client.SendMessage( {
container.ActualUpdate.From.Id, text, parseMode, replyParameters, CallbackQuery query = container.ActualUpdate;
if (query.Message == null)
throw new Exception("Callback origin message not found!");
return await container.Client.SendMessage(
query.Message.Chat, text, parseMode, replyParameters,
replyMarkup, linkPreviewOptions, replyMarkup, linkPreviewOptions,
messageThreadId, entities, messageThreadId, entities,
disableNotification, protectContent, disableNotification, protectContent,
messageEffectId, businessConnectionId, messageEffectId, businessConnectionId,
allowPaidBroadcast, cancellationToken); allowPaidBroadcast, cancellationToken);
}
/// <summary>
/// Edits message text that this CallbackQuery was originated from
/// </summary>
/// <param name="container"></param>
/// <param name="text"></param>
/// <param name="parseMode"></param>
/// <param name="replyMarkup"></param>
/// <param name="entities"></param>
/// <param name="linkPreviewOptions"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static async Task<Message> EditMessage( public static async Task<Message> EditMessage(
this IAbstractHandlerContainer<CallbackQuery> container, this IAbstractHandlerContainer<CallbackQuery> container,
string text, string text,
@@ -212,10 +249,13 @@ namespace Telegrator
LinkPreviewOptions? linkPreviewOptions = null, LinkPreviewOptions? linkPreviewOptions = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var update = container.ActualUpdate; CallbackQuery query = container.ActualUpdate;
if (query.Message == null)
throw new Exception("Callback origin message not found!");
return await container.Client.EditMessageText( return await container.Client.EditMessageText(
chatId: update.Message.Chat.Id, query.Message.Chat,
messageId: update.Message.MessageId, query.Message.MessageId,
text: text, text: text,
parseMode: parseMode, parseMode: parseMode,
replyMarkup: replyMarkup, replyMarkup: replyMarkup,
@@ -224,6 +264,22 @@ namespace Telegrator
cancellationToken: cancellationToken); cancellationToken: cancellationToken);
} }
/// <summary>
/// Use this method to send answers to callback queries sent from <a href="https://core.telegram.org/bots/features#inline-keyboards">inline keyboards</a>.
/// The answer will be displayed to the user as a notification at the top of the chat screen or as an alert
/// </summary>
/// <remarks>
/// Alternatively, the user can be redirected to the specified Game URL.
/// For this option to work, you must first create a game for your bot via <a href="https://t.me/botfather">@BotFather</a> and accept the terms.
/// Otherwise, you may use links like <c>t.me/your_bot?start=XXXX</c> that open your bot with a parameter.
/// </remarks>
/// <param name="container"></param>
/// <param name="text"></param>
/// <param name="showAlert"></param>
/// <param name="url"></param>
/// <param name="cacheTime"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task AnswerCallbackQuery( public static async Task AnswerCallbackQuery(
this IAbstractHandlerContainer<CallbackQuery> container, this IAbstractHandlerContainer<CallbackQuery> container,
string? text = null, string? text = null,
@@ -231,11 +287,8 @@ namespace Telegrator
string? url = null, string? url = null,
int cacheTime = 0, int cacheTime = 0,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ => await container.Client.AnswerCallbackQuery(
var callbackQueryId = container.ActualUpdate.Id; callbackQueryId: container.ActualUpdate.Id,
await container.Client.AnswerCallbackQuery(
callbackQueryId: callbackQueryId,
text: text, text: text,
showAlert: showAlert, showAlert: showAlert,
url: url, url: url,
@@ -243,11 +296,6 @@ namespace Telegrator
cancellationToken: cancellationToken); cancellationToken: cancellationToken);
} }
}
/// <summary> /// <summary>
/// Extensions methods for Awaiter Handler Builders /// Extensions methods for Awaiter Handler Builders
/// </summary> /// </summary>