Open burtimax opened 1 month ago
Hi @burtimax. Sorry, but the approach to follow in this library is to be as similar as possible to the official Telegram Bot API docs. So, only the original fields, methods and classes are included, respecting names and types as possible.
By following this approach, I managed to create an special script that scraps the Telegram documentation and automatically generates almost all the code, allowing to update the library faster when a new version is released.
However, you can add extension methods, extend existing models and/or add custom methods that use your own models as indicated in the readme, in the Making custom requests section. This is an example.
public class CustomUpdate : Update {
[JsonIgnore]
public CustomUpdateTypeEnum Type => ...; // Custom implementation
}
public static class TelegramBotClientExtensions
{
public static CustomUpdate[] GetCustomUpdates(this ITelegramBotClient client, int? offset = null /* ...other args */)
{
var args = new Dictionary<string, object>() {
{ "offset", offset }, // { paramName, value }
// ...
};
return client.CallMethod<CustomUpdate[]>("getUpdates", args);
}
}
// Usage
var client = new TelegramBotClient(botToken);
var updates = client.GetCustomUpdates();
In fact, you can probably use the models in Telegram.Bot here by implementing custom methods as mentioned above, as they now use System.Text.Json as well. I haven't tested it yet, but it should work unless their models require some additional serialization/deserialization process.
I Like your project so much. Please Add Type property to Update and Message. Could you make models as Telegram.Bot library, it would be easy to refactor existed code on your library 😘😅