* 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:
@@ -28,7 +28,20 @@ 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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,26 @@ namespace Telegrator
|
|||||||
disableNotification, protectContent,
|
disableNotification, protectContent,
|
||||||
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,18 +249,37 @@ namespace Telegrator
|
|||||||
LinkPreviewOptions? linkPreviewOptions = null,
|
LinkPreviewOptions? linkPreviewOptions = null,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var update = container.ActualUpdate;
|
CallbackQuery query = container.ActualUpdate;
|
||||||
return await container.Client.EditMessageText(
|
if (query.Message == null)
|
||||||
chatId: update.Message.Chat.Id,
|
throw new Exception("Callback origin message not found!");
|
||||||
messageId: update.Message.MessageId,
|
|
||||||
text: text,
|
return await container.Client.EditMessageText(
|
||||||
parseMode: parseMode,
|
query.Message.Chat,
|
||||||
replyMarkup: replyMarkup,
|
query.Message.MessageId,
|
||||||
entities: entities,
|
text: text,
|
||||||
linkPreviewOptions: linkPreviewOptions,
|
parseMode: parseMode,
|
||||||
cancellationToken: cancellationToken);
|
replyMarkup: replyMarkup,
|
||||||
|
entities: entities,
|
||||||
|
linkPreviewOptions: linkPreviewOptions,
|
||||||
|
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,22 +287,14 @@ 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,
|
||||||
cacheTime: cacheTime,
|
cacheTime: cacheTime,
|
||||||
cancellationToken: cancellationToken);
|
cancellationToken: cancellationToken);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Extensions methods for Awaiter Handler Builders
|
/// Extensions methods for Awaiter Handler Builders
|
||||||
|
|||||||
Reference in New Issue
Block a user