Files
EugeneTes ee3049e47a feat(telegram): TelegramChatChannel delivers send files and scheduler texts in order
Add TelegramLimits, TelegramChatChannel (every delivery through
ChatRenderer.RunInOrderAsync, auto photo falls back to a document on a 400)
and wire it into ChatRegistry as AgentSessionOptions.Channel and
ChatContext.Channel. Spec: SendTextAsync names its failure text
("Telegram did not accept the message.") and throws when any chunk fails.
2026-09-26 22:00:16 +02:00

33 lines
1.3 KiB
C#

using System.Globalization;
namespace Volcanic.AgenticCore.Telegram.Rendering;
/// <summary>Bot API size limits (cloud Bot API server) and size text for users and the model.</summary>
public static class TelegramLimits
{
private const long MiB = 1024 * 1024;
/// <summary>Bots can download files up to 20 MB.</summary>
public const long MaxDownloadBytes = 20 * MiB;
/// <summary>Largest photo a bot can upload with <c>sendPhoto</c>.</summary>
public const long MaxPhotoBytes = 10 * MiB;
/// <summary>Largest file a bot can upload with <c>sendDocument</c>.</summary>
public const long MaxDocumentBytes = 50 * MiB;
/// <summary>Longest photo or document caption, in characters.</summary>
public const int MaxCaptionLength = 1024;
/// <summary>Megabytes with one decimal, e.g. <c>21.0</c>.</summary>
public static string Megabytes(long bytes) => (bytes / (double)MiB).ToString("0.0", CultureInfo.InvariantCulture);
/// <summary><c>5 bytes</c>, <c>1.5 KB</c>, <c>1.2 MB</c>.</summary>
public static string FormatSize(long bytes) => bytes switch
{
< 1024 => $"{bytes.ToString(CultureInfo.InvariantCulture)} bytes",
< MiB => $"{(bytes / 1024.0).ToString("0.0", CultureInfo.InvariantCulture)} KB",
_ => $"{Megabytes(bytes)} MB",
};
}