Path: redb-route/redb.Route.Telegram/TelegramConnectionFactory.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/TelegramConnectionFactory.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
namespace redb.Route.Telegram;
///
/// Named connection factory for Telegram. Register it in the route registry and reference it by
/// name from the endpoint URI (connectionFactory=my-bot) so the bot token — a full account
/// credential — never has to appear in the URI, and therefore can never reach logs, telemetry,
/// or the Tsak dashboard.
///
/// Example:
///
/// context.AddToRegistry("support-bot", new TelegramConnectionFactory
/// {
/// Token = Environment.GetEnvironmentVariable("TELEGRAM_TOKEN")!
/// });
///
/// // route carries no token at all:
/// r.From("telegram://receive?connectionFactory=support-bot")
///
///
///
public sealed class TelegramConnectionFactory
{
/// Bot token from @BotFather. Supports ${env:NAME} expressions.
[Sensitive]
public string Token { get; set; } = string.Empty;
/// Per-send timeout in seconds for producer calls (default 120, range 1–600).
public int SendTimeoutSeconds { get; set; } = 120;
///
/// Copies this factory's settings onto the endpoint options, but only for parameters the
/// endpoint URI did not set explicitly — an inline URI value always wins, so existing routes
/// keep their behaviour.
///
internal void ApplyTo(TelegramEndpointOptions options, EndpointUri uri)
{
var supplied = uri.RawParameters;
if (!supplied.ContainsKey(nameof(options.Token))) options.Token = Token;
if (!supplied.ContainsKey(nameof(options.SendTimeoutSeconds)))
options.SendTimeoutSeconds = SendTimeoutSeconds;
}
}