| | | 1 | | using TeleFlow.Telegram.Schema.Abstractions; |
| | | 2 | | |
| | | 3 | | namespace TeleFlow.Telegram.Internal; |
| | | 4 | | |
| | | 5 | | internal sealed class TelegramClient : ITelegramClient |
| | | 6 | | { |
| | | 7 | | private readonly ITelegramRequestExecutor _executor; |
| | | 8 | | |
| | | 9 | | public TelegramClient( |
| | | 10 | | ITelegramRequestExecutor executor, |
| | | 11 | | TelegramClientOptions options, |
| | | 12 | | TelegramDeepLinks deepLinks) |
| | | 13 | | { |
| | 302 | 14 | | ArgumentNullException.ThrowIfNull(executor); |
| | 302 | 15 | | ArgumentNullException.ThrowIfNull(options); |
| | 302 | 16 | | ArgumentNullException.ThrowIfNull(deepLinks); |
| | | 17 | | |
| | 302 | 18 | | _executor = executor; |
| | 302 | 19 | | Defaults = options.Defaults; |
| | | 20 | | DeepLinks = deepLinks; |
| | 302 | 21 | | } |
| | | 22 | | |
| | | 23 | | public TelegramBotDefaults Defaults { get; } |
| | | 24 | | |
| | | 25 | | public TelegramDeepLinks DeepLinks { get; } |
| | | 26 | | |
| | | 27 | | public async Task<TResult> SendAsync<TResult>( |
| | | 28 | | ITelegramApiMethod<TResult> method, |
| | | 29 | | CancellationToken cancellationToken = default) |
| | | 30 | | { |
| | 85 | 31 | | ArgumentNullException.ThrowIfNull(method); |
| | | 32 | | |
| | 85 | 33 | | var result = await _executor.ExecuteAsync( |
| | 85 | 34 | | new SchemaTelegramRequest<TResult>(method), |
| | 85 | 35 | | cancellationToken).ConfigureAwait(false); |
| | | 36 | | |
| | 53 | 37 | | return result.Value; |
| | 53 | 38 | | } |
| | | 39 | | } |