Path: redb-route/redb.Route.Telegram/TelegramUpdateUnpackProcessor.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Telegram/TelegramUpdateUnpackProcessor.cs
----
using Telegram.Bot.Types;
using redb.Route.Abstractions;
namespace redb.Route.Telegram;
///
/// Inline processor that unpacks a Telegram from the exchange body
/// and populates on the inbound message.
///
/// Use this after Unmarshal(TelegramUpdateSerializer, typeof(Update)) in a webhook route:
///
/// From(Http.Listen("/tg/webhook"))
/// .Unmarshal(new TelegramUpdateSerializer(), typeof(Update))
/// .Process(new TelegramUpdateUnpackProcessor())
/// .To("direct://tg-dispatch");
///
/// Or use the convenience extension: .UnpackTelegramUpdate().
///
///
/// After this processor runs the exchange has the same headers as a long-polling
/// exchange, ensuring uniform downstream processing.
///
///
public sealed class TelegramUpdateUnpackProcessor : IProcessor
{
///
public Task Process(IExchange exchange, CancellationToken ct = default)
{
if (exchange.In.Body is not Update update)
throw new InvalidOperationException(
$"TelegramUpdateUnpackProcessor expects an {nameof(Update)} in the exchange body, " +
$"but found: {exchange.In.Body?.GetType().Name ?? "null"}. " +
$"Ensure Unmarshal(new TelegramUpdateSerializer(), typeof(Update)) runs before this processor.");
if (!TelegramUpdateMapper.MapUpdate(update, exchange.In))
throw new InvalidOperationException(
$"TelegramUpdateUnpackProcessor: unsupported update type '{update.Type}'. " +
"Add explicit handling or filter the route before this processor.");
return Task.CompletedTask;
}
}