diff --git a/CHANGELOG.md b/CHANGELOG.md index 34ad81e7..1c83e16f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 1.17.1 + +- ‼️ Strict typing for `ctx.editMessageMedia` and `ctx.editMessageReplyMarkup` +- Fix: `ChatID` constuctor accepted `dynamic` + # 1.17.0 - 🤖 Bot API 7.4 (May 28, 2024) diff --git a/lib/src/televerse/context/context.dart b/lib/src/televerse/context/context.dart index ac773409..d68a966b 100644 --- a/lib/src/televerse/context/context.dart +++ b/lib/src/televerse/context/context.dart @@ -1749,47 +1749,66 @@ class Context { /// Edit the message media /// Use this method to edit animation, audio, document, photo, or video messages. - Future editMessageMedia( + /// + /// Make sure to pass the type parameter for correct typing. If the message to be edited is an + /// inline message, the type parameter should be `bool`, otherwise `Message` should be passed. + /// + /// Since Televerse don't deal with `dynamic` types on the public interface, if you do not pass + /// type parameter, this method will throw a `TeleverseException`. + Future editMessageMedia( InputMedia media, { InlineKeyboardMarkup? replyMarkup, }) async { + if (MessageOrBool != Message && MessageOrBool != bool) { + throw TeleverseException.typeParameterRequired( + "editMessageMedia", + MessageOrBool, + [Message, bool], + ); + } + if (_isInline()) { - await api.editInlineMessageMedia( + return await api.editInlineMessageMedia( _inlineMsgId!, media, replyMarkup: replyMarkup, - ); + ) as MessageOrBool; } else { _verifyInfo([_chatId, _msgId], APIMethod.editMessageMedia); - await api.editMessageMedia( + return await api.editMessageMedia( id, _msgId!, media, replyMarkup: replyMarkup, - ); + ) as MessageOrBool; } - return true; } /// Edit the message reply markup /// Use this method to edit only the reply markup of messages. - Future editMessageReplyMarkup({ + Future editMessageReplyMarkup({ InlineKeyboardMarkup? replyMarkup, }) async { + if (MessageOrBool != Message && MessageOrBool != bool) { + throw TeleverseException.typeParameterRequired( + "editMessageReplyMarkup", + MessageOrBool, + [Message, bool], + ); + } if (_isInline()) { - await api.editInlineMessageReplyMarkup( + return await api.editInlineMessageReplyMarkup( _inlineMsgId!, replyMarkup: replyMarkup, - ); + ) as MessageOrBool; } else { _verifyInfo([_chatId, _msgId], APIMethod.editMessageReplyMarkup); - await api.editMessageReplyMarkup( + return await api.editMessageReplyMarkup( id, _msgId!, replyMarkup: replyMarkup, - ); + ) as MessageOrBool; } - return true; } /// Answer inline query diff --git a/lib/src/televerse/models/chat_id.dart b/lib/src/televerse/models/chat_id.dart index 21e7e37f..d0d8ac28 100644 --- a/lib/src/televerse/models/chat_id.dart +++ b/lib/src/televerse/models/chat_id.dart @@ -87,7 +87,7 @@ class ChatID extends ID { /// // Print the chat's title. /// print(chat.title); /// ``` - const ChatID(super.id); + const ChatID(int super.id); /// The ID getter, returns the actual integer value @override diff --git a/lib/src/televerse/models/televerse_exception.dart b/lib/src/televerse/models/televerse_exception.dart index 8e52da7d..81b6b478 100644 --- a/lib/src/televerse/models/televerse_exception.dart +++ b/lib/src/televerse/models/televerse_exception.dart @@ -94,4 +94,21 @@ class TeleverseException implements Exception { type: TeleverseExceptionType.timeoutException, ); } + + /// Exception thrown when the timeout exception occurs. + static TeleverseException typeParameterRequired( + String method, + Type type, + List expected, + ) { + return TeleverseException( + "Type Parameter Required.", + description: + "Televerse is a strictly typed library and does not allows usage of dynamic types. This exception is thrown either\n" + " 1. when you do not mention type parameter when it is required or\n" + " 2. when you've passed the type [$type] where types [${expected.join(', ')}] are expected.\n\n" + "If you are using the `Context.$method` method, try `ctx.$method(...)` for inline messages or `ctx.$method(...)` otherwise.", + type: TeleverseExceptionType.invalidParameter, + ); + } } diff --git a/pubspec.yaml b/pubspec.yaml index 3c6ee2fd..b0664f45 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: televerse -description: Televerse lets you create your own efficient Telegram bots with ease in Dart. Supports latest Telegram Bot API - 7.3! -version: 1.17.0 +description: Televerse lets you create your own efficient Telegram bots with ease in Dart. Supports latest Telegram Bot API - 7.4! +version: 1.17.1 homepage: https://github.com/HeySreelal/televerse topics: - telegram