TelegramBots / Telegram.Bot

.NET Client for Telegram Bot API
https://telegrambots.github.io/book
MIT License
3.22k stars 690 forks source link

Please remove implicit operator InputOnlineFile(stream) #1119

Closed wiz0u closed 1 year ago

wiz0u commented 2 years ago

It confuses people more than help them.

Nobody ever wants to send a nameless file without an extension defining the type.

Additionally, you could make the fileName parameter mandatory (no default null value) on:

public InputOnlineFile(Stream content, string? fileName = null)
karb0f0s commented 2 years ago

I do agree that all SendXXXAsync() methods would benefit from this approach. But there are few cases, where file name should not be mandatory:

Should we enforce users to specify FileName in some methods with new NamedStreamFileSomething type?

karb0f0s commented 2 years ago

I did some changes in InputFile type hierarchy to align it with the Bot API: https://github.com/TelegramBots/Telegram.Bot/tree/karb0f0s/input_file

wiz0u commented 2 years ago
  • certificate parameter in setWebhook this one is InputFileStream, not InputOnlineFile

for the other, if type is implicit regardless of filename/extension, user can still pass an explicit null as filename.

in any case, if you don't accept my second suggestion (InputOnlineFile mandatory 2nd argument), the removal of implicit operator will force the dev to get interested in the InputOnlineFile constructors and find out the filename parameter if they need it.

karb0f0s commented 2 years ago

I don't really like the idea of passing null around. Giving this whole issue some though it seems that the only method that actually requires file extension is SendDocument. For all other cases/media types extension is not important or relevant. I'd love to see some prototype/suggestion on how this case should be handled.

wiz0u commented 2 years ago

then maybe have an overload of SendDocument take Stream and filename arguments instead of InputOnlineFile

tuscen commented 1 year ago

Resolved by #1147.