电报机器人 - 错误请求:文件必须是非空的
telegram bot - Bad Request: file must be non-empty
我想使用以下代码在 telegram bot 中发送用于 c# 版本 15.7.1 的文本文件:
var csvFile = new StringBuilder();
foreach ( var person in persons)
{
var output = new List<string>
{
person.Fardi.Name,
person.Fardi.LastName,
person.Fardi.PhoneNumber,
person.Fardi.BrithYear.ToString(),
person.Fardi.Father
};
csvFile.AppendLine(string.Join(_delimiter, output));
}
using var stream = new MemoryStream();
using var streamWriter = new StreamWriter(stream, Encoding.UTF8);
await streamWriter.WriteAsync(csvFile.ToString());
await streamWriter.FlushAsync();
await _botClient.SendDocumentAsync(new ChatId(chatId), new InputOnlineFile(stream, "test.txt"), replyMarkup: GetInlineKeyboard(buttons));
但是当我发送请求时,出现了这个错误:
Error while sending message
Telegram.Bot.Exceptions.ApiRequestException: Bad Request: file must be non-empty
at Telegram.Bot.TelegramBotClient.MakeRequestAsync[TResponse](IRequest`1 request, CancellationToken cancellationToken)
但是我的流不是空的,它的长度是 200。
我不知道 telegram bot 是什么,但是修复可能就像用 [=13] 倒带 stream 一样简单=]
Gets or sets the current position within the stream.
using var stream = new MemoryStream();
...
stream.Position = 0;
await _botClient.SendDocumentAsync(
new ChatId(chatId),
new InputOnlineFile(stream, "test.txt"),
replyMarkup: GetInlineKeyboard(buttons));
我想使用以下代码在 telegram bot 中发送用于 c# 版本 15.7.1 的文本文件:
var csvFile = new StringBuilder();
foreach ( var person in persons)
{
var output = new List<string>
{
person.Fardi.Name,
person.Fardi.LastName,
person.Fardi.PhoneNumber,
person.Fardi.BrithYear.ToString(),
person.Fardi.Father
};
csvFile.AppendLine(string.Join(_delimiter, output));
}
using var stream = new MemoryStream();
using var streamWriter = new StreamWriter(stream, Encoding.UTF8);
await streamWriter.WriteAsync(csvFile.ToString());
await streamWriter.FlushAsync();
await _botClient.SendDocumentAsync(new ChatId(chatId), new InputOnlineFile(stream, "test.txt"), replyMarkup: GetInlineKeyboard(buttons));
但是当我发送请求时,出现了这个错误:
Error while sending message
Telegram.Bot.Exceptions.ApiRequestException: Bad Request: file must be non-empty
at Telegram.Bot.TelegramBotClient.MakeRequestAsync[TResponse](IRequest`1 request, CancellationToken cancellationToken)
但是我的流不是空的,它的长度是 200。
我不知道 telegram bot 是什么,但是修复可能就像用 [=13] 倒带 stream 一样简单=]
Gets or sets the current position within the stream.
using var stream = new MemoryStream();
...
stream.Position = 0;
await _botClient.SendDocumentAsync(
new ChatId(chatId),
new InputOnlineFile(stream, "test.txt"),
replyMarkup: GetInlineKeyboard(buttons));