I need to send a photo album in a bundle to the telegram bot. The number of photos is unknown in advance.
I wrote the code:
List<IAlbumInputMedia> streamArray = new List<IAlbumInputMedia> {};
foreach (var formFile in files)
{
if (formFile.Length > 0)
{
using var stream = formFile.OpenReadStream();
streamArray.Add(stream); // there is a mistake here. cannot convert to System.IO.Stream to Telegram.Bot.Types.IAlbumInputmedia
//await clientTg.SendPhotoAsync(groupId,stream); // it works fine
}
}
await clientTg.SendMediaGroupAsync(groupId, streamArray);
I can’t add stream to List arrayStream, error "cannot convert to System.IO.Stream to Telegram.Bot.Types.IAlbumInputmedia"
In a single instance, the stream is normally sent via the SendPhotoAsync method, commented out in the code.
How do I convert these types and send a group photo?
2
Answers
@Vadim's answer didn't work, probably because I can't
Add
in this case. But their answer did push me in the right direction. I decided to write code for a different number of photos of different branches of the program.I'm not sure that I'm using
await using
correctly, but at least it works.According to the docs:
You must explicitly set the type of files.
In your case it will be like: