< Summary

Information
Class: TeleFlow.Telegram.EphemeralMessageReference
Assembly: TeleFlow.Telegram.Client
File(s): /_/src/TeleFlow.Telegram.Client/EphemeralMessageReference.cs
Line coverage
100%
Covered lines: 42
Uncovered lines: 0
Coverable lines: 42
Total lines: 108
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_ReceiverUserId()100%11100%
EditTextAsync(...)100%11100%
EditCaptionAsync(...)100%11100%
EditMediaAsync(...)100%11100%
EditReplyMarkupAsync(...)100%11100%
DeleteAsync(...)100%11100%

File(s)

/_/src/TeleFlow.Telegram.Client/EphemeralMessageReference.cs

#LineLine coverage
 1using TeleFlow.Telegram.Schema.Abstractions;
 2using TeleFlow.Telegram.Schema.Types;
 3
 4namespace TeleFlow.Telegram;
 5
 6/// <summary>
 7/// Represents an ephemeral message sent through the Telegram Bot API.
 8/// It retains the addressing identity required by Telegram's dedicated ephemeral edit and delete methods.
 9/// </summary>
 10public sealed class EphemeralMessageReference
 11{
 12    private readonly ITelegramClient _bot;
 13
 14    internal EphemeralMessageReference(
 15        ITelegramClient bot,
 16        EphemeralMessageTarget target,
 17        long ephemeralMessageId,
 18        Message telegramMessage)
 19    {
 320        ArgumentNullException.ThrowIfNull(bot);
 321        ArgumentNullException.ThrowIfNull(target);
 322        ArgumentNullException.ThrowIfNull(telegramMessage);
 23
 324        _bot = bot;
 25        Target = target;
 26        EphemeralMessageId = ephemeralMessageId;
 27        TelegramMessage = telegramMessage;
 328    }
 29
 30    public EphemeralMessageTarget Target { get; }
 31
 632    public long ReceiverUserId => Target.ReceiverUserId;
 33
 34    public long EphemeralMessageId { get; }
 35
 36    public Message TelegramMessage { get; }
 37
 38    public Task<bool> EditTextAsync(
 39        string text,
 40        InlineKeyboardMarkup? replyMarkup = null,
 41        CancellationToken cancellationToken = default)
 42    {
 143        ArgumentException.ThrowIfNullOrWhiteSpace(text);
 44
 145        return _bot.EditEphemeralMessageTextAsync(
 146            chatId: Target.ChatId,
 147            receiverUserId: ReceiverUserId,
 148            ephemeralMessageId: EphemeralMessageId,
 149            text: text,
 150            replyMarkup: replyMarkup,
 151            cancellationToken: cancellationToken);
 52    }
 53
 54    public Task<bool> EditCaptionAsync(
 55        string? caption = null,
 56        TelegramParseMode? parseMode = null,
 57        IReadOnlyList<MessageEntity>? captionEntities = null,
 58        InlineKeyboardMarkup? replyMarkup = null,
 59        CancellationToken cancellationToken = default)
 60    {
 161        return _bot.EditEphemeralMessageCaptionAsync(
 162            chatId: Target.ChatId,
 163            receiverUserId: ReceiverUserId,
 164            ephemeralMessageId: EphemeralMessageId,
 165            caption: caption,
 166            parseMode: parseMode,
 167            captionEntities: captionEntities,
 168            replyMarkup: replyMarkup,
 169            cancellationToken: cancellationToken);
 70    }
 71
 72    public Task<bool> EditMediaAsync(
 73        InputMedia media,
 74        InlineKeyboardMarkup? replyMarkup = null,
 75        CancellationToken cancellationToken = default)
 76    {
 177        ArgumentNullException.ThrowIfNull(media);
 78
 179        return _bot.EditEphemeralMessageMediaAsync(
 180            chatId: Target.ChatId,
 181            receiverUserId: ReceiverUserId,
 182            ephemeralMessageId: EphemeralMessageId,
 183            media: media,
 184            replyMarkup: replyMarkup,
 185            cancellationToken: cancellationToken);
 86    }
 87
 88    public Task<bool> EditReplyMarkupAsync(
 89        InlineKeyboardMarkup? replyMarkup = null,
 90        CancellationToken cancellationToken = default)
 91    {
 192        return _bot.EditEphemeralMessageReplyMarkupAsync(
 193            chatId: Target.ChatId,
 194            receiverUserId: ReceiverUserId,
 195            ephemeralMessageId: EphemeralMessageId,
 196            replyMarkup: replyMarkup,
 197            cancellationToken: cancellationToken);
 98    }
 99
 100    public Task<bool> DeleteAsync(CancellationToken cancellationToken = default)
 101    {
 1102        return _bot.DeleteEphemeralMessageAsync(
 1103            chatId: Target.ChatId,
 1104            receiverUserId: ReceiverUserId,
 1105            ephemeralMessageId: EphemeralMessageId,
 1106            cancellationToken: cancellationToken);
 107    }
 108}