Skip to content

Make API more Dart-y #99

@MarcelGarus

Description

@MarcelGarus

I like the distinction of telegram and teledart – one is a simple typed wrapper around web requests, the other one a full-fledged powerful API that uses the capabilities of object-oriented programming. Some aspects like the inline mode are really great, but I think other parts could be a bit better.
For example, most requests still need to be made through the teledart instance with the exception of replies. I'd love it if you could simply send a message to a chat if you got hold of the Chat. Something like chat.send('Some text.').
Also, most fields currently have the name from the API in snake_case instead of using an adapted camelCase version. The typing could also be a bit stronger. For example, we could create a ChatId class to represent a reference to a Chat. Then we could do stuff like this:

final id = someMessage.chat.id;
final chat = await id.resolve();

We could also introduce classes for several other concepts to make them type-safe. Take photos for example. Currently, the telegram.sendPhoto function accepts dynamic as a photo and developers are forced to go to the Telegram API documentation to find out what they can send, but we could also create a Photo class which gets subclassed by PhotoUrl, and PhotoFile. Users could then create photos using Photo.fromUrl(…) and Photo.fromFile(…) constructors, which makes the API easier to use and explore.

Let me know what you think about this. I'd be happy to help implementing these changes.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions