Telegram.Bot icon indicating copy to clipboard operation
Telegram.Bot copied to clipboard

Please remove implicit operator InputOnlineFile(stream)

Open wiz0u opened this issue 3 years ago • 5 comments

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)

wiz0u avatar Aug 05 '22 22:08 wiz0u

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

  • a certificate parameter in setWebhook
  • a photo parameter in setChatPhoto
  • *sticker* parameters in createNewStickerSet, sendSticker , uploadStickerFile , addStickerToSet, setStickerSetThumb
  • all thumb parameters...

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

karb0f0s avatar Aug 06 '22 16:08 karb0f0s

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

karb0f0s avatar Aug 06 '22 19:08 karb0f0s

  • 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.

wiz0u avatar Aug 06 '22 19:08 wiz0u

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.

karb0f0s avatar Aug 07 '22 19:08 karb0f0s

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

wiz0u avatar Aug 07 '22 21:08 wiz0u

Resolved by #1147.

tuscen avatar Dec 04 '22 01:12 tuscen