Telegram bot file upload showing garbled filename with Cyrillic characters

I’m working with a Telegram bot that needs to send documents to users. The bot sends files successfully but there’s an issue with filenames that contain Cyrillic characters. When the file reaches the recipient, the filename appears as encoded text instead of the original name.

string apiUrl = "https://api.telegram.org/bot" + botToken + "/sendDocument";

string documentPath = @"D:\Мой документ.docx";
string originalName = documentPath.Split('\\').Last();
var telegramBot = new Telegram.Bot.Api("YOUR_BOT_TOKEN");
using (var fileStream = System.IO.File.Open(documentPath, FileMode.Open))
{
    FileToSend document = new FileToSend();
    document.Content = fileStream;
    document.Filename = documentPath.Split('\\').Last();
    var result = await telegramBot.SendDocumentAsync(chatId, document, messageCaption);
}

I suspect the filename gets encoded with Base64 and UTF-8 somewhere in the process. I tried converting the filename to UTF-8 encoding manually:

Encoding utf8Encoding = Encoding.UTF8;
Encoding unicodeEncoding = Encoding.Unicode;

byte[] unicodeByteArray = unicodeEncoding.GetBytes(originalName);
byte[] utf8ByteArray = Encoding.Convert(unicodeEncoding, utf8Encoding, unicodeByteArray);

char[] utf8CharArray = new char[utf8Encoding.GetCharCount(utf8ByteArray, 0, utf8ByteArray.Length)];
utf8Encoding.GetChars(utf8ByteArray, 0, utf8ByteArray.Length, utf8CharArray, 0);
string convertedName = new string(utf8CharArray);

originalName = convertedName;

This approach didn’t solve the problem. The filename still appears garbled on the client side. How can I properly handle Unicode filenames so they display correctly when users receive the documents through the Telegram bot?

Had this exact problem six months ago building a document management bot for Russian clients. Your encoding conversion isn’t the issue - it’s how Telegram’s Bot API handles multipart form data headers. When you set the filename in FileToSend, it gets URL-encoded during the HTTP request and mangles Cyrillic characters. Here’s what fixed it for me: use RFC 2231 encoding for the filename parameter. Don’t set document.Filename directly. Instead, manually construct the Content-Disposition header with proper encoding. Try HttpUtility.UrlEncode with UTF-8 on just the filename part, or better yet, switch to InputFileStream with a properly encoded filename parameter. The key is making sure the filename gets transmitted with the correct charset declaration in the multipart boundary.

I had the same problem with non-ASCII filenames in Telegram bot uploads. The Telegram.Bot library doesn’t handle filename encoding well in multipart requests. Don’t bother with manual encoding conversion - just URL-encode the filename before you assign it to the FileToSend object. Use System.Web.HttpUtility.UrlEncode(originalName, Encoding.UTF8) or Uri.EscapeDataString(originalName) for the filename property. What also worked for me: strip out just the base filename (no path) and make sure your app uses UTF-8 for all string handling. And check your Telegram.Bot library version - older versions had Unicode filename bugs in multipart forms.

have u tried using a simpler filename format first? like just letters and numbers, then change it back after?? it might help with the encoding thing. sometimes telegram has trouble with special chars.