diff --git a/.github/workflows/package_analyzer.yml b/.github/workflows/package_analyzer.yml index 497a7023..b886052f 100644 --- a/.github/workflows/package_analyzer.yml +++ b/.github/workflows/package_analyzer.yml @@ -1,6 +1,6 @@ name: Package Analyzer -on: [push, pull_request] +on: [push, pull_request, workflow_call] jobs: build: @@ -8,8 +8,8 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 # required - - uses: axel-op/dart-package-analyzer/with-full-sdk@stable + - uses: actions/checkout@v3 # required + - uses: axel-op/dart-package-analyzer@v3 with: # Required: githubToken: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..cfcb6d5b --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,19 @@ +name: Publish to pub.dev + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+*' + + +jobs: + analyse: + uses: DinoLeung/TeleDart/.github/workflows/package_analyzer.yml@master + verify_dot_g: + uses: DinoLeung/TeleDart/.github/workflows/verify_dot_g.yml@master + publish: + needs: [analyse, verify_dot_g] + permissions: + id-token: write # Required for authentication using OIDC + # Publish using the reusable workflow from dart-lang. + uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1 diff --git a/.github/workflows/verify_dot_g.yml b/.github/workflows/verify_dot_g.yml index 78b3a07d..689834f3 100644 --- a/.github/workflows/verify_dot_g.yml +++ b/.github/workflows/verify_dot_g.yml @@ -5,16 +5,17 @@ on: branches: [master] pull_request: branches: [master, develop] + workflow_call: jobs: build: runs-on: ubuntu-latest container: - image: google/dart:latest + image: dart:stable steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Print Dart SDK version run: dart --version diff --git a/CHANGELOG.md b/CHANGELOG.md index aa93947c..c3c43d70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,60 @@ +## 0.6.1 + +- Fixed Dart doc generation errors +- Fixed Dart formatter errors + +## 0.6.0 + +- Support API 6.5, 6.6, 6.7, 6.8 +- Updated method `sendMediaGroup` and `editMessageMedia` to dynamically upload media with multipart post +- Added factory `InputMedia.fromFile` which accepts parameter `media` in type `io.File` +- Added class `InputMediaWithThumbnail` what implements `InputMedia` and factories `withThumbnailFile` and `fromFileWithThumbnailFile` +- **Breaking** Replaced the fields `can_send_media_messages` in the classes [ChatMemberRestricted] and [ChatPermissions] with separate fields `can_send_audios`, `can_send_documents`, `can_send_photos`, `can_send_videos`, `can_send_video_notes`, and `can_send_voice_notes` for different media types +- **Breaking** Renamed the field `thumb` in the classes [Animation], [Audio], [Document], [Sticker], [Video], [VideoNote], [InputMediaAnimation], [InputMediaAudio], [InputMediaDocument], [InputMediaVideo], [StickerSet] to `thumbnail` +- **Breaking** Renamed the parameter `thumb` in the methods [sendAnimation], [sendAudio], [sendDocument], [sendVideo], [sendVideoNote] to `thumbnail` +- **Breaking** Renamed the method `setStickerSetThumb` to `setStickerSetThumbnail` and its parameter `thumb` to `thumbnail` +- **Breaking** Renamed the fields `thumb_url`, `thumb_width`, and `thumb_height` in the classes [InlineQueryResultArticle], [InlineQueryResultContact], [InlineQueryResultDocument], [InlineQueryResultLocation], and [InlineQueryResultVenue] to `thumbnail_url`, `thumbnail_width`, and `thumbnail_height` respectively +- **Breaking** Renamed the field `thumb_url` in the classes [InlineQueryResultPhoto] and [InlineQueryResultVideo] to `thumbnail_url` +- **Breaking** Renamed the fields `thumb_url` and `thumb_mime_type` in the classes [InlineQueryResultGif], and [InlineQueryResultMpeg4Gif] to `thumbnail_url` and `thumbnail_mime_type` respectively. + +## 0.5.6 + +- Export util classes, so users can catch http client exceptions + +## 0.5.5 + +- Fixed typo in response object + +## 0.5.4 + +- Implemented Telegram bot API response object +- Update long_polling.dart to respect `retry_after` in error response +- Fixed json_serializable deprecation + +## 0.5.3 + +- Fixed reply in topic bug + +## 0.5.2 + +- Fixed typos in static constants +- Rolled back 0.5.1 as abstract classes cannot be used with json_serializable + +## 0.5.1 + +- Made classes like `chat_member`, `input_media` and other abstract. + +## 0.5.0 + +- Configured JSON serialiser to map properties from snake case to camel case +- **Breaking** Fully convert all property names and parameter names into camel case, so it aligns with Dart styling guide + +## 0.4.0 + +- Fixed `TEXT_MENTION` bug when using regex +- Support API 6.0, 6.1, 6.2, 6.3, 6.4 +- **Breaking** Removed `secretPath` from `webhook` fetcher, should use `secret_token` instead see [setWebhook](https://core.telegram.org/bots/api#setwebhook) + ## 0.3.4 - Webhook to throw error when `setWebhook` failed @@ -18,7 +75,7 @@ ## 0.3.0 - Support API 5.4, 5.5 and 5.6 -- **Breaking** `TeleDart` now extends `Telegram`, constructor signiture has changed, all `Telegram` functions are accessable from `TeleDart`. +- **Breaking** `TeleDart` now extends `Telegram`, constructor signature has changed, all `Telegram` functions are accessible from `TeleDart`. - **Breaking** Renamed `TeleDart.setWebhook` into `TeleDart.configureWebhook` - **Breaking** Removed `TeleDart.editLiveLocation`, should use `Telegram.editMessageLiveLocation` instead - **Breaking** Removed `TeleDart.stopLiveLocation`, should use `Telegram.stopMessageLiveLocation` instead @@ -35,6 +92,7 @@ ## 0.2.1 - Format files to comply with Dart styling guide + ## 0.2.0 - Support API 5.2 and 5.3 @@ -46,7 +104,7 @@ ## 0.1.6 -- Fixed `jsonEncode` issue caused by `_nullFilter` fix +- Fixed `jsonEncode` issue caused by `_nullFilter` fix ## 0.1.5 @@ -72,11 +130,11 @@ ## 0.1.1 -- Allowed create webook without key pair +- Allowed create webhook without key pair ## 0.1.0 -- Inrtoduced `AbstractUpdateFetcher`, and now `Webhook` and `LongPoll` extends this class. +- Introduced `AbstractUpdateFetcher`, and now `Webhook` and `LongPoll` extends this class. - Support custom update fetcher implementations through `AbstractUpdateFetcher` - Introduced `stop` function to `Teledart` to stop fetching updates. - Introduced `setWebhook` to `Teledart`, which is an alias to `setWebhook` function in `Webhook`, and it is not required to call this function before starting webhook. @@ -88,18 +146,18 @@ ## 0.0.50 -- Fixed long poll onError type mismatch bug -- Enabled Teledart to remove webhook without setting up a webhook +- Fixed long poll `onError` type mismatch bug +- Enabled `Teledart` to remove webhook without setting up a webhook ## 0.0.49 - Fixed http client exception bug -- Femoved redundant error catch +- Removed redundant error catch - Temporary accept dynamic `chat_id` ## 0.0.48 -- Fixed restrictChatMember API URL +- Fixed `restrictChatMember` API URL - Fixed `toJson` methods in `chat_permissions`, `location` and `login_url` models - Enabled `explicit_to_json` in `json_serializable` so nested objects can be parsed @@ -109,14 +167,14 @@ - Added auto-retry to long poll implementation - Gradually increase retry timeout on each retry, initial timeout is 1 minute - Automatically retry on exception except HTTP Client error (400) -- Updated multipart file upload to include original file name +- Updated multi-part file upload to include original file name ## 0.0.46 -- Fixed removeLongPolling not stopping recursive long poll +- Fixed `removeLongPolling` not stopping recursive long poll - Fixed long poll not starting with custom long poll configuration -- Fixed missing fields/typos in InlineQueryResultGif, InlineQueryResultMpeg4Gif and PassportElementErrorUnspecified -- updated restrictChatMember +- Fixed missing fields/typos in `InlineQueryResultGif`, `InlineQueryResultMpeg4Gif` and `PassportElementErrorUnspecified` +- updated `restrictChatMember` ## 0.0.45 @@ -131,7 +189,7 @@ ## 0.0.43 -- Added onPollAnswer teledart shorthand +- Added `onPollAnswer` `TeleDart` shorthand ## 0.0.42 @@ -140,7 +198,7 @@ ## 0.0.41 -- Fixed answerPreCheckoutQuery typo +- Fixed `answerPreCheckoutQuery` typo ## 0.0.40 @@ -161,7 +219,7 @@ - Support API 4.6 - Support API 4.7 - Utilised native objects for date/time related objects (#91) -- Updated onMessage (and related functions) to accept String as well as RegExp (#92) +- Updated `onMessage` (and related functions) to accept String as well as RegExp (#92) ## 0.0.36 @@ -184,11 +242,11 @@ ## 0.0.32 -- Prepare for upcoming change to HttpRequest and HttpClientResponse +- Prepare for upcoming change to `HttpRequest` and `HttpClientResponse` ## 0.0.31 -- Fixed styling with if statments +- Fixed styling with if statements - Updated readme and example ## 0.0.30 @@ -205,7 +263,7 @@ ## 0.0.28 -- Modulised model files +- Modularised model files - Updated examples ## 0.0.27 @@ -236,12 +294,12 @@ ## 0.0.21 -- Hot fix #36, toJSON() passing null values explicitly +- Hot fix #36, `toJSON()` passing null values explicitly ## 0.0.20 -- Hot fix #34 400 Bad Request: field "keyboard" of the ReplyKeyboardMarkup should be an Array of Arrays -- Fixed getUserProfilePhotos() returns UserProfilePhotos instead of List +- Hot fix #34 400 Bad Request: field "keyboard" of the `ReplyKeyboardMarkup` should be an Array of Arrays +- Fixed `getUserProfilePhotos()` returns `UserProfilePhotos` instead of `List` ## 0.0.19 @@ -263,7 +321,7 @@ ## 0.0.15 -- Hot fix inline_keyboard variable in InlineKeyboardMarkup +- Hot fix inline_keyboard variable in `InlineKeyboardMarkup` ## 0.0.14 @@ -275,16 +333,16 @@ ## 0.0.12 -- Depends on json_serializable/json_annotation handling json objects +- Depends on `json_serializable/json_annotation` handling json objects - Fixes typos in model.dart ## 0.0.11 -- Supports regular expression in onMessage() +- Supports regular expression in `onMessage()` ## 0.0.10 -- Fixes pubspec.ymal SDK constraint to support Dart 2 release +- Fixes `pubspec.ymal` SDK constraint to support Dart 2 release - Edit README.md Dart Version shield to build version ## 0.0.9 @@ -301,8 +359,8 @@ - Dart2 ready! - Add short-cut for inline query -- Rename ChosenInlineQuery into ChosenInlineResult and associated objects -- Add missing InlineQueryResultVoice to model +- Rename `ChosenInlineQuery` into `ChosenInlineResult` and associated objects +- Add missing `InlineQueryResultVoice` to model - Bug fixes ## 0.0.6 @@ -311,9 +369,9 @@ ## 0.0.5 -- Add onMessage short-cuts -- Add sendMessage short-cuts -- Add missing ShippingQuery to Update +- Add `onMessage` short-cuts +- Add `sendMessage` short-cuts +- Add missing `ShippingQuery` to Update ## 0.0.4 diff --git a/README.md b/README.md index 3eb3156f..3a09d55e 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ A clean implementation of [Telegram bot API](https://core.telegram.org/bots/api) ![TeleDart](https://raw.githubusercontent.com/DinoLeung/TeleDart/master/example/dash_paper_plane.svg?sanitize=true) -[![Bot API Version](https://img.shields.io/badge/Bot%20API-5.7-blue.svg?style=flat-square)](https://core.telegram.org/bots/api) -[![Dart Version](https://img.shields.io/badge/Dart-2.14-blue.svg?style=flat-square)](https://dart.dev) +[![Bot API Version](https://img.shields.io/badge/Bot%20API-6.8-blue.svg?style=flat-square)](https://core.telegram.org/bots/api) +[![Dart Version](https://img.shields.io/badge/Dart-3.1-blue.svg?style=flat-square)](https://dart.dev) [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg?style=flat-square)](https://www.gnu.org/licenses/gpl-3.0) [![Readme Card](https://github-readme-stats.vercel.app/api/pin/?username=DinoLeung&repo=TeleDart)](https://github.com/DinoLeung/TeleDart) @@ -69,13 +69,13 @@ teledart.onInlineQuery().listen((inlineQuery) => inlineQuery.answer([ InlineQueryResultArticle( id: 'ping', title: 'ping', - input_message_content: InputTextMessageContent( - message_text: '*pong*', parse_mode: 'MarkdownV2')), + inputMessageContent: InputTextMessageContent( + messageText: '*pong*', parseMode: 'MarkdownV2')), InlineQueryResultArticle( id: 'ding', title: 'ding', - input_message_content: InputTextMessageContent( - message_text: '*_dong_*', parse_mode: 'MarkdownV2')), + inputMessageContent: InputTextMessageContent( + messageText: '*_dong_*', parseMode: 'MarkdownV2')), ])); ``` diff --git a/TeleDart.iml b/TeleDart.iml deleted file mode 100644 index 75734c90..00000000 --- a/TeleDart.iml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/analysis_options.yaml b/analysis_options.yaml index a681144b..0376e61d 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -10,7 +10,6 @@ linter: - always_declare_return_types - cancel_subscriptions - hash_and_equals - - iterable_contains_unrelated_type - - list_remove_unrelated_type + - collection_methods_unrelated_type - prefer_expression_function_bodies - test_types_in_equals diff --git a/example/main.dart b/example/main.dart index 19437a16..9207841e 100644 --- a/example/main.dart +++ b/example/main.dart @@ -16,10 +16,10 @@ Future main() async { // var webhook = await Webhook.createHttpsWebhok( // Telegram(envVars['BOT_TOKEN']!), // envVars['HOST_URL']!, - // envVars['BOT_TOKEN']!, // io.File(envVars['CERT_PATH']!), // io.File(envVars['KEY_PATH']!), - // port: int.parse(envVars['BOT_PORT']!)); + // port: int.parse(envVars['BOT_PORT']!), + // secretToken: envVars['SECRET_TOKEN']!); // var teledart = TeleDart(envVars['BOT_TOKEN']!, Event(username!), fetcher: webhook); teledart.start(); @@ -30,8 +30,7 @@ Future main() async { // Sick of boilerplates? Reply messages like below, nice and tidy // Short hands also available for answer query methods - teledart.onCommand('glory') - .listen((message) => message.reply('to Ukraine!')); + teledart.onCommand('glory').listen((message) => message.reply('to Ukraine!')); // You can also utilise regular expressions teledart @@ -53,12 +52,12 @@ Future main() async { InlineQueryResultArticle( id: 'ping', title: 'ping', - input_message_content: InputTextMessageContent( - message_text: '*pong*', parse_mode: 'MarkdownV2')), + inputMessageContent: InputTextMessageContent( + messageText: '*pong*', parseMode: 'MarkdownV2')), InlineQueryResultArticle( id: 'ding', title: 'ding', - input_message_content: InputTextMessageContent( - message_text: '*_dong_*', parse_mode: 'MarkdownV2')), + inputMessageContent: InputTextMessageContent( + messageText: '*_dong_*', parseMode: 'MarkdownV2')), ])); } diff --git a/lib/src/teledart/event/event.dart b/lib/src/teledart/event/event.dart index df8d0ec9..001e5b09 100644 --- a/lib/src/teledart/event/event.dart +++ b/lib/src/teledart/event/event.dart @@ -69,32 +69,32 @@ class Event { void emitUpdate(Update update) { if (update.message != null) { _messageStreamController.add(update.message!); - } else if (update.edited_message != null) { - _editedMessageStreamController.add(update.edited_message!); - } else if (update.channel_post != null) { - _channelPostStreamController.add(update.channel_post!); - } else if (update.edited_channel_post != null) { - _editedChannelPostStreamController.add(update.edited_channel_post!); - } else if (update.inline_query != null) { - _inlineQueryStreamController.add(update.inline_query!); - } else if (update.chosen_inline_result != null) { - _chosenInlineResultStreamController.add(update.chosen_inline_result!); - } else if (update.callback_query != null) { - _callbackQueryStreamController.add(update.callback_query!); - } else if (update.shipping_query != null) { - _shippingQueryStreamController.add(update.shipping_query!); - } else if (update.pre_checkout_query != null) { - _preCheckoutQueryStreamController.add(update.pre_checkout_query!); + } else if (update.editedMessage != null) { + _editedMessageStreamController.add(update.editedMessage!); + } else if (update.channelPost != null) { + _channelPostStreamController.add(update.channelPost!); + } else if (update.editedChannelPost != null) { + _editedChannelPostStreamController.add(update.editedChannelPost!); + } else if (update.inlineQuery != null) { + _inlineQueryStreamController.add(update.inlineQuery!); + } else if (update.chosenInlineResult != null) { + _chosenInlineResultStreamController.add(update.chosenInlineResult!); + } else if (update.callbackQuery != null) { + _callbackQueryStreamController.add(update.callbackQuery!); + } else if (update.shippingQuery != null) { + _shippingQueryStreamController.add(update.shippingQuery!); + } else if (update.preCheckoutQuery != null) { + _preCheckoutQueryStreamController.add(update.preCheckoutQuery!); } else if (update.poll != null) { _pollStreamController.add(update.poll!); - } else if (update.poll_answer != null) { - _pollAnswerStreamController.add(update.poll_answer!); - } else if (update.my_chat_member != null) { - _myChatMemberStreamController.add(update.my_chat_member!); - } else if (update.chat_member != null) { - _chatMemberStreamController.add(update.chat_member!); - } else if (update.chat_join_request != null) { - _chatJoinRequestStreamController.add(update.chat_join_request!); + } else if (update.pollAnswer != null) { + _pollAnswerStreamController.add(update.pollAnswer!); + } else if (update.myChatMember != null) { + _myChatMemberStreamController.add(update.myChatMember!); + } else if (update.chatMember != null) { + _chatMemberStreamController.add(update.chatMember!); + } else if (update.chatJoinRequest != null) { + _chatJoinRequestStreamController.add(update.chatJoinRequest!); } else { throw TeleDartEventException('Receieved unrecognised update'); } @@ -108,7 +108,7 @@ class Event { if (keyword == null) { if (entityType == null) { // no keyword and entityType - return (message.entities ?? message.caption_entities) == null; + return (message.entities ?? message.captionEntities) == null; } else { // no keyword but entityType return entityType == '*' || message.entityOf(entityType) != null; @@ -118,18 +118,19 @@ class Event { throw TeleDartEventException( 'Attribute \'keyword\' accepts type of String or RegExp'); } else if (entityType == null) { - return (message.entities ?? message.caption_entities) == null && + return (message.entities ?? message.captionEntities) == null && (message.text ?? message.caption ?? '').contains(keyword); } else if (message.entityOf(entityType) == null) { return false; - } else if (entityType == MessageEntity.TEXT_MENTION) { + } else if (entityType == MessageEntity.typeTextMention) { var userId = message.entityOf(entityType)?.user?.id; - var firstName = message.entityOf(entityType)?.user?.first_name; + var firstName = message.entityOf(entityType)?.user?.firstName; if (keyword is RegExp) { - var hasMatch = false; - if (firstName != null) keyword.hasMatch(firstName); - if (userId != null) keyword.hasMatch(userId.toString()); - return hasMatch; + var matchFirstName = + firstName != null ? keyword.hasMatch(firstName) : false; + var matchUserId = + userId != null ? keyword.hasMatch(userId.toString()) : false; + return matchFirstName || matchUserId; } else { return keyword == firstName || keyword == userId; } @@ -140,33 +141,37 @@ class Event { case '*': // Any entityType entityText = (message.text ?? message.caption ?? ''); break; - case MessageEntity.MENTION: // '\@${keyword}' - case MessageEntity.CASHTAG: // '\$${keyword}' - case MessageEntity.HASHTAG: // '\#${keyword}' + case MessageEntity.typeMention: // '\@${keyword}' + case MessageEntity.typeCashtag: // '\$${keyword}' + case MessageEntity.typeHashtag: // '\#${keyword}' entityText = message.getEntity(entityType)?.substring(1) ?? ''; break; - case 'bot_command': // '\/${keyword}' or '\/${keyword}\@${me.username}' + case MessageEntity + .typeBotCommand: // '\/${keyword}' or '\/${keyword}\@${me.username}' entityText = message .getEntity(entityType) ?.substring(1) - .replaceAll('\@$username', '') ?? + .replaceAll('@$username', '') ?? ''; break; - case MessageEntity.URL: - case MessageEntity.EMAIL: - case MessageEntity.PHONE_NUMBER: - case MessageEntity.BOLD: - case MessageEntity.ITALIC: - case MessageEntity.SPOILER: - case MessageEntity.CODE: - case MessageEntity.PRE: - case MessageEntity.UNDERLINE: - case MessageEntity.STRIKETHROUGH: + case MessageEntity.typeUrl: + case MessageEntity.typeEmail: + case MessageEntity.typePhoneNmber: + case MessageEntity.typeItalic: + case MessageEntity.typeSpolier: + case MessageEntity.typeCode: + case MessageEntity + .typePre: // TODO: need to return language prop somehow + case MessageEntity.typeUnderline: + case MessageEntity.typeStrikethrough: entityText = message.getEntity(entityType) ?? ''; break; - case MessageEntity.TEXT_LINK: + case MessageEntity.typeTextLink: entityText = message.entityOf(entityType)?.url ?? ''; break; + case MessageEntity.typeCustomEmoji: + entityText = message.entityOf(entityType)?.customEmojiId ?? ''; + break; default: // Dynamically listen to message types. entityText = message.getEntity(entityType) ?? ''; break; diff --git a/lib/src/teledart/fetch/long_polling.dart b/lib/src/teledart/fetch/long_polling.dart index 2275468d..000eeadf 100644 --- a/lib/src/teledart/fetch/long_polling.dart +++ b/lib/src/teledart/fetch/long_polling.dart @@ -16,7 +16,6 @@ * along with this program. If not, see . */ -import 'dart:async'; import 'dart:core'; import 'dart:io'; @@ -31,17 +30,18 @@ import 'abstract_update_fetcher.dart'; class LongPolling extends AbstractUpdateFetcher { final Telegram telegram; - final MAX_TIMEOUT = 50; + final maxTimeout = 50; + final defaultRetryDelay = Duration(seconds: 5); int offset; int limit; int timeout; - List? allowed_updates; + List? allowedUpdates; bool _isPolling = false; bool get isPolling => _isPolling; - Duration retryDelay = Duration(minutes: 1); + Duration retryDelay = Duration(seconds: 5); /// Setup long polling /// @@ -51,12 +51,12 @@ class LongPolling extends AbstractUpdateFetcher { {this.offset = 0, this.limit = 100, this.timeout = 30, - this.allowed_updates}) { + this.allowedUpdates}) { if (limit > 100 || limit < 1) { throw LongPollingException('Limit must between 1 and 100.'); } - if (timeout > MAX_TIMEOUT) { - throw LongPollingException('Timeout may not greater than $MAX_TIMEOUT.'); + if (timeout > maxTimeout) { + throw LongPollingException('Timeout may not greater than $maxTimeout.'); } } @@ -89,12 +89,12 @@ class LongPolling extends AbstractUpdateFetcher { offset: offset, limit: limit, timeout: timeout, - allowed_updates: allowed_updates) + allowedUpdates: allowedUpdates) .then((updates) { if (updates.isNotEmpty) { for (var update in updates) { emitUpdate(update); - offset = update.update_id + 1; + offset = update.updateId + 1; } } _resetRetryDelay(); @@ -109,7 +109,10 @@ class LongPolling extends AbstractUpdateFetcher { } void _onRecursivePollingHttpError(HttpClientException error) { - if (error.isHttpClientError()) { + if (error.isTooManyRequests()) { + retryDelay = error.parameters?.retryAfter_ ?? retryDelay; + _onRecursivePollingError(error); + } else if (error.isHttpClientError()) { _isPolling = false; throw LongPollingException(error.toString()); } else { @@ -118,14 +121,15 @@ class LongPolling extends AbstractUpdateFetcher { } void _onRecursivePollingError(Object error) { + // `error` should be `Error` or `Exception` type print('${DateTime.now()} $error'); - print('Retrying in ${retryDelay.inMinutes} minute(s)...'); + print('Retrying in ${retryDelay.inSeconds} second(s)...'); _delayRetry(); _doubleRetryDelay(); _recursivePolling(); } - void _resetRetryDelay() => retryDelay = Duration(minutes: 1); + void _resetRetryDelay() => retryDelay = defaultRetryDelay; void _doubleRetryDelay() => retryDelay *= 2; void _delayRetry() => sleep(retryDelay); } diff --git a/lib/src/teledart/fetch/webhook.dart b/lib/src/teledart/fetch/webhook.dart index 1c07d269..2a6ca8a5 100644 --- a/lib/src/teledart/fetch/webhook.dart +++ b/lib/src/teledart/fetch/webhook.dart @@ -34,13 +34,13 @@ class Webhook extends AbstractUpdateFetcher { final io.HttpServer _server; String url; - String? ip_address; - String secretPath; + String? ipAddress; int port; int? serverPort; - int max_connections; - List? allowed_updates; - bool? drop_pending_updates; + int maxConnections; + List? allowedUpdates; + bool? dropPendingUpdates; + String? secretToken; io.File? certificate; io.File? privateKey; @@ -50,96 +50,99 @@ class Webhook extends AbstractUpdateFetcher { /// /// Webhook server listens to [port] by default, set [serverPort] to override. /// - /// Set [url] as host name e.g. `https://example.com`, suggested to use bot tokan as [secretPath]. + /// Set [url] as host name e.g. `https://example.com`. /// /// Default [port] is `443`, Telegram API supports `443`, `80`, `88`, `8443`. /// Provide [privateKey] and [certificate] pair for HTTPS configuration /// /// Throws [WebhookException] if [port] is not supported by Telegram - /// or [max_connections] is less than 1 or greater than 100. - Webhook(this.telegram, this.url, this.secretPath, this._server, - {this.ip_address, + /// or [maxConnections] is less than 1 or greater than 100. + Webhook(this.telegram, this.url, this._server, + {this.ipAddress, this.certificate, this.privateKey, this.port = 443, this.serverPort, this.uploadCertificate = false, - this.max_connections = 40, - this.allowed_updates, - this.drop_pending_updates}) { + this.maxConnections = 40, + this.allowedUpdates, + this.dropPendingUpdates, + this.secretToken}) { if (![443, 80, 88, 8443].contains(port)) { throw WebhookException( 'Ports currently supported for Webhooks: 443, 80, 88, 8443.'); } - if (max_connections > 100 || max_connections < 1) { + if (maxConnections > 100 || maxConnections < 1) { throw WebhookException('Connection limit must between 1 and 100.'); } - - // prefix url and secret path - if (url.endsWith('\/')) url.substring(0, url.length - 1); - if (!secretPath.startsWith('\/')) { - secretPath = '\/' + secretPath; - } } - static Future createHttpWebhok( - Telegram telegram, String url, String secretPath, - {String? ip_address, + static Future createHttpWebhok(Telegram telegram, String url, + {String? ipAddress, int port = 80, int? serverPort, - int max_connections = 40, - List? allowed_updates, - bool? drop_pending_updates}) async { + int maxConnections = 40, + List? allowedUpdates, + bool? dropPendingUpdates, + String? secretToken}) async { var server = await io.HttpServer.bind( io.InternetAddress.anyIPv4.address, serverPort ?? port); - return Webhook(telegram, url, secretPath, server, - ip_address: ip_address, + return Webhook(telegram, url, server, + ipAddress: ipAddress, port: port, serverPort: serverPort, - max_connections: max_connections, - allowed_updates: allowed_updates); + maxConnections: maxConnections, + allowedUpdates: allowedUpdates, + secretToken: secretToken); } - static Future createHttpsWebhok(Telegram telegram, String url, - String secretPath, io.File certificate, io.File privateKey, - {String? ip_address, + static Future createHttpsWebhok( + Telegram telegram, String url, io.File certificate, io.File privateKey, + {String? ipAddress, int port = 80, int? serverPort, bool uploadCertificate = false, - int max_connections = 40, - List? allowed_updates, - bool? drop_pending_updates}) async { + int maxConnections = 40, + List? allowedUpdates, + bool? dropPendingUpdates, + String? secretToken}) async { var server = await io.HttpServer.bindSecure( io.InternetAddress.anyIPv4.address, serverPort ?? port, io.SecurityContext() ..useCertificateChainBytes(certificate.readAsBytesSync()) ..usePrivateKeyBytes(privateKey.readAsBytesSync())); - return Webhook(telegram, url, secretPath, server, - ip_address: ip_address, + return Webhook(telegram, url, server, + ipAddress: ipAddress, certificate: certificate, privateKey: privateKey, port: port, serverPort: serverPort, uploadCertificate: uploadCertificate, - max_connections: max_connections, - allowed_updates: allowed_updates); + maxConnections: maxConnections, + allowedUpdates: allowedUpdates, + secretToken: secretToken); } - Future setWebhook() async => - await telegram.setWebhook('$url:$port$secretPath', - ip_address: ip_address, - certificate: uploadCertificate ? certificate : null, - max_connections: max_connections, - allowed_updates: allowed_updates, - drop_pending_updates: drop_pending_updates); + Future setWebhook() async => await telegram.setWebhook('$url:$port', + ipAddress: ipAddress, + certificate: uploadCertificate ? certificate : null, + maxConnections: maxConnections, + allowedUpdates: allowedUpdates, + dropPendingUpdates: dropPendingUpdates, + secretToken: secretToken); /// Apply webhook configuration on Telegram API, and start the webhook server. @override Future start() async { if (await setWebhook()) { _server.listen((io.HttpRequest request) { - if (request.method == 'POST' && request.uri.path == secretPath) { + var isPostRequest = request.method == 'POST'; + var isAuthorised = secretToken == null || + secretToken == + request.headers.value('X-Telegram-Bot-Api-Secret-Token'); + + if (isPostRequest && isAuthorised) { request.cast>().transform(utf8.decoder).join().then((data) { emitUpdate(Update.fromJson(jsonDecode(data))); request.response @@ -154,14 +157,15 @@ class Webhook extends AbstractUpdateFetcher { } }); } else { - throw WebhookException('Telegram API returns an error while attempting to set the webhook.'); + throw WebhookException( + 'Telegram API returns an error while attempting to set the webhook.'); } } /// Remove webhook configuration from Telegram API, and stop the webhook server. @override - Future stop({bool? drop_pending_updates}) async { - await telegram.deleteWebhook(drop_pending_updates: drop_pending_updates); + Future stop({bool? dropPendingUpdates}) async { + await telegram.deleteWebhook(dropPendingUpdates: dropPendingUpdates); return _server.close(); } } diff --git a/lib/src/teledart/model/callback_query.dart b/lib/src/teledart/model/callback_query.dart index 2c1f02d2..4108138b 100644 --- a/lib/src/teledart/model/callback_query.dart +++ b/lib/src/teledart/model/callback_query.dart @@ -37,10 +37,10 @@ class TeleDartCallbackQuery extends CallbackQuery { id: callbackQuery.id, from: callbackQuery.from, message: callbackQuery.message, - inline_message_id: callbackQuery.inline_message_id, - chat_instance: callbackQuery.chat_instance, + inlineMessageId: callbackQuery.inlineMessageId, + chatInstance: callbackQuery.chatInstance, data: callbackQuery.data, - game_short_name: callbackQuery.game_short_name, + gameShortName: callbackQuery.gameShortName, ); TeleDartMessage? get teledartMessage => @@ -57,10 +57,10 @@ class TeleDartCallbackQuery extends CallbackQuery { /// for more information about those options.** Future answer({ String? text, - bool? show_alert, + bool? showAlert, String? url, - int? cache_time, + int? cacheTime, }) => _teledart.answerCallbackQuery(id, - text: text, show_alert: show_alert, url: url, cache_time: cache_time); + text: text, showAlert: showAlert, url: url, cacheTime: cacheTime); } diff --git a/lib/src/teledart/model/inline_query.dart b/lib/src/teledart/model/inline_query.dart index 209901a1..1cc2770f 100644 --- a/lib/src/teledart/model/inline_query.dart +++ b/lib/src/teledart/model/inline_query.dart @@ -37,7 +37,7 @@ class TeleDartInlineQuery extends InlineQuery { from: inlineQuery.from, query: inlineQuery.query, offset: inlineQuery.offset, - chat_type: inlineQuery.chat_type, + chatType: inlineQuery.chatType, location: inlineQuery.location, ); @@ -54,16 +54,17 @@ class TeleDartInlineQuery extends InlineQuery { /// for more information about those options.** Future answer( List results, { - int? cache_time, - bool? is_personal, - String? next_offset, - String? switch_pm_text, - String? switch_pm_parameter, + int? cacheTime, + bool? isPersonal, + String? nextOffset, + InlineQueryResultsButton? button, }) => - _teledart.answerInlineQuery(id, results, - cache_time: cache_time, - is_personal: is_personal, - next_offset: next_offset, - switch_pm_text: switch_pm_text, - switch_pm_parameter: switch_pm_parameter); + _teledart.answerInlineQuery( + id, + results, + cacheTime: cacheTime, + isPersonal: isPersonal, + nextOffset: nextOffset, + button: button, + ); } diff --git a/lib/src/teledart/model/message.dart b/lib/src/teledart/model/message.dart index bcf067a5..db55a268 100644 --- a/lib/src/teledart/model/message.dart +++ b/lib/src/teledart/model/message.dart @@ -35,24 +35,26 @@ class TeleDartMessage extends Message { TeleDartMessage(this._teledart, Message message) : super( - message_id: message.message_id, + messageId: message.messageId, + messageThreadId: message.messageThreadId, from: message.from, date: message.date, - sender_chat: message.sender_chat, + senderChat: message.senderChat, chat: message.chat, - forward_from: message.forward_from, - forward_from_chat: message.forward_from_chat, - forward_from_message_id: message.forward_from_message_id, - forward_signature: message.forward_signature, - forward_sender_name: message.forward_sender_name, - forward_date: message.forward_date, - is_automatic_forward: message.is_automatic_forward, - reply_to_message: message.reply_to_message, - via_bot: message.via_bot, - edit_date: message.edit_date, - has_protected_content: message.has_protected_content, - media_group_id: message.media_group_id, - author_signature: message.author_signature, + forwardFrom: message.forwardFrom, + forwardFromChat: message.forwardFromChat, + forwardFromMessageId: message.forwardFromMessageId, + forwardSignature: message.forwardSignature, + forwardSenderName: message.forwardSenderName, + forwardDate: message.forwardDate, + isTopicMessage: message.isTopicMessage, + isAutomaticForward: message.isAutomaticForward, + replyToMessage: message.replyToMessage, + viaBot: message.viaBot, + editDate: message.editDate, + hasProtectedContent: message.hasProtectedContent, + mediaGroupId: message.mediaGroupId, + authorSignature: message.authorSignature, text: message.text, entities: message.entities, animation: message.animation, @@ -60,46 +62,56 @@ class TeleDartMessage extends Message { document: message.document, photo: message.photo, sticker: message.sticker, + story: message.story, video: message.video, - video_note: message.video_note, + videoNote: message.videoNote, voice: message.voice, caption: message.caption, - caption_entities: message.caption_entities, + captionEntities: message.captionEntities, + hasMediaSpoiler: message.hasMediaSpoiler, contact: message.contact, dice: message.dice, game: message.game, poll: message.poll, venue: message.venue, location: message.location, - new_chat_members: message.new_chat_members, - left_chat_member: message.left_chat_member, - new_chat_title: message.new_chat_title, - new_chat_photo: message.new_chat_photo, - delete_chat_photo: message.delete_chat_photo, - group_chat_created: message.group_chat_created, - supergroup_chat_created: message.supergroup_chat_created, - channel_chat_created: message.channel_chat_created, - message_auto_delete_timer_changed: - message.message_auto_delete_timer_changed, - migrate_to_chat_id: message.migrate_to_chat_id, - migrate_from_chat_id: message.migrate_from_chat_id, - pinned_message: message.pinned_message, + newChatMembers: message.newChatMembers, + leftChatMember: message.leftChatMember, + newChatTitle: message.newChatTitle, + newChatPhoto: message.newChatPhoto, + deleteChatPhoto: message.deleteChatPhoto, + groupChatCreated: message.groupChatCreated, + supergroupChatCreated: message.supergroupChatCreated, + channelChatCreated: message.channelChatCreated, + messageAutoDeleteTimerChanged: message.messageAutoDeleteTimerChanged, + migrateToChatId: message.migrateToChatId, + migrateFromChatId: message.migrateFromChatId, + pinnedMessage: message.pinnedMessage, invoice: message.invoice, - successful_payment: message.successful_payment, - connected_website: message.connected_website, - passport_data: message.passport_data, - proximity_alert_triggered: message.proximity_alert_triggered, - voice_chat_scheduled: message.voice_chat_scheduled, - voice_chat_started: message.voice_chat_started, - voice_chat_ended: message.voice_chat_ended, - voice_chat_participants_invited: - message.voice_chat_participants_invited, - reply_markup: message.reply_markup, + successfulPayment: message.successfulPayment, + userShared: message.userShared, + chatShared: message.chatShared, + connectedWebsite: message.connectedWebsite, + writeAccessAllowed: message.writeAccessAllowed, + passportData: message.passportData, + proximityAlertTriggered: message.proximityAlertTriggered, + forumTopicCreated: message.forumTopicCreated, + forumTopicEdited: message.forumTopicEdited, + forumTopicClosed: message.forumTopicClosed, + forumTopicReopened: message.forumTopicReopened, + generalForumTopicHidden: message.generalForumTopicHidden, + generalForumTopicUnhidden: message.generalForumTopicUnhidden, + videoChatScheduled: message.videoChatScheduled, + videoChatStarted: message.videoChatStarted, + videoChatEnded: message.videoChatEnded, + videoChatParticipantsInvited: message.videoChatParticipantsInvited, + webAppData: message.webAppData, + replyMarkup: message.replyMarkup, ); /// Reply to the recieved message with text /// - /// A wrapper around [TeleDart.replyMessage]. + /// A wrapper around [TeleDart.sendMessage]. /// On success, returns the sent [Message]. /// /// Apart from a [String] to reply with, it can @@ -111,25 +123,26 @@ class TeleDartMessage extends Message { Future reply( String text, { bool withQuote = false, - String? parse_mode, + String? parseMode, List? entities, - bool? disable_web_page_preview, - bool? disable_notification, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup, + bool? disableWebPagePreview, + bool? disableNotification, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup, }) => _teledart.sendMessage(chat.id, text, - parse_mode: parse_mode, + messageThreadId: messageThreadId, + parseMode: parseMode, entities: entities, - disable_web_page_preview: disable_web_page_preview, - disable_notification: disable_notification, - reply_to_message_id: withQuote ? message_id : null, - allow_sending_without_reply: allow_sending_without_reply, - reply_markup: reply_markup); + disableWebPagePreview: disableWebPagePreview, + disableNotification: disableNotification, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); /// Reply to the recieved message with an image /// - /// A wrapper around [TeleDart.replyPhoto]. + /// A wrapper around [TeleDart.sendPhoto]. /// On success, returns the sent [Message]. /// /// Apart from a [photo] to reply with, it can @@ -142,24 +155,27 @@ class TeleDartMessage extends Message { dynamic photo, { bool withQuote = false, String? caption, - String? parse_mode, - List? caption_entities, - bool? disable_notification, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup, + String? parseMode, + List? captionEntities, + bool? hasSpoiler, + bool? disableNotification, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup, }) => _teledart.sendPhoto(chat.id, photo, + messageThreadId: messageThreadId, caption: caption, - parse_mode: parse_mode, - caption_entities: caption_entities, - disable_notification: disable_notification, - reply_to_message_id: withQuote ? message_id : null, - allow_sending_without_reply: allow_sending_without_reply, - reply_markup: reply_markup); + parseMode: parseMode, + captionEntities: captionEntities, + hasSpoiler: hasSpoiler, + disableNotification: disableNotification, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); /// Reply to the recieved message with an audio /// - /// A wrapper around [TeleDart.replyAudio]. + /// A wrapper around [TeleDart.sendAudio]. /// On success, returns the sent [Message]. /// /// Apart from an [audio] to reply with, it can @@ -172,32 +188,33 @@ class TeleDartMessage extends Message { dynamic audio, { bool withQuote = false, String? caption, - String? parse_mode, - List? caption_entities, + String? parseMode, + List? captionEntities, int? duration, String? performer, String? title, - dynamic thumb, - bool? disable_notification, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup, + dynamic thumbnail, + bool? disableNotification, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup, }) => _teledart.sendAudio(chat.id, audio, + messageThreadId: messageThreadId, caption: caption, - parse_mode: parse_mode, - caption_entities: caption_entities, + parseMode: parseMode, + captionEntities: captionEntities, duration: duration, performer: performer, title: title, - thumb: thumb, - disable_notification: disable_notification, - reply_to_message_id: withQuote ? message_id : null, - allow_sending_without_reply: allow_sending_without_reply, - reply_markup: reply_markup); + thumbnail: thumbnail, + disableNotification: disableNotification, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); /// Reply to the recieved message with a document /// - /// A wrapper around [TeleDart.replyDocument]. + /// A wrapper around [TeleDart.sendDocument]. /// On success, returns the sent [Message]. /// /// Apart from a [document] to reply with, it can @@ -209,27 +226,28 @@ class TeleDartMessage extends Message { Future replyDocument( dynamic document, { bool withQuote = false, - dynamic thumb, + dynamic thumbnail, String? caption, - String? parse_mode, - List? caption_entities, - bool? disable_notification, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup, + String? parseMode, + List? captionEntities, + bool? disableNotification, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup, }) => _teledart.sendDocument(chat.id, document, - thumb: thumb, + messageThreadId: messageThreadId, + thumbnail: thumbnail, caption: caption, - parse_mode: parse_mode, - caption_entities: caption_entities, - disable_notification: disable_notification, - reply_to_message_id: withQuote ? message_id : null, - allow_sending_without_reply: allow_sending_without_reply, - reply_markup: reply_markup); + parseMode: parseMode, + captionEntities: captionEntities, + disableNotification: disableNotification, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); /// Reply to the recieved message with a video /// - /// A wrapper around [TeleDart.replyVideo]. + /// A wrapper around [TeleDart.sendVideo]. /// On success, returns the sent [Message]. /// /// Apart from a [video] to reply with, it can @@ -244,32 +262,35 @@ class TeleDartMessage extends Message { int? duration, int? width, int? height, - dynamic thumb, + dynamic thumbnail, String? caption, - String? parse_mode, - List? caption_entities, - bool? supports_streaming, - bool? disable_notification, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup, + String? parseMode, + List? captionEntities, + bool? hasSpoiler, + bool? supportsStreaming, + bool? disableNotification, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup, }) => _teledart.sendVideo(chat.id, video, + messageThreadId: messageThreadId, duration: duration, width: width, height: height, - thumb: thumb, + thumbnail: thumbnail, caption: caption, - parse_mode: parse_mode, - caption_entities: caption_entities, - supports_streaming: supports_streaming, - disable_notification: disable_notification, - reply_to_message_id: withQuote ? message_id : null, - allow_sending_without_reply: allow_sending_without_reply, - reply_markup: reply_markup); + parseMode: parseMode, + captionEntities: captionEntities, + hasSpoiler: hasSpoiler, + supportsStreaming: supportsStreaming, + disableNotification: disableNotification, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); /// Reply to the recieved message with an animation (GIF or H.264/MPEG-4 AVC video without sound) /// - /// A wrapper around [TeleDart.replyAnimation]. + /// A wrapper around [TeleDart.sendAnimation]. /// On success, returns the sent [Message]. /// /// Apart from an [animation] to reply with, it can @@ -284,30 +305,33 @@ class TeleDartMessage extends Message { int? duration, int? width, int? height, - dynamic thumb, + dynamic thumbnail, String? caption, - String? parse_mode, - List? caption_entities, - bool? disable_notification, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup, + String? parseMode, + List? captionEntities, + bool? hasSpoiler, + bool? disableNotification, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup, }) => _teledart.sendAnimation(chat.id, animation, + messageThreadId: messageThreadId, duration: duration, width: width, height: height, - thumb: thumb, + thumbnail: thumbnail, caption: caption, - parse_mode: parse_mode, - caption_entities: caption_entities, - disable_notification: disable_notification, - reply_to_message_id: withQuote ? message_id : null, - allow_sending_without_reply: allow_sending_without_reply, - reply_markup: reply_markup); + parseMode: parseMode, + captionEntities: captionEntities, + hasSpoiler: hasSpoiler, + disableNotification: disableNotification, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); /// Reply to the recieved message with a voice message /// - /// A wrapper around [TeleDart.replyVoice]. + /// A wrapper around [TeleDart.sendVoice]. /// On success, returns the sent [Message]. /// /// Apart from a [voice] to reply with, it can @@ -320,54 +344,56 @@ class TeleDartMessage extends Message { dynamic voice, { bool withQuote = false, String? caption, - String? parse_mode, - List? caption_entities, - bool? disable_notification, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup, + String? parseMode, + List? captionEntities, + bool? disableNotification, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup, }) => _teledart.sendVoice(chat.id, voice, + messageThreadId: messageThreadId, caption: caption, - parse_mode: parse_mode, - caption_entities: caption_entities, - disable_notification: disable_notification, - reply_to_message_id: withQuote ? message_id : null, - allow_sending_without_reply: allow_sending_without_reply, - reply_markup: reply_markup); + parseMode: parseMode, + captionEntities: captionEntities, + disableNotification: disableNotification, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); /// Reply to the recieved message with a video note /// - /// A wrapper around [TeleDart.replyVideoNote]. + /// A wrapper around [TeleDart.sendVideoNote]. /// On success, returns the sent [Message]. /// - /// Apart from a [video_note] to reply with, it can + /// Apart from a [videoNote] to reply with, it can /// also take some options that control the message /// appearance and behavior. /// /// **Check [Telegram API documentation](https://core.telegram.org/bots/api#sendvideonote) /// for more information about those options.** Future replyVideoNote( - dynamic video_note, { + dynamic videoNote, { bool withQuote = false, int? duration, int? length, - dynamic thumb, - bool? disable_notification, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup, + dynamic thumbnail, + bool? disableNotification, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup, }) => - _teledart.sendVideoNote(chat.id, video_note, + _teledart.sendVideoNote(chat.id, videoNote, + messageThreadId: messageThreadId, duration: duration, length: length, - thumb: thumb, - disable_notification: disable_notification, - reply_to_message_id: withQuote ? message_id : null, - allow_sending_without_reply: allow_sending_without_reply, - reply_markup: reply_markup); + thumbnail: thumbnail, + disableNotification: disableNotification, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); /// Reply to the recieved message with a media group message (multiple media files) /// - /// A wrapper around [TeleDart.replyMediaGroup]. + /// A wrapper around [TeleDart.sendMediaGroup]. /// On success, returns the sent [Message]. /// /// Apart from a [List] to reply with, it can @@ -379,17 +405,18 @@ class TeleDartMessage extends Message { Future> replyMediaGroup( List media, { bool withQuote = false, - bool? disable_notification, - bool? allow_sending_without_reply, + bool? disableNotification, + bool? allowSendingWithoutReply, }) => _teledart.sendMediaGroup(chat.id, media, - disable_notification: disable_notification, - reply_to_message_id: withQuote ? message_id : null, - allow_sending_without_reply: allow_sending_without_reply); + messageThreadId: messageThreadId, + disableNotification: disableNotification, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply); /// Reply to the recieved message with a location /// - /// A wrapper around [TeleDart.replyLocation]. + /// A wrapper around [TeleDart.sendLocation]. /// On success, returns the sent [Message]. /// /// Apart from a [latitude] and a [longitude], it can @@ -402,27 +429,28 @@ class TeleDartMessage extends Message { double latitude, double longitude, { bool withQuote = false, - double? horizontal_accuracy, - int? live_period, + double? horizontalAccuracy, + int? livePeriod, int? heading, - int? proximity_alert_radius, - bool? disable_notification, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup, + int? proximityAlertRadius, + bool? disableNotification, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup, }) => _teledart.sendLocation(chat.id, latitude, longitude, - horizontal_accuracy: horizontal_accuracy, - live_period: live_period, + messageThreadId: messageThreadId, + horizontalAccuracy: horizontalAccuracy, + livePeriod: livePeriod, heading: heading, - proximity_alert_radius: proximity_alert_radius, - disable_notification: disable_notification, - reply_to_message_id: withQuote ? message_id : null, - allow_sending_without_reply: allow_sending_without_reply, - reply_markup: reply_markup); + proximityAlertRadius: proximityAlertRadius, + disableNotification: disableNotification, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); /// Reply to the recieved message with a venue message /// - /// A wrapper around [TeleDart.replyVenue]. + /// A wrapper around [TeleDart.sendVenue]. /// On success, returns the sent [Message]. /// /// Apart from a [latitude] and a [longitude] a [title] and an [address], @@ -437,56 +465,58 @@ class TeleDartMessage extends Message { String title, String address, { bool withQuote = false, - String? foursquare_id, - String? foursquare_type, - String? google_place_id, - String? google_place_type, - bool? disable_notification, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup, + String? foursquareId, + String? foursquareType, + String? googlePlaceId, + String? googlePlaceType, + bool? disableNotification, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup, }) => _teledart.sendVenue(chat.id, latitude, longitude, title, address, - foursquare_id: foursquare_id, - foursquare_type: foursquare_type, - google_place_id: google_place_id, - google_place_type: google_place_type, - disable_notification: disable_notification, - reply_to_message_id: withQuote ? message_id : null, - allow_sending_without_reply: allow_sending_without_reply, - reply_markup: reply_markup); + messageThreadId: messageThreadId, + foursquareId: foursquareId, + foursquareType: foursquareType, + googlePlaceId: googlePlaceId, + googlePlaceType: googlePlaceType, + disableNotification: disableNotification, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); /// Reply to the recieved message with a location /// - /// A wrapper around [TeleDart.replyContact]. + /// A wrapper around [TeleDart.sendContact]. /// On success, returns the sent [Message]. /// - /// Apart from a [phone_number] and a [first_name], it can + /// Apart from a [phoneNumber] and a [firstName], it can /// also take some options that control the message /// appearance and behavior. /// /// **Check [Telegram API documentation](https://core.telegram.org/bots/api#sendcontact) /// for more information about those options.** Future replyContact( - String phone_number, - String first_name, { + String phoneNumber, + String firstName, { bool withQuote = false, - String? last_name, + String? lastName, String? vcard, - bool? disable_notification, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup, + bool? disableNotification, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup, }) => - _teledart.sendContact(chat.id, phone_number, first_name, - last_name: last_name, + _teledart.sendContact(chat.id, phoneNumber, firstName, + messageThreadId: messageThreadId, + lastName: lastName, vcard: vcard, - disable_notification: disable_notification, - reply_to_message_id: withQuote ? message_id : null, - allow_sending_without_reply: allow_sending_without_reply, - reply_markup: reply_markup); + disableNotification: disableNotification, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); /// Reply to the recieved message with a poll /// - /// A wrapper around [TeleDart.replyPoll]. + /// A wrapper around [TeleDart.sendPoll]. /// On success, returns the sent [Message]. /// /// Apart from a [question] and a [List] of [options], it can @@ -495,40 +525,44 @@ class TeleDartMessage extends Message { /// /// **Check [Telegram API documentation](https://core.telegram.org/bots/api#sendpoll) /// for more information about those options.** - Future replyPoll(String question, List options, - {bool withQuote = false, - bool? is_anonymous, - String? type, - bool? allows_multiple_answers, - int? correct_option_id, - String? explanation, - String? explanation_parse_mode, - List? explanation_entities, - int? open_period, - int? close_date, - bool? is_closed, - bool? disable_notification, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) => + Future replyPoll( + String question, + List options, { + bool withQuote = false, + bool? isAnonymous, + String? type, + bool? allowsMultipleAnswers, + int? correctOptionId, + String? explanation, + String? explanationParseMode, + List? explanationEntities, + int? openPeriod, + int? closeDate, + bool? isClosed, + bool? disableNotification, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup, + }) => _teledart.sendPoll(chat.id, question, options, - is_anonymous: is_anonymous, + messageThreadId: messageThreadId, + isAnonymous: isAnonymous, type: type, - allows_multiple_answers: allows_multiple_answers, - correct_option_id: correct_option_id, + allowsMultipleAnswers: allowsMultipleAnswers, + correctOptionId: correctOptionId, explanation: explanation, - explanation_parse_mode: explanation_parse_mode, - explanation_entities: explanation_entities, - open_period: open_period, - close_date: close_date, - is_closed: is_closed, - disable_notification: disable_notification, - reply_to_message_id: withQuote ? message_id : null, - allow_sending_without_reply: allow_sending_without_reply, - reply_markup: reply_markup); + explanationParseMode: explanationParseMode, + explanationEntities: explanationEntities, + openPeriod: openPeriod, + closeDate: closeDate, + isClosed: isClosed, + disableNotification: disableNotification, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); /// Reply to the recieved message with a dice message /// - /// A wrapper around [TeleDart.replyDice]. + /// A wrapper around [TeleDart.sendDice]. /// On success, returns the sent [Message]. /// /// It can take some options that control the message @@ -536,22 +570,112 @@ class TeleDartMessage extends Message { /// /// **Check [Telegram API documentation](https://core.telegram.org/bots/api#senddice) /// for more information about those options.** - Future replyDice( - {bool withQuote = false, - String emoji = Dice.DICE, - bool? disable_notification, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) => + Future replyDice({ + int? messageThreadId, + bool withQuote = false, + String emoji = Dice.emojiDice, + bool? disableNotification, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup, + }) => _teledart.sendDice(chat.id, + messageThreadId: messageThreadId ?? this.messageThreadId, emoji: emoji, - disable_notification: disable_notification, - reply_to_message_id: withQuote ? message_id : null, - allow_sending_without_reply: allow_sending_without_reply, - reply_markup: reply_markup); + disableNotification: disableNotification, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); + + /// Reply to the recieved message with an invoice + /// + /// A wrapper around [TeleDart.sendInvoice]. + /// On success, returns the sent [Message]. + /// + /// Apart from a [title], a [description], a [payload], a [providerToken] and a list of [prices], + /// it can also take some options that control the message appearance and behavior. + /// + /// **Check [Telegram API documentation](https://core.telegram.org/bots/api#sendinvoice) + /// for more information about those options.** + Future replyInvoice( + String title, + String description, + String payload, + String providerToken, + String currency, + List prices, { + bool withQuote = false, + int? maxTipAmount, + List? suggestedTipAmounts, + String? startParameter, + String? providerData, + String? photoUrl, + int? photoSize, + int? photoWidth, + int? photoHeight, + bool? needName, + bool? needPhoneNumber, + bool? needEmail, + bool? needShippingAddress, + bool? sendPhoneNumberToProvider, + bool? sendEmailToProvider, + bool? isFlexible, + bool? disableNotification, + bool? protectContent, + bool? allowSendingWithoutReply, + InlineKeyboardMarkup? replyMarkup, + }) => + _teledart.sendInvoice( + chat.id, title, description, payload, providerToken, currency, prices, + messageThreadId: messageThreadId, + maxTipAmount: maxTipAmount, + suggestedTipAmounts: suggestedTipAmounts, + startParameter: startParameter, + providerData: providerData, + photoUrl: photoUrl, + photoSize: photoSize, + photoWidth: photoWidth, + photoHeight: photoHeight, + needName: needName, + needPhoneNumber: needPhoneNumber, + needEmail: needEmail, + needShippingAddress: needShippingAddress, + sendPhoneNumberToProvider: sendPhoneNumberToProvider, + sendEmailToProvider: sendEmailToProvider, + isFlexible: isFlexible, + disableNotification: disableNotification, + protectContent: protectContent, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); + + /// Reply to the recieved message with a game + /// + /// A wrapper around [TeleDart.sendGame]. + /// On success, returns the sent [Message]. + /// + /// Apart from a [gameShortName], it can also take some options that control the message appearance and behavior. + /// + /// **Check [Telegram API documentation](https://core.telegram.org/bots/api#sendgame) + /// for more information about those options.** + Future replyGame( + String gameShortName, { + bool withQuote = false, + bool? disableNotification, + bool? protectContent, + bool? allowSendingWithoutReply, + InlineKeyboardMarkup? replyMarkup, + }) => + _teledart.sendGame(chat.id, gameShortName, + messageThreadId: messageThreadId, + disableNotification: disableNotification, + protectContent: protectContent, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); /// Reply to the recieved message with an image /// - /// A wrapper around [TeleDart.replySticker]. + /// A wrapper around [TeleDart.sendSticker]. /// On success, returns the sent [Message]. /// /// Apart from a [sticker] to reply with, it can @@ -560,14 +684,71 @@ class TeleDartMessage extends Message { /// /// **Check [Telegram API documentation](https://core.telegram.org/bots/api#sendsticker) /// for more information about those options.** - Future replySticker(dynamic sticker, - {bool withQuote = false, - bool? disable_notification, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) => + Future replySticker( + dynamic sticker, { + bool withQuote = false, + bool? disableNotification, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup, + }) => _teledart.sendSticker(chat.id, sticker, - disable_notification: disable_notification, - reply_to_message_id: withQuote ? message_id : null, - allow_sending_without_reply: allow_sending_without_reply, - reply_markup: reply_markup); + messageThreadId: messageThreadId, + disableNotification: disableNotification, + replyToMessageId: withQuote ? messageId : null, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); + + /// Copy the recieved message to a channel or chat. + /// + /// A wrapper around [TeleDart.copyMessage]. + /// On success, returns the sent [MessageId]. + /// + /// Apart from a [chatId] to copy the message to, it can + /// also take some options that control the message + /// + /// **Check [Telegram API documentation](https://core.telegram.org/bots/api#copymessage) + /// for more information about those options.** + Future copyTo( + int chatId, { + int? messageThreadId, + int? replyToMessageId, + String? caption, + String? parseMode, + List? captionEntities, + bool? disableNotification, + bool? protectContent, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup, + }) => + _teledart.copyMessage(chatId, chat.id, messageId, + messageThreadId: messageThreadId, + caption: caption, + parseMode: parseMode, + captionEntities: captionEntities, + disableNotification: disableNotification, + protectContent: protectContent, + replyToMessageId: replyToMessageId, + allowSendingWithoutReply: allowSendingWithoutReply, + replyMarkup: replyMarkup); + + /// Forward the recieved message to a channel or chat. + /// + /// A wrapper around [TeleDart.forwardMessage]. + /// On success, returns the sent [Message]. + /// + /// Apart from a [chatId] to forward the message to, it can + /// also take some options that control the message + /// + /// **Check [Telegram API documentation](https://core.telegram.org/bots/api#forwardmessage) + /// for more information about those options.** + Future forwardTo( + int chatId, { + int? messageThreadId, + bool? disableNotification, + bool? protectContent, + }) => + _teledart.forwardMessage(chatId, chat.id, messageId, + messageThreadId: messageThreadId, + disableNotification: disableNotification, + protectContent: protectContent); } diff --git a/lib/src/teledart/model/pre_checkout_query.dart b/lib/src/teledart/model/pre_checkout_query.dart index 091c0eef..00d5dde4 100644 --- a/lib/src/teledart/model/pre_checkout_query.dart +++ b/lib/src/teledart/model/pre_checkout_query.dart @@ -36,10 +36,10 @@ class TeleDartPreCheckoutQuery extends PreCheckoutQuery { id: preCheckoutQuery.id, from: preCheckoutQuery.from, currency: preCheckoutQuery.currency, - total_amount: preCheckoutQuery.total_amount, - invoice_payload: preCheckoutQuery.invoice_payload, - shipping_option_id: preCheckoutQuery.shipping_option_id, - order_info: preCheckoutQuery.order_info, + totalAmount: preCheckoutQuery.totalAmount, + invoicePayload: preCheckoutQuery.invoicePayload, + shippingOptionId: preCheckoutQuery.shippingOptionId, + orderInfo: preCheckoutQuery.orderInfo, ); /// Answer the recieved pre-checkout query @@ -48,11 +48,11 @@ class TeleDartPreCheckoutQuery extends PreCheckoutQuery { /// On success, returns true. /// /// It can take a [bool] that indicates - /// if the pre-checkout is possible, and an [error_message] that + /// if the pre-checkout is possible, and an [errorMessage] that /// is shown to user if [ok] is false (You don't have to specify it if [ok] is true). /// /// **Check [Telegram API documentation](https://core.telegram.org/bots/api#answerprecheckoutquery) /// for more information about those options.** - Future answer(bool ok, {String? error_message}) => - _teledart.answerPreCheckoutQuery(id, ok, error_message: error_message); + Future answer(bool ok, {String? errorMessage}) => + _teledart.answerPreCheckoutQuery(id, ok, errorMessage: errorMessage); } diff --git a/lib/src/teledart/model/shipping_query.dart b/lib/src/teledart/model/shipping_query.dart index a9a076f5..b6e769d6 100644 --- a/lib/src/teledart/model/shipping_query.dart +++ b/lib/src/teledart/model/shipping_query.dart @@ -35,8 +35,8 @@ class TeleDartShippingQuery extends ShippingQuery { : super( id: shippingQuery.id, from: shippingQuery.from, - invoice_payload: shippingQuery.invoice_payload, - shipping_address: shippingQuery.shipping_address, + invoicePayload: shippingQuery.invoicePayload, + shippingAddress: shippingQuery.shippingAddress, ); /// Answer the recieved shipping query @@ -51,7 +51,7 @@ class TeleDartShippingQuery extends ShippingQuery { /// **Check [Telegram API documentation](https://core.telegram.org/bots/api#answershippingquery) /// for more information about those options.** Future answer(bool ok, - {List? shipping_options, String? error_message}) => + {List? shippingOptions, String? errorMessage}) => _teledart.answerShippingQuery(id, ok, - shipping_options: shipping_options, error_message: error_message); + shippingOptions: shippingOptions, errorMessage: errorMessage); } diff --git a/lib/src/teledart/teledart.dart b/lib/src/teledart/teledart.dart index 277f1853..fa859376 100644 --- a/lib/src/teledart/teledart.dart +++ b/lib/src/teledart/teledart.dart @@ -48,9 +48,6 @@ import 'model/shipping_query.dart'; /// /// Here the `message` variable will be an instance of [TeleDartMessage], /// since the onMessage method returns a [Stream]. -/// -/// In case you want to use methods of the [Telegram] class, you can do so -/// by calling them through [TeleDart.telegram] class TeleDart extends Telegram { final Event _event; @@ -204,59 +201,59 @@ class TeleDart extends Telegram { /// Short-cut for [onMessage] handling entityType `mention` (@username) Stream onMention([dynamic keyword]) => - onMessage(entityType: MessageEntity.MENTION, keyword: keyword); + onMessage(entityType: MessageEntity.typeMention, keyword: keyword); /// Short-cut for [onMessage] handling entityType `cashtag` Stream onCashtag([dynamic keyword]) => - onMessage(entityType: MessageEntity.CASHTAG, keyword: keyword); + onMessage(entityType: MessageEntity.typeCashtag, keyword: keyword); /// Short-cut for [onMessage] handling entityType `hashtag` Stream onHashtag([dynamic keyword]) => - onMessage(entityType: MessageEntity.HASHTAG, keyword: keyword); + onMessage(entityType: MessageEntity.typeHashtag, keyword: keyword); /// Short-cut for [onMessage] handling entityType `bot_command` Stream onCommand([dynamic keyword]) => - onMessage(entityType: MessageEntity.BOT_COMMAND, keyword: keyword); + onMessage(entityType: MessageEntity.typeBotCommand, keyword: keyword); /// Short-cut for [onMessage] handling entityType `url` Stream onUrl([dynamic keyword]) => - onMessage(entityType: MessageEntity.URL, keyword: keyword); + onMessage(entityType: MessageEntity.typeUrl, keyword: keyword); /// Short-cut for [onMessage] handling entityType `email` Stream onEmail([dynamic keyword]) => - onMessage(entityType: MessageEntity.EMAIL, keyword: keyword); + onMessage(entityType: MessageEntity.typeEmail, keyword: keyword); /// Short-cut for [onMessage] handling entityType `phone_number` Stream onPhoneNumber([dynamic keyword]) => - onMessage(entityType: MessageEntity.PHONE_NUMBER, keyword: keyword); + onMessage(entityType: MessageEntity.typePhoneNmber, keyword: keyword); /// Short-cut for [onMessage] handling entityType `bold` Stream onBold([dynamic keyword]) => - onMessage(entityType: MessageEntity.BOLD, keyword: keyword); + onMessage(entityType: MessageEntity.typeBold, keyword: keyword); /// Short-cut for [onMessage] handling entityType `italic` Stream onItalic([dynamic keyword]) => - onMessage(entityType: MessageEntity.ITALIC, keyword: keyword); + onMessage(entityType: MessageEntity.typeItalic, keyword: keyword); /// Short-cut for [onMessage] handling entityType `spoiler` Stream onSpoiler([dynamic keyword]) => - onMessage(entityType: MessageEntity.SPOILER, keyword: keyword); + onMessage(entityType: MessageEntity.typeSpolier, keyword: keyword); /// Short-cut for [onMessage] handling entityType `code` Stream onCode([dynamic keyword]) => - onMessage(entityType: MessageEntity.CODE, keyword: keyword); + onMessage(entityType: MessageEntity.typeCode, keyword: keyword); /// Short-cut for [onMessage] handling entityType `pre` Stream onPre([dynamic keyword]) => - onMessage(entityType: MessageEntity.PRE, keyword: keyword); + onMessage(entityType: MessageEntity.typePre, keyword: keyword); /// Short-cut for [onMessage] handling entityType `text_link` Stream onTextLink([dynamic keyword]) => - onMessage(entityType: MessageEntity.TEXT_LINK, keyword: keyword); + onMessage(entityType: MessageEntity.typeTextLink, keyword: keyword); /// Short-cut for [onMessage] handling entityType `text_mention` Stream onTextMention([dynamic keyword]) => - onMessage(entityType: MessageEntity.TEXT_MENTION, keyword: keyword); + onMessage(entityType: MessageEntity.typeTextMention, keyword: keyword); } class TeleDartException implements Exception { diff --git a/lib/src/telegram/model.dart b/lib/src/telegram/model.dart index 6857a5e3..babbd014 100644 --- a/lib/src/telegram/model.dart +++ b/lib/src/telegram/model.dart @@ -16,133 +16,164 @@ * along with this program. If not, see . */ +import 'package:http/http.dart'; import 'package:json_annotation/json_annotation.dart'; import '../util/time_helper.dart'; +import 'dart:io' as io; part 'model.g.dart'; -part 'models/update.dart'; -part 'models/webhook_info.dart'; -part 'models/user.dart'; -part 'models/chat.dart'; -part 'models/message.dart'; -part 'models/message_id.dart'; -part 'models/message_entity.dart'; -part 'models/photo_size.dart'; -part 'models/audio.dart'; -part 'models/document.dart'; -part 'models/video.dart'; part 'models/animation.dart'; -part 'models/voice.dart'; -part 'models/video_note.dart'; -part 'models/contact.dart'; -part 'models/login_url.dart'; -part 'models/location.dart'; -part 'models/venue.dart'; -part 'models/poll_option.dart'; -part 'models/poll_answer.dart'; -part 'models/poll.dart'; -part 'models/dice.dart'; -part 'models/proximity_alert_triggered.dart'; -part 'models/message_auto_delete_timer_changed.dart'; -part 'models/voice_chat_scheduled.dart'; -part 'models/voice_chat_started.dart'; -part 'models/voice_chat_ended.dart'; -part 'models/voice_chat_participants_invited.dart'; -part 'models/user_profile_photos.dart'; -part 'models/file.dart'; -part 'models/reply_markup.dart'; -part 'models/reply_keyboard_markup.dart'; -part 'models/keyboard_button.dart'; -part 'models/keyboard_button_poll_type.dart'; -part 'models/reply_keyboard_remove.dart'; -part 'models/inline_keyboard_markup.dart'; -part 'models/inline_keyboard_button.dart'; +part 'models/audio.dart'; +part 'models/bot_command_scope_all_chats_administrators.dart'; +part 'models/bot_command_scope_all_group_chats.dart'; +part 'models/bot_command_scope_all_private_chats.dart'; +part 'models/bot_command_scope_chat_administrators.dart'; +part 'models/bot_command_scope_chat_member.dart'; +part 'models/bot_command_scope_chat.dart'; +part 'models/bot_command_scope_default.dart'; +part 'models/bot_command_scope.dart'; +part 'models/bot_command.dart'; +part 'models/bot_description.dart'; +part 'models/bot_name.dart'; +part 'models/bot_short_description.dart'; +part 'models/callback_game.dart'; part 'models/callback_query.dart'; -part 'models/force_reply.dart'; -part 'models/chat_photo.dart'; +part 'models/chat_administrator_rights.dart'; part 'models/chat_invite_link.dart'; -part 'models/chat_member.dart'; -part 'models/chat_member_owner.dart'; +part 'models/chat_join_request.dart'; +part 'models/chat_location.dart'; part 'models/chat_member_administrator.dart'; +part 'models/chat_member_banned.dart'; +part 'models/chat_member_left.dart'; part 'models/chat_member_member.dart'; +part 'models/chat_member_owner.dart'; part 'models/chat_member_restricted.dart'; -part 'models/chat_member_left.dart'; -part 'models/chat_member_banned.dart'; part 'models/chat_member_updated.dart'; -part 'models/chat_join_request.dart'; +part 'models/chat_member.dart'; part 'models/chat_permissions.dart'; -part 'models/chat_location.dart'; -part 'models/bot_command.dart'; -part 'models/bot_command_scope.dart'; -part 'models/bot_command_scope_default.dart'; -part 'models/bot_command_scope_all_private_chats.dart'; -part 'models/bot_command_scope_all_group_chats.dart'; -part 'models/bot_command_scope_all_chats_administrators.dart'; -part 'models/bot_command_scope_chat.dart'; -part 'models/bot_command_scope_chat_administrators.dart'; -part 'models/bot_command_scope_chat_member.dart'; -part 'models/response_parameters.dart'; -part 'models/input_media.dart'; -part 'models/input_media_photo.dart'; -part 'models/input_media_video.dart'; -part 'models/input_media_animation.dart'; -part 'models/input_media_audio.dart'; -part 'models/input_media_document.dart'; -part 'models/sticker.dart'; -part 'models/sticker_set.dart'; -part 'models/mask_position.dart'; -part 'models/inline_query.dart'; -part 'models/inline_query_result.dart'; +part 'models/chat_photo.dart'; +part 'models/chat_shared.dart'; +part 'models/chat.dart'; +part 'models/chosen_inline_result.dart'; +part 'models/contact.dart'; +part 'models/dice.dart'; +part 'models/document.dart'; +part 'models/encrypted_credentials.dart'; +part 'models/encrypted_passport_element.dart'; +part 'models/file.dart'; +part 'models/force_reply.dart'; +part 'models/forum_topic_closed.dart'; +part 'models/forum_topic_created.dart'; +part 'models/forum_topic_edited.dart'; +part 'models/forum_topic_reopened.dart'; +part 'models/forum_topic.dart'; +part 'models/game_high_score.dart'; +part 'models/game.dart'; +part 'models/general_forum_topic_hidden.dart'; +part 'models/general_forum_topic_unhidden.dart'; +part 'models/inline_keyboard_button.dart'; +part 'models/inline_keyboard_markup.dart'; part 'models/inline_query_result_article.dart'; -part 'models/inline_query_result_photo.dart'; -part 'models/inline_query_result_gif.dart'; -part 'models/inline_query_result_mpeg4_gif.dart'; -part 'models/inline_query_result_video.dart'; part 'models/inline_query_result_audio.dart'; -part 'models/inline_query_result_voice.dart'; -part 'models/inline_query_result_document.dart'; -part 'models/inline_query_result_location.dart'; -part 'models/inline_query_result_venue.dart'; -part 'models/inline_query_result_contact.dart'; -part 'models/inline_query_result_game.dart'; -part 'models/inline_query_result_cached_photo.dart'; +part 'models/inline_query_result_cached_audio.dart'; +part 'models/inline_query_result_cached_document.dart'; part 'models/inline_query_result_cached_gif.dart'; part 'models/inline_query_result_cached_mpeg4_gif.dart'; +part 'models/inline_query_result_cached_photo.dart'; part 'models/inline_query_result_cached_sticker.dart'; -part 'models/inline_query_result_cached_document.dart'; part 'models/inline_query_result_cached_video.dart'; part 'models/inline_query_result_cached_voice.dart'; -part 'models/inline_query_result_cached_audio.dart'; +part 'models/inline_query_result_contact.dart'; +part 'models/inline_query_result_document.dart'; +part 'models/inline_query_result_game.dart'; +part 'models/inline_query_result_gif.dart'; +part 'models/inline_query_result_location.dart'; +part 'models/inline_query_result_mpeg4_gif.dart'; +part 'models/inline_query_result_photo.dart'; +part 'models/inline_query_result_venue.dart'; +part 'models/inline_query_result_video.dart'; +part 'models/inline_query_result_voice.dart'; +part 'models/inline_query_result.dart'; +part 'models/inline_query_results_button.dart'; +part 'models/inline_query.dart'; +part 'models/input_contact_message_content.dart'; +part 'models/input_invoice_message_content.dart'; +part 'models/input_location_message_content.dart'; +part 'models/input_media_animation.dart'; +part 'models/input_media_audio.dart'; +part 'models/input_media_document.dart'; +part 'models/input_media_photo.dart'; +part 'models/input_media_video.dart'; +part 'models/input_media_with_thumbnail.dart'; +part 'models/input_media.dart'; part 'models/input_message_content.dart'; +part 'models/input_sticker.dart'; part 'models/input_text_message_content.dart'; -part 'models/input_location_message_content.dart'; part 'models/input_venue_message_content.dart'; -part 'models/input_contact_message_content.dart'; -part 'models/input_invoice_message_content.dart'; -part 'models/chosen_inline_result.dart'; -part 'models/labeled_price.dart'; part 'models/invoice.dart'; -part 'models/shipping_address.dart'; +part 'models/keyboard_button_poll_type.dart'; +part 'models/keyboard_button_request_chat.dart'; +part 'models/keyboard_button_request_user.dart'; +part 'models/keyboard_button.dart'; +part 'models/labeled_price.dart'; +part 'models/location.dart'; +part 'models/login_url.dart'; +part 'models/mask_position.dart'; +part 'models/menu_button_commands.dart'; +part 'models/menu_button_default.dart'; +part 'models/menu_button_web_app.dart'; +part 'models/menu_button.dart'; +part 'models/message_auto_delete_timer_changed.dart'; +part 'models/message_entity.dart'; +part 'models/message_id.dart'; +part 'models/message.dart'; part 'models/order_info.dart'; -part 'models/shipping_option.dart'; -part 'models/successful_payment.dart'; -part 'models/shipping_query.dart'; -part 'models/pre_checkout_query.dart'; part 'models/passport_data.dart'; -part 'models/passport_file.dart'; -part 'models/encrypted_passport_element.dart'; -part 'models/encrypted_credentials.dart'; -part 'models/passport_element_error.dart'; part 'models/passport_element_error_data_field.dart'; +part 'models/passport_element_error_file.dart'; +part 'models/passport_element_error_files.dart'; part 'models/passport_element_error_front_side.dart'; part 'models/passport_element_error_reverse_side.dart'; part 'models/passport_element_error_selfie.dart'; -part 'models/passport_element_error_file.dart'; -part 'models/passport_element_error_files.dart'; part 'models/passport_element_error_translation_file.dart'; part 'models/passport_element_error_translation_files.dart'; part 'models/passport_element_error_unspecified.dart'; -part 'models/game.dart'; -part 'models/callback_game.dart'; -part 'models/game_high_score.dart'; +part 'models/passport_element_error.dart'; +part 'models/passport_file.dart'; +part 'models/photo_size.dart'; +part 'models/poll_answer.dart'; +part 'models/poll_option.dart'; +part 'models/poll.dart'; +part 'models/pre_checkout_query.dart'; +part 'models/proximity_alert_triggered.dart'; +part 'models/reply_keyboard_markup.dart'; +part 'models/reply_keyboard_remove.dart'; +part 'models/reply_markup.dart'; +part 'models/response_parameters.dart'; +part 'models/response.dart'; +part 'models/sent_web_app_message.dart'; +part 'models/shipping_address.dart'; +part 'models/shipping_option.dart'; +part 'models/shipping_query.dart'; +part 'models/sticker_set.dart'; +part 'models/sticker.dart'; +part 'models/story.dart'; +part 'models/successful_payment.dart'; +part 'models/switch_inline_query_chosen_chat.dart'; +part 'models/update.dart'; +part 'models/user_profile_photos.dart'; +part 'models/user_shared.dart'; +part 'models/user.dart'; +part 'models/venue.dart'; +part 'models/video_note.dart'; +part 'models/video.dart'; +part 'models/voice_chat_ended.dart'; +part 'models/voice_chat_participants_invited.dart'; +part 'models/voice_chat_scheduled.dart'; +part 'models/voice_chat_started.dart'; +part 'models/voice.dart'; +part 'models/web_app_data.dart'; +part 'models/web_app_info.dart'; +part 'models/webhook_info.dart'; +part 'models/write_access_allowed.dart'; diff --git a/lib/src/telegram/model.g.dart b/lib/src/telegram/model.g.dart index f9a842b8..28bd4574 100644 --- a/lib/src/telegram/model.g.dart +++ b/lib/src/telegram/model.g.dart @@ -6,63 +6,27 @@ part of 'model.dart'; // JsonSerializableGenerator // ************************************************************************** -Update _$UpdateFromJson(Map json) => Update( - update_id: json['update_id'] as int, - message: json['message'] == null - ? null - : Message.fromJson(json['message'] as Map), - edited_message: json['edited_message'] == null - ? null - : Message.fromJson(json['edited_message'] as Map), - channel_post: json['channel_post'] == null - ? null - : Message.fromJson(json['channel_post'] as Map), - edited_channel_post: json['edited_channel_post'] == null - ? null - : Message.fromJson( - json['edited_channel_post'] as Map), - inline_query: json['inline_query'] == null - ? null - : InlineQuery.fromJson(json['inline_query'] as Map), - chosen_inline_result: json['chosen_inline_result'] == null - ? null - : ChosenInlineResult.fromJson( - json['chosen_inline_result'] as Map), - callback_query: json['callback_query'] == null - ? null - : CallbackQuery.fromJson( - json['callback_query'] as Map), - shipping_query: json['shipping_query'] == null - ? null - : ShippingQuery.fromJson( - json['shipping_query'] as Map), - pre_checkout_query: json['pre_checkout_query'] == null - ? null - : PreCheckoutQuery.fromJson( - json['pre_checkout_query'] as Map), - poll: json['poll'] == null - ? null - : Poll.fromJson(json['poll'] as Map), - poll_answer: json['poll_answer'] == null - ? null - : PollAnswer.fromJson(json['poll_answer'] as Map), - my_chat_member: json['my_chat_member'] == null - ? null - : ChatMemberUpdated.fromJson( - json['my_chat_member'] as Map), - chat_member: json['chat_member'] == null - ? null - : ChatMemberUpdated.fromJson( - json['chat_member'] as Map), - chat_join_request: json['chat_join_request'] == null +Animation _$AnimationFromJson(Map json) => Animation( + fileId: json['file_id'] as String, + fileUniqueId: json['file_unique_id'] as String, + width: json['width'] as int, + height: json['height'] as int, + duration: json['duration'] as int, + thumbnail: json['thumbnail'] == null ? null - : ChatJoinRequest.fromJson( - json['chat_join_request'] as Map), + : PhotoSize.fromJson(json['thumbnail'] as Map), + fileName: json['file_name'] as String?, + mimeType: json['mime_type'] as String?, + fileSize: json['file_size'] as int?, ); -Map _$UpdateToJson(Update instance) { +Map _$AnimationToJson(Animation instance) { final val = { - 'update_id': instance.update_id, + 'file_id': instance.fileId, + 'file_unique_id': instance.fileUniqueId, + 'width': instance.width, + 'height': instance.height, + 'duration': instance.duration, }; void writeNotNull(String key, dynamic value) { @@ -71,41 +35,32 @@ Map _$UpdateToJson(Update instance) { } } - writeNotNull('message', instance.message?.toJson()); - writeNotNull('edited_message', instance.edited_message?.toJson()); - writeNotNull('channel_post', instance.channel_post?.toJson()); - writeNotNull('edited_channel_post', instance.edited_channel_post?.toJson()); - writeNotNull('inline_query', instance.inline_query?.toJson()); - writeNotNull('chosen_inline_result', instance.chosen_inline_result?.toJson()); - writeNotNull('callback_query', instance.callback_query?.toJson()); - writeNotNull('shipping_query', instance.shipping_query?.toJson()); - writeNotNull('pre_checkout_query', instance.pre_checkout_query?.toJson()); - writeNotNull('poll', instance.poll?.toJson()); - writeNotNull('poll_answer', instance.poll_answer?.toJson()); - writeNotNull('my_chat_member', instance.my_chat_member?.toJson()); - writeNotNull('chat_member', instance.chat_member?.toJson()); - writeNotNull('chat_join_request', instance.chat_join_request?.toJson()); + writeNotNull('thumbnail', instance.thumbnail?.toJson()); + writeNotNull('file_name', instance.fileName); + writeNotNull('mime_type', instance.mimeType); + writeNotNull('file_size', instance.fileSize); return val; } -WebhookInfo _$WebhookInfoFromJson(Map json) => WebhookInfo( - url: json['url'] as String, - has_custom_certificate: json['has_custom_certificate'] as bool, - pending_update_count: json['pending_update_count'] as int, - ip_address: json['ip_address'] as String?, - last_error_date: json['last_error_date'] as int?, - last_error_message: json['last_error_message'] as String?, - max_connections: json['max_connections'] as int?, - allowed_updates: (json['allowed_updates'] as List?) - ?.map((e) => e as String) - .toList(), +Audio _$AudioFromJson(Map json) => Audio( + fileId: json['file_id'] as String, + fileUniqueId: json['file_unique_id'] as String, + duration: json['duration'] as int, + performer: json['performer'] as String?, + title: json['title'] as String?, + fileName: json['file_name'] as String?, + mimeType: json['mime_type'] as String?, + fileSize: json['file_size'] as int?, + thumbnail: json['thumbnail'] == null + ? null + : PhotoSize.fromJson(json['thumbnail'] as Map), ); -Map _$WebhookInfoToJson(WebhookInfo instance) { +Map _$AudioToJson(Audio instance) { final val = { - 'url': instance.url, - 'has_custom_certificate': instance.has_custom_certificate, - 'pending_update_count': instance.pending_update_count, + 'file_id': instance.fileId, + 'file_unique_id': instance.fileUniqueId, + 'duration': instance.duration, }; void writeNotNull(String key, dynamic value) { @@ -114,31 +69,64 @@ Map _$WebhookInfoToJson(WebhookInfo instance) { } } - writeNotNull('ip_address', instance.ip_address); - writeNotNull('last_error_date', instance.last_error_date); - writeNotNull('last_error_message', instance.last_error_message); - writeNotNull('max_connections', instance.max_connections); - writeNotNull('allowed_updates', instance.allowed_updates); + writeNotNull('performer', instance.performer); + writeNotNull('title', instance.title); + writeNotNull('file_name', instance.fileName); + writeNotNull('mime_type', instance.mimeType); + writeNotNull('file_size', instance.fileSize); + writeNotNull('thumbnail', instance.thumbnail?.toJson()); return val; } -User _$UserFromJson(Map json) => User( - id: json['id'] as int, - is_bot: json['is_bot'] as bool, - first_name: json['first_name'] as String, - last_name: json['last_name'] as String?, - username: json['username'] as String?, - language_code: json['language_code'] as String?, - can_join_groups: json['can_join_groups'] as bool?, - can_read_all_group_messages: json['can_read_all_group_messages'] as bool?, - supports_inline_queries: json['supports_inline_queries'] as bool?, +BotCommandScopeAllChatAdministrators + _$BotCommandScopeAllChatAdministratorsFromJson(Map json) => + BotCommandScopeAllChatAdministrators( + type: json['type'] as String? ?? + BotCommandScope.typeAllChatAdministrators, + ); + +Map _$BotCommandScopeAllChatAdministratorsToJson( + BotCommandScopeAllChatAdministrators instance) => + { + 'type': instance.type, + }; + +BotCommandScopeAllGroupChats _$BotCommandScopeAllGroupChatsFromJson( + Map json) => + BotCommandScopeAllGroupChats( + type: json['type'] as String? ?? BotCommandScope.typeAllGroupChats, ); -Map _$UserToJson(User instance) { +Map _$BotCommandScopeAllGroupChatsToJson( + BotCommandScopeAllGroupChats instance) => + { + 'type': instance.type, + }; + +BotCommandScopeAllPrivateChats _$BotCommandScopeAllPrivateChatsFromJson( + Map json) => + BotCommandScopeAllPrivateChats( + type: json['type'] as String? ?? BotCommandScope.typeAllPrivateChats, + ); + +Map _$BotCommandScopeAllPrivateChatsToJson( + BotCommandScopeAllPrivateChats instance) => + { + 'type': instance.type, + }; + +BotCommandScopeChatAdministrators _$BotCommandScopeChatAdministratorsFromJson( + Map json) => + BotCommandScopeChatAdministrators( + type: + json['type'] as String? ?? BotCommandScope.typeAllChatAdministrators, + chatId: json['chat_id'], + ); + +Map _$BotCommandScopeChatAdministratorsToJson( + BotCommandScopeChatAdministrators instance) { final val = { - 'id': instance.id, - 'is_bot': instance.is_bot, - 'first_name': instance.first_name, + 'type': instance.type, }; void writeNotNull(String key, dynamic value) { @@ -147,50 +135,20 @@ Map _$UserToJson(User instance) { } } - writeNotNull('last_name', instance.last_name); - writeNotNull('username', instance.username); - writeNotNull('language_code', instance.language_code); - writeNotNull('can_join_groups', instance.can_join_groups); - writeNotNull( - 'can_read_all_group_messages', instance.can_read_all_group_messages); - writeNotNull('supports_inline_queries', instance.supports_inline_queries); + writeNotNull('chat_id', instance.chatId); return val; } -Chat _$ChatFromJson(Map json) => Chat( - id: json['id'] as int, - type: json['type'] as String, - title: json['title'] as String?, - username: json['username'] as String?, - first_name: json['first_name'] as String?, - last_name: json['last_name'] as String?, - photo: json['photo'] == null - ? null - : ChatPhoto.fromJson(json['photo'] as Map), - bio: json['bio'] as String?, - has_private_forwards: json['has_private_forwards'] as bool?, - description: json['description'] as String?, - invite_link: json['invite_link'] as String?, - pinned_message: json['pinned_message'] == null - ? null - : Message.fromJson(json['pinned_message'] as Map), - permissions: json['permissions'] == null - ? null - : ChatPermissions.fromJson( - json['permissions'] as Map), - slow_mode_delay: json['slow_mode_delay'] as int?, - has_protected_content: json['has_protected_content'] as bool?, - sticker_set_name: json['sticker_set_name'] as String?, - can_set_sticker_set: json['can_set_sticker_set'] as bool?, - linked_chat_id: json['linked_chat_id'] as int?, - location: json['location'] == null - ? null - : ChatLocation.fromJson(json['location'] as Map), +BotCommandScopeChatMember _$BotCommandScopeChatMemberFromJson( + Map json) => + BotCommandScopeChatMember( + type: json['type'] as String? ?? BotCommandScope.typeChatMember, + chatId: json['chat_id'], ); -Map _$ChatToJson(Chat instance) { +Map _$BotCommandScopeChatMemberToJson( + BotCommandScopeChatMember instance) { final val = { - 'id': instance.id, 'type': instance.type, }; @@ -200,175 +158,19 @@ Map _$ChatToJson(Chat instance) { } } - writeNotNull('title', instance.title); - writeNotNull('username', instance.username); - writeNotNull('first_name', instance.first_name); - writeNotNull('last_name', instance.last_name); - writeNotNull('photo', instance.photo?.toJson()); - writeNotNull('bio', instance.bio); - writeNotNull('has_private_forwards', instance.has_private_forwards); - writeNotNull('description', instance.description); - writeNotNull('invite_link', instance.invite_link); - writeNotNull('pinned_message', instance.pinned_message?.toJson()); - writeNotNull('permissions', instance.permissions?.toJson()); - writeNotNull('slow_mode_delay', instance.slow_mode_delay); - writeNotNull('has_protected_content', instance.has_protected_content); - writeNotNull('sticker_set_name', instance.sticker_set_name); - writeNotNull('can_set_sticker_set', instance.can_set_sticker_set); - writeNotNull('linked_chat_id', instance.linked_chat_id); - writeNotNull('location', instance.location?.toJson()); + writeNotNull('chat_id', instance.chatId); return val; } -Message _$MessageFromJson(Map json) => Message( - message_id: json['message_id'] as int, - from: json['from'] == null - ? null - : User.fromJson(json['from'] as Map), - sender_chat: json['sender_chat'] == null - ? null - : Chat.fromJson(json['sender_chat'] as Map), - date: json['date'] as int, - chat: Chat.fromJson(json['chat'] as Map), - forward_from: json['forward_from'] == null - ? null - : User.fromJson(json['forward_from'] as Map), - forward_from_chat: json['forward_from_chat'] == null - ? null - : Chat.fromJson(json['forward_from_chat'] as Map), - forward_from_message_id: json['forward_from_message_id'] as int?, - forward_signature: json['forward_signature'] as String?, - forward_sender_name: json['forward_sender_name'] as String?, - forward_date: json['forward_date'] as int?, - is_automatic_forward: json['is_automatic_forward'] as bool?, - reply_to_message: json['reply_to_message'] == null - ? null - : Message.fromJson(json['reply_to_message'] as Map), - via_bot: json['via_bot'] == null - ? null - : User.fromJson(json['via_bot'] as Map), - edit_date: json['edit_date'] as int?, - has_protected_content: json['has_protected_content'] as bool?, - media_group_id: json['media_group_id'] as String?, - author_signature: json['author_signature'] as String?, - text: json['text'] as String?, - entities: (json['entities'] as List?) - ?.map((e) => MessageEntity.fromJson(e as Map)) - .toList(), - animation: json['animation'] == null - ? null - : Animation.fromJson(json['animation'] as Map), - audio: json['audio'] == null - ? null - : Audio.fromJson(json['audio'] as Map), - document: json['document'] == null - ? null - : Document.fromJson(json['document'] as Map), - photo: (json['photo'] as List?) - ?.map((e) => PhotoSize.fromJson(e as Map)) - .toList(), - sticker: json['sticker'] == null - ? null - : Sticker.fromJson(json['sticker'] as Map), - video: json['video'] == null - ? null - : Video.fromJson(json['video'] as Map), - video_note: json['video_note'] == null - ? null - : VideoNote.fromJson(json['video_note'] as Map), - voice: json['voice'] == null - ? null - : Voice.fromJson(json['voice'] as Map), - caption: json['caption'] as String?, - caption_entities: (json['caption_entities'] as List?) - ?.map((e) => MessageEntity.fromJson(e as Map)) - .toList(), - contact: json['contact'] == null - ? null - : Contact.fromJson(json['contact'] as Map), - dice: json['dice'] == null - ? null - : Dice.fromJson(json['dice'] as Map), - game: json['game'] == null - ? null - : Game.fromJson(json['game'] as Map), - poll: json['poll'] == null - ? null - : Poll.fromJson(json['poll'] as Map), - venue: json['venue'] == null - ? null - : Venue.fromJson(json['venue'] as Map), - location: json['location'] == null - ? null - : Location.fromJson(json['location'] as Map), - new_chat_members: (json['new_chat_members'] as List?) - ?.map((e) => User.fromJson(e as Map)) - .toList(), - left_chat_member: json['left_chat_member'] == null - ? null - : User.fromJson(json['left_chat_member'] as Map), - new_chat_title: json['new_chat_title'] as String?, - new_chat_photo: (json['new_chat_photo'] as List?) - ?.map((e) => PhotoSize.fromJson(e as Map)) - .toList(), - delete_chat_photo: json['delete_chat_photo'] as bool?, - group_chat_created: json['group_chat_created'] as bool?, - supergroup_chat_created: json['supergroup_chat_created'] as bool?, - channel_chat_created: json['channel_chat_created'] as bool?, - message_auto_delete_timer_changed: - json['message_auto_delete_timer_changed'] == null - ? null - : MessageAutoDeleteTimerChanged.fromJson( - json['message_auto_delete_timer_changed'] - as Map), - migrate_to_chat_id: json['migrate_to_chat_id'] as int?, - migrate_from_chat_id: json['migrate_from_chat_id'] as int?, - pinned_message: json['pinned_message'] == null - ? null - : Message.fromJson(json['pinned_message'] as Map), - invoice: json['invoice'] == null - ? null - : Invoice.fromJson(json['invoice'] as Map), - successful_payment: json['successful_payment'] == null - ? null - : SuccessfulPayment.fromJson( - json['successful_payment'] as Map), - connected_website: json['connected_website'] as String?, - passport_data: json['passport_data'] == null - ? null - : PassportData.fromJson( - json['passport_data'] as Map), - proximity_alert_triggered: json['proximity_alert_triggered'] == null - ? null - : ProximityAlertTriggered.fromJson( - json['proximity_alert_triggered'] as Map), - voice_chat_scheduled: json['voice_chat_scheduled'] == null - ? null - : VoiceChatScheduled.fromJson( - json['voice_chat_scheduled'] as Map), - voice_chat_started: json['voice_chat_started'] == null - ? null - : VoiceChatStarted.fromJson( - json['voice_chat_started'] as Map), - voice_chat_ended: json['voice_chat_ended'] == null - ? null - : VoiceChatEnded.fromJson( - json['voice_chat_ended'] as Map), - voice_chat_participants_invited: - json['voice_chat_participants_invited'] == null - ? null - : VoiceChatParticipantsInvited.fromJson( - json['voice_chat_participants_invited'] - as Map), - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), +BotCommandScopeChat _$BotCommandScopeChatFromJson(Map json) => + BotCommandScopeChat( + type: json['type'] as String? ?? BotCommandScope.typeChat, + chatId: json['chat_id'], ); -Map _$MessageToJson(Message instance) { +Map _$BotCommandScopeChatToJson(BotCommandScopeChat instance) { final val = { - 'message_id': instance.message_id, + 'type': instance.type, }; void writeNotNull(String key, dynamic value) { @@ -377,156 +179,95 @@ Map _$MessageToJson(Message instance) { } } - writeNotNull('from', instance.from?.toJson()); - writeNotNull('sender_chat', instance.sender_chat?.toJson()); - val['date'] = instance.date; - val['chat'] = instance.chat.toJson(); - writeNotNull('forward_from', instance.forward_from?.toJson()); - writeNotNull('forward_from_chat', instance.forward_from_chat?.toJson()); - writeNotNull('forward_from_message_id', instance.forward_from_message_id); - writeNotNull('forward_signature', instance.forward_signature); - writeNotNull('forward_sender_name', instance.forward_sender_name); - writeNotNull('forward_date', instance.forward_date); - writeNotNull('is_automatic_forward', instance.is_automatic_forward); - writeNotNull('reply_to_message', instance.reply_to_message?.toJson()); - writeNotNull('via_bot', instance.via_bot?.toJson()); - writeNotNull('edit_date', instance.edit_date); - writeNotNull('has_protected_content', instance.has_protected_content); - writeNotNull('media_group_id', instance.media_group_id); - writeNotNull('author_signature', instance.author_signature); - writeNotNull('text', instance.text); - writeNotNull('entities', instance.entities?.map((e) => e.toJson()).toList()); - writeNotNull('animation', instance.animation?.toJson()); - writeNotNull('audio', instance.audio?.toJson()); - writeNotNull('document', instance.document?.toJson()); - writeNotNull('photo', instance.photo?.map((e) => e.toJson()).toList()); - writeNotNull('sticker', instance.sticker?.toJson()); - writeNotNull('video', instance.video?.toJson()); - writeNotNull('video_note', instance.video_note?.toJson()); - writeNotNull('voice', instance.voice?.toJson()); - writeNotNull('caption', instance.caption); - writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('contact', instance.contact?.toJson()); - writeNotNull('dice', instance.dice?.toJson()); - writeNotNull('game', instance.game?.toJson()); - writeNotNull('poll', instance.poll?.toJson()); - writeNotNull('venue', instance.venue?.toJson()); - writeNotNull('location', instance.location?.toJson()); - writeNotNull('new_chat_members', - instance.new_chat_members?.map((e) => e.toJson()).toList()); - writeNotNull('left_chat_member', instance.left_chat_member?.toJson()); - writeNotNull('new_chat_title', instance.new_chat_title); - writeNotNull('new_chat_photo', - instance.new_chat_photo?.map((e) => e.toJson()).toList()); - writeNotNull('delete_chat_photo', instance.delete_chat_photo); - writeNotNull('group_chat_created', instance.group_chat_created); - writeNotNull('supergroup_chat_created', instance.supergroup_chat_created); - writeNotNull('channel_chat_created', instance.channel_chat_created); - writeNotNull('message_auto_delete_timer_changed', - instance.message_auto_delete_timer_changed?.toJson()); - writeNotNull('migrate_to_chat_id', instance.migrate_to_chat_id); - writeNotNull('migrate_from_chat_id', instance.migrate_from_chat_id); - writeNotNull('pinned_message', instance.pinned_message?.toJson()); - writeNotNull('invoice', instance.invoice?.toJson()); - writeNotNull('successful_payment', instance.successful_payment?.toJson()); - writeNotNull('connected_website', instance.connected_website); - writeNotNull('passport_data', instance.passport_data?.toJson()); - writeNotNull('proximity_alert_triggered', - instance.proximity_alert_triggered?.toJson()); - writeNotNull('voice_chat_scheduled', instance.voice_chat_scheduled?.toJson()); - writeNotNull('voice_chat_started', instance.voice_chat_started?.toJson()); - writeNotNull('voice_chat_ended', instance.voice_chat_ended?.toJson()); - writeNotNull('voice_chat_participants_invited', - instance.voice_chat_participants_invited?.toJson()); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); + writeNotNull('chat_id', instance.chatId); return val; } -MessageId _$MessageIdFromJson(Map json) => MessageId( - message_id: json['message_id'] as int, +BotCommandScopeDefault _$BotCommandScopeDefaultFromJson( + Map json) => + BotCommandScopeDefault( + type: json['type'] as String? ?? BotCommandScope.typeDefault, ); -Map _$MessageIdToJson(MessageId instance) => { - 'message_id': instance.message_id, +Map _$BotCommandScopeDefaultToJson( + BotCommandScopeDefault instance) => + { + 'type': instance.type, }; -MessageEntity _$MessageEntityFromJson(Map json) => - MessageEntity( +BotCommandScope _$BotCommandScopeFromJson(Map json) => + BotCommandScope( type: json['type'] as String, - offset: json['offset'] as int, - length: json['length'] as int, - url: json['url'] as String?, - user: json['user'] == null - ? null - : User.fromJson(json['user'] as Map), - language: json['language'] as String?, ); -Map _$MessageEntityToJson(MessageEntity instance) { - final val = { - 'type': instance.type, - 'offset': instance.offset, - 'length': instance.length, - }; +Map _$BotCommandScopeToJson(BotCommandScope instance) => + { + 'type': instance.type, + }; - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } +BotCommand _$BotCommandFromJson(Map json) => BotCommand( + command: json['command'] as String, + description: json['description'] as String, + ); - writeNotNull('url', instance.url); - writeNotNull('user', instance.user?.toJson()); - writeNotNull('language', instance.language); - return val; -} +Map _$BotCommandToJson(BotCommand instance) => + { + 'command': instance.command, + 'description': instance.description, + }; -PhotoSize _$PhotoSizeFromJson(Map json) => PhotoSize( - file_id: json['file_id'] as String, - file_unique_id: json['file_unique_id'] as String, - width: json['width'] as int, - height: json['height'] as int, - file_size: json['file_size'] as int?, +BotDescription _$BotDescriptionFromJson(Map json) => + BotDescription( + description: json['description'] as String, ); -Map _$PhotoSizeToJson(PhotoSize instance) { - final val = { - 'file_id': instance.file_id, - 'file_unique_id': instance.file_unique_id, - 'width': instance.width, - 'height': instance.height, - }; +Map _$BotDescriptionToJson(BotDescription instance) => + { + 'description': instance.description, + }; - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } +BotName _$BotNameFromJson(Map json) => BotName( + name: json['name'] as String, + ); - writeNotNull('file_size', instance.file_size); - return val; -} +Map _$BotNameToJson(BotName instance) => { + 'name': instance.name, + }; -Audio _$AudioFromJson(Map json) => Audio( - file_id: json['file_id'] as String, - file_unique_id: json['file_unique_id'] as String, - duration: json['duration'] as int, - performer: json['performer'] as String?, - title: json['title'] as String?, - file_name: json['file_name'] as String?, - mime_type: json['mime_type'] as String?, - file_size: json['file_size'] as int?, - thumb: json['thumb'] == null +BotShortDescription _$BotShortDescriptionFromJson(Map json) => + BotShortDescription( + shortDescription: json['short_description'] as String, + ); + +Map _$BotShortDescriptionToJson( + BotShortDescription instance) => + { + 'short_description': instance.shortDescription, + }; + +CallbackGame _$CallbackGameFromJson(Map json) => + CallbackGame(); + +Map _$CallbackGameToJson(CallbackGame instance) => + {}; + +CallbackQuery _$CallbackQueryFromJson(Map json) => + CallbackQuery( + id: json['id'] as String, + from: User.fromJson(json['from'] as Map), + message: json['message'] == null ? null - : PhotoSize.fromJson(json['thumb'] as Map), + : Message.fromJson(json['message'] as Map), + inlineMessageId: json['inline_message_id'] as String?, + chatInstance: json['chat_instance'] as String?, + data: json['data'] as String?, + gameShortName: json['game_short_name'] as String?, ); -Map _$AudioToJson(Audio instance) { +Map _$CallbackQueryToJson(CallbackQuery instance) { final val = { - 'file_id': instance.file_id, - 'file_unique_id': instance.file_unique_id, - 'duration': instance.duration, + 'id': instance.id, + 'from': instance.from.toJson(), }; void writeNotNull(String key, dynamic value) { @@ -535,30 +276,42 @@ Map _$AudioToJson(Audio instance) { } } - writeNotNull('performer', instance.performer); - writeNotNull('title', instance.title); - writeNotNull('file_name', instance.file_name); - writeNotNull('mime_type', instance.mime_type); - writeNotNull('file_size', instance.file_size); - writeNotNull('thumb', instance.thumb?.toJson()); + writeNotNull('message', instance.message?.toJson()); + writeNotNull('inline_message_id', instance.inlineMessageId); + writeNotNull('chat_instance', instance.chatInstance); + writeNotNull('data', instance.data); + writeNotNull('game_short_name', instance.gameShortName); return val; } -Document _$DocumentFromJson(Map json) => Document( - file_id: json['file_id'] as String, - file_unique_id: json['file_unique_id'] as String, - thumb: json['thumb'] == null - ? null - : PhotoSize.fromJson(json['thumb'] as Map), - file_name: json['file_name'] as String?, - mime_type: json['mime_type'] as String?, - file_size: json['file_size'] as int?, +ChatAdministratorRights _$ChatAdministratorRightsFromJson( + Map json) => + ChatAdministratorRights( + isAnonymous: json['is_anonymous'] as bool? ?? false, + canManageChat: json['can_manage_chat'] as bool? ?? false, + canDeleteMessages: json['can_delete_messages'] as bool? ?? false, + canManageVideoChats: json['can_manage_video_chats'] as bool? ?? false, + canRestrictMembers: json['can_restrict_members'] as bool? ?? false, + canPromoteMembers: json['can_promote_members'] as bool? ?? false, + canChangeInfo: json['can_change_info'] as bool? ?? false, + canInviteUsers: json['can_invite_users'] as bool? ?? false, + canPostMessages: json['can_post_messages'] as bool?, + canEditMessages: json['can_edit_messages'] as bool?, + canPinMessages: json['can_pin_messages'] as bool?, + canManageTopics: json['can_manage_topics'] as bool?, ); -Map _$DocumentToJson(Document instance) { +Map _$ChatAdministratorRightsToJson( + ChatAdministratorRights instance) { final val = { - 'file_id': instance.file_id, - 'file_unique_id': instance.file_unique_id, + 'is_anonymous': instance.isAnonymous, + 'can_manage_chat': instance.canManageChat, + 'can_delete_messages': instance.canDeleteMessages, + 'can_manage_video_chats': instance.canManageVideoChats, + 'can_restrict_members': instance.canRestrictMembers, + 'can_promote_members': instance.canPromoteMembers, + 'can_change_info': instance.canChangeInfo, + 'can_invite_users': instance.canInviteUsers, }; void writeNotNull(String key, dynamic value) { @@ -567,34 +320,33 @@ Map _$DocumentToJson(Document instance) { } } - writeNotNull('thumb', instance.thumb?.toJson()); - writeNotNull('file_name', instance.file_name); - writeNotNull('mime_type', instance.mime_type); - writeNotNull('file_size', instance.file_size); + writeNotNull('can_post_messages', instance.canPostMessages); + writeNotNull('can_edit_messages', instance.canEditMessages); + writeNotNull('can_pin_messages', instance.canPinMessages); + writeNotNull('can_manage_topics', instance.canManageTopics); return val; } -Video _$VideoFromJson(Map json) => Video( - file_id: json['file_id'] as String, - file_unique_id: json['file_unique_id'] as String, - width: json['width'] as int, - height: json['height'] as int, - duration: json['duration'] as int, - thumb: json['thumb'] == null - ? null - : PhotoSize.fromJson(json['thumb'] as Map), - file_name: json['file_name'] as String?, - mime_type: json['mime_type'] as String?, - file_size: json['file_size'] as int?, +ChatInviteLink _$ChatInviteLinkFromJson(Map json) => + ChatInviteLink( + inviteLink: json['invite_link'] as String, + creator: User.fromJson(json['creator'] as Map), + createsJoinRequest: json['creates_join_request'] as bool, + isPrimary: json['is_primary'] as bool, + isRevoked: json['is_revoked'] as bool, + name: json['name'] as String?, + expireDate: json['expire_date'] as int?, + memberLimit: json['member_limit'] as int?, + pendingJoinRequestCount: json['pending_join_request_count'] as int?, ); -Map _$VideoToJson(Video instance) { +Map _$ChatInviteLinkToJson(ChatInviteLink instance) { final val = { - 'file_id': instance.file_id, - 'file_unique_id': instance.file_unique_id, - 'width': instance.width, - 'height': instance.height, - 'duration': instance.duration, + 'invite_link': instance.inviteLink, + 'creator': instance.creator.toJson(), + 'creates_join_request': instance.createsJoinRequest, + 'is_primary': instance.isPrimary, + 'is_revoked': instance.isRevoked, }; void writeNotNull(String key, dynamic value) { @@ -603,34 +355,32 @@ Map _$VideoToJson(Video instance) { } } - writeNotNull('thumb', instance.thumb?.toJson()); - writeNotNull('file_name', instance.file_name); - writeNotNull('mime_type', instance.mime_type); - writeNotNull('file_size', instance.file_size); + writeNotNull('name', instance.name); + writeNotNull('expire_date', instance.expireDate); + writeNotNull('member_limit', instance.memberLimit); + writeNotNull('pending_join_request_count', instance.pendingJoinRequestCount); return val; } -Animation _$AnimationFromJson(Map json) => Animation( - file_id: json['file_id'] as String, - file_unique_id: json['file_unique_id'] as String, - width: json['width'] as int, - height: json['height'] as int, - duration: json['duration'] as int, - thumb: json['thumb'] == null +ChatJoinRequest _$ChatJoinRequestFromJson(Map json) => + ChatJoinRequest( + chat: Chat.fromJson(json['chat'] as Map), + from: User.fromJson(json['from'] as Map), + userChatId: json['user_chat_id'] as int, + date: json['date'] as int, + bio: json['bio'] as String?, + inviteLink: json['invite_link'] == null ? null - : PhotoSize.fromJson(json['thumb'] as Map), - file_name: json['file_name'] as String?, - mime_type: json['mime_type'] as String?, - file_size: json['file_size'] as int?, + : ChatInviteLink.fromJson( + json['invite_link'] as Map), ); -Map _$AnimationToJson(Animation instance) { +Map _$ChatJoinRequestToJson(ChatJoinRequest instance) { final val = { - 'file_id': instance.file_id, - 'file_unique_id': instance.file_unique_id, - 'width': instance.width, - 'height': instance.height, - 'duration': instance.duration, + 'chat': instance.chat.toJson(), + 'from': instance.from.toJson(), + 'user_chat_id': instance.userChatId, + 'date': instance.date, }; void writeNotNull(String key, dynamic value) { @@ -639,26 +389,57 @@ Map _$AnimationToJson(Animation instance) { } } - writeNotNull('thumb', instance.thumb?.toJson()); - writeNotNull('file_name', instance.file_name); - writeNotNull('mime_type', instance.mime_type); - writeNotNull('file_size', instance.file_size); + writeNotNull('bio', instance.bio); + writeNotNull('invite_link', instance.inviteLink?.toJson()); return val; } -Voice _$VoiceFromJson(Map json) => Voice( - file_id: json['file_id'] as String, - file_unique_id: json['file_unique_id'] as String, - duration: json['duration'] as int, - mime_type: json['mime_type'] as String?, - file_size: json['file_size'] as int?, +ChatLocation _$ChatLocationFromJson(Map json) => ChatLocation( + location: Location.fromJson(json['location'] as Map), + address: json['address'] as String, ); -Map _$VoiceToJson(Voice instance) { +Map _$ChatLocationToJson(ChatLocation instance) => + { + 'location': instance.location.toJson(), + 'address': instance.address, + }; + +ChatMemberAdministrator _$ChatMemberAdministratorFromJson( + Map json) => + ChatMemberAdministrator( + status: json['status'] as String, + user: User.fromJson(json['user'] as Map), + canBeEdited: json['can_be_edited'] as bool? ?? false, + isAnonymous: json['is_anonymous'] as bool? ?? false, + canManageChat: json['can_manage_chat'] as bool? ?? false, + canDeleteMessages: json['can_delete_messages'] as bool? ?? false, + canManageVideoChats: json['can_manage_video_chats'] as bool? ?? false, + canRestrictMembers: json['can_restrict_members'] as bool? ?? false, + canPromoteMembers: json['can_promote_members'] as bool? ?? false, + canChangeInfo: json['can_change_info'] as bool? ?? false, + canInviteUsers: json['can_invite_users'] as bool? ?? false, + canPostMessages: json['can_post_messages'] as bool?, + canEditMessages: json['can_edit_messages'] as bool?, + canPinMessages: json['can_pin_messages'] as bool?, + canManageTopics: json['can_manage_topics'] as bool?, + customTitle: json['custom_title'] as String?, + ); + +Map _$ChatMemberAdministratorToJson( + ChatMemberAdministrator instance) { final val = { - 'file_id': instance.file_id, - 'file_unique_id': instance.file_unique_id, - 'duration': instance.duration, + 'status': instance.status, + 'user': instance.user.toJson(), + 'can_be_edited': instance.canBeEdited, + 'is_anonymous': instance.isAnonymous, + 'can_manage_chat': instance.canManageChat, + 'can_delete_messages': instance.canDeleteMessages, + 'can_manage_video_chats': instance.canManageVideoChats, + 'can_restrict_members': instance.canRestrictMembers, + 'can_promote_members': instance.canPromoteMembers, + 'can_change_info': instance.canChangeInfo, + 'can_invite_users': instance.canInviteUsers, }; void writeNotNull(String key, dynamic value) { @@ -667,53 +448,65 @@ Map _$VoiceToJson(Voice instance) { } } - writeNotNull('mime_type', instance.mime_type); - writeNotNull('file_size', instance.file_size); + writeNotNull('can_post_messages', instance.canPostMessages); + writeNotNull('can_edit_messages', instance.canEditMessages); + writeNotNull('can_pin_messages', instance.canPinMessages); + writeNotNull('can_manage_topics', instance.canManageTopics); + writeNotNull('custom_title', instance.customTitle); return val; } -VideoNote _$VideoNoteFromJson(Map json) => VideoNote( - file_id: json['file_id'] as String, - file_unique_id: json['file_unique_id'] as String, - length: json['length'] as int, - duration: json['duration'] as int, - thumb: json['thumb'] == null - ? null - : PhotoSize.fromJson(json['thumb'] as Map), - file_size: json['file_size'] as int?, +ChatMemberBanned _$ChatMemberBannedFromJson(Map json) => + ChatMemberBanned( + status: json['status'] as String, + user: User.fromJson(json['user'] as Map), + untilDate: json['until_date'] as int, ); -Map _$VideoNoteToJson(VideoNote instance) { - final val = { - 'file_id': instance.file_id, - 'file_unique_id': instance.file_unique_id, - 'length': instance.length, - 'duration': instance.duration, - }; +Map _$ChatMemberBannedToJson(ChatMemberBanned instance) => + { + 'status': instance.status, + 'user': instance.user.toJson(), + 'until_date': instance.untilDate, + }; - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } +ChatMemberLeft _$ChatMemberLeftFromJson(Map json) => + ChatMemberLeft( + status: json['status'] as String, + user: User.fromJson(json['user'] as Map), + ); - writeNotNull('thumb', instance.thumb?.toJson()); - writeNotNull('file_size', instance.file_size); - return val; -} +Map _$ChatMemberLeftToJson(ChatMemberLeft instance) => + { + 'status': instance.status, + 'user': instance.user.toJson(), + }; -Contact _$ContactFromJson(Map json) => Contact( - phone_number: json['phone_number'] as String, - first_name: json['first_name'] as String, - last_name: json['last_name'] as String?, - user_id: json['user_id'] as int?, - vcard: json['vcard'] as String?, +ChatMemberMember _$ChatMemberMemberFromJson(Map json) => + ChatMemberMember( + status: json['status'] as String, + user: User.fromJson(json['user'] as Map), ); -Map _$ContactToJson(Contact instance) { +Map _$ChatMemberMemberToJson(ChatMemberMember instance) => + { + 'status': instance.status, + 'user': instance.user.toJson(), + }; + +ChatMemberOwner _$ChatMemberOwnerFromJson(Map json) => + ChatMemberOwner( + user: User.fromJson(json['user'] as Map), + status: json['status'] as String, + isAnonymous: json['is_anonymous'] as bool, + customTitle: json['custom_title'] as String?, + ); + +Map _$ChatMemberOwnerToJson(ChatMemberOwner instance) { final val = { - 'phone_number': instance.phone_number, - 'first_name': instance.first_name, + 'status': instance.status, + 'user': instance.user.toJson(), + 'is_anonymous': instance.isAnonymous, }; void writeNotNull(String key, dynamic value) { @@ -722,22 +515,45 @@ Map _$ContactToJson(Contact instance) { } } - writeNotNull('last_name', instance.last_name); - writeNotNull('user_id', instance.user_id); - writeNotNull('vcard', instance.vcard); + writeNotNull('custom_title', instance.customTitle); return val; } -LoginUrl _$LoginUrlFromJson(Map json) => LoginUrl( - url: json['url'] as String, - forward_text: json['forward_text'] as String?, - bot_username: json['bot_username'] as String?, - request_write_access: json['request_write_access'] as bool?, +ChatMemberRestricted _$ChatMemberRestrictedFromJson( + Map json) => + ChatMemberRestricted( + status: json['status'] as String, + user: User.fromJson(json['user'] as Map), + isMember: json['is_member'] as bool? ?? false, + canChangeInfo: json['can_change_info'] as bool? ?? false, + canInviteUsers: json['can_invite_users'] as bool? ?? false, + canPinMessages: json['can_pin_messages'] as bool? ?? false, + canManageTopics: json['can_manage_topics'] as bool? ?? false, + canSendMessages: json['can_send_messages'] as bool? ?? false, + canSendAudios: json['can_send_audios'] as bool? ?? false, + canSendDocuments: json['can_send_documents'] as bool? ?? false, + canSendPhotos: json['can_send_photos'] as bool? ?? false, + canSendVideos: json['can_send_videos'] as bool? ?? false, + canSendVideoNotes: json['can_send_video_notes'] as bool? ?? false, + canSendVoiceNotes: json['can_send_voice_notes'] as bool? ?? false, + canSendPolls: json['can_send_polls'] as bool? ?? false, + canSendOtherMessages: json['can_send_other_messages'] as bool? ?? false, + canAddWebPagePreviews: + json['can_add_web_page_previews'] as bool? ?? false, + untilDate: json['until_date'] as int, ); -Map _$LoginUrlToJson(LoginUrl instance) { +Map _$ChatMemberRestrictedToJson( + ChatMemberRestricted instance) { final val = { - 'url': instance.url, + 'status': instance.status, + 'user': instance.user.toJson(), + 'is_member': instance.isMember, + 'can_change_info': instance.canChangeInfo, + 'can_invite_users': instance.canInviteUsers, + 'can_pin_messages': instance.canPinMessages, + 'can_manage_topics': instance.canManageTopics, + 'can_send_messages': instance.canSendMessages, }; void writeNotNull(String key, dynamic value) { @@ -746,26 +562,45 @@ Map _$LoginUrlToJson(LoginUrl instance) { } } - writeNotNull('forward_text', instance.forward_text); - writeNotNull('bot_username', instance.bot_username); - writeNotNull('request_write_access', instance.request_write_access); + writeNotNull('can_send_audios', instance.canSendAudios); + writeNotNull('can_send_documents', instance.canSendDocuments); + writeNotNull('can_send_photos', instance.canSendPhotos); + writeNotNull('can_send_videos', instance.canSendVideos); + writeNotNull('can_send_video_notes', instance.canSendVideoNotes); + writeNotNull('can_send_voice_notes', instance.canSendVoiceNotes); + val['can_send_polls'] = instance.canSendPolls; + val['can_send_other_messages'] = instance.canSendOtherMessages; + val['can_add_web_page_previews'] = instance.canAddWebPagePreviews; + val['until_date'] = instance.untilDate; return val; } -Location _$LocationFromJson(Map json) => Location( - longitude: (json['longitude'] as num).toDouble(), - latitude: (json['latitude'] as num).toDouble(), - horizontal_accuracy: (json['horizontal_accuracy'] as num?)?.toDouble(), - live_period: json['live_period'] as int?, - heading: json['heading'] as int?, - proximity_alert_radius: json['proximity_alert_radius'] as int?, +ChatMemberUpdated _$ChatMemberUpdatedFromJson(Map json) => + ChatMemberUpdated( + chat: json['chat'] == null + ? null + : Chat.fromJson(json['chat'] as Map), + from: json['from'] == null + ? null + : User.fromJson(json['from'] as Map), + oldChatMember: json['old_chat_member'] == null + ? null + : ChatMember.fromJson( + json['old_chat_member'] as Map), + newChatMember: json['new_chat_member'] == null + ? null + : ChatMember.fromJson( + json['new_chat_member'] as Map), + inviteLink: json['invite_link'] == null + ? null + : ChatInviteLink.fromJson( + json['invite_link'] as Map), + viaChatFolderInviteLink: json['via_chat_folder_invite_link'] as bool?, + date: json['date'] as int?, ); -Map _$LocationToJson(Location instance) { - final val = { - 'longitude': instance.longitude, - 'latitude': instance.latitude, - }; +Map _$ChatMemberUpdatedToJson(ChatMemberUpdated instance) { + final val = {}; void writeNotNull(String key, dynamic value) { if (value != null) { @@ -773,29 +608,47 @@ Map _$LocationToJson(Location instance) { } } - writeNotNull('horizontal_accuracy', instance.horizontal_accuracy); - writeNotNull('live_period', instance.live_period); - writeNotNull('heading', instance.heading); - writeNotNull('proximity_alert_radius', instance.proximity_alert_radius); + writeNotNull('chat', instance.chat?.toJson()); + writeNotNull('from', instance.from?.toJson()); + writeNotNull('date', instance.date); + writeNotNull('old_chat_member', instance.oldChatMember?.toJson()); + writeNotNull('new_chat_member', instance.newChatMember?.toJson()); + writeNotNull('invite_link', instance.inviteLink?.toJson()); + writeNotNull('via_chat_folder_invite_link', instance.viaChatFolderInviteLink); return val; } -Venue _$VenueFromJson(Map json) => Venue( - location: Location.fromJson(json['location'] as Map), - title: json['title'] as String, - address: json['address'] as String, - foursquare_id: json['foursquare_id'] as String?, - foursquare_type: json['foursquare_type'] as String?, - google_place_id: json['google_place_id'] as String?, - google_place_type: json['google_place_type'] as String?, +ChatMember _$ChatMemberFromJson(Map json) => ChatMember( + status: json['status'] as String, + user: User.fromJson(json['user'] as Map), ); -Map _$VenueToJson(Venue instance) { - final val = { - 'location': instance.location.toJson(), - 'title': instance.title, - 'address': instance.address, - }; +Map _$ChatMemberToJson(ChatMember instance) => + { + 'status': instance.status, + 'user': instance.user.toJson(), + }; + +ChatPermissions _$ChatPermissionsFromJson(Map json) => + ChatPermissions( + canSendMessages: json['can_send_messages'] as bool?, + canSendAudios: json['can_send_audios'] as bool?, + canSendDocuments: json['can_send_documents'] as bool?, + canSendPhotos: json['can_send_photos'] as bool?, + canSendVideos: json['can_send_videos'] as bool?, + canSendVideoNotes: json['can_send_video_notes'] as bool?, + canSendVoiceNotes: json['can_send_voice_notes'] as bool?, + canSendPolls: json['can_send_polls'] as bool?, + canSendOtherMessages: json['can_send_other_messages'] as bool?, + canAddWebPagePreviews: json['can_add_web_page_previews'] as bool?, + canChangeInfo: json['can_change_info'] as bool?, + canInviteUsers: json['can_invite_users'] as bool?, + canPinMessages: json['can_pin_messages'] as bool?, + canManageTopics: json['can_manage_topics'] as bool?, + ); + +Map _$ChatPermissionsToJson(ChatPermissions instance) { + final val = {}; void writeNotNull(String key, dynamic value) { if (value != null) { @@ -803,68 +656,98 @@ Map _$VenueToJson(Venue instance) { } } - writeNotNull('foursquare_id', instance.foursquare_id); - writeNotNull('foursquare_type', instance.foursquare_type); - writeNotNull('google_place_id', instance.google_place_id); - writeNotNull('google_place_type', instance.google_place_type); + writeNotNull('can_send_messages', instance.canSendMessages); + writeNotNull('can_send_audios', instance.canSendAudios); + writeNotNull('can_send_documents', instance.canSendDocuments); + writeNotNull('can_send_photos', instance.canSendPhotos); + writeNotNull('can_send_videos', instance.canSendVideos); + writeNotNull('can_send_video_notes', instance.canSendVideoNotes); + writeNotNull('can_send_voice_notes', instance.canSendVoiceNotes); + writeNotNull('can_send_polls', instance.canSendPolls); + writeNotNull('can_send_other_messages', instance.canSendOtherMessages); + writeNotNull('can_add_web_page_previews', instance.canAddWebPagePreviews); + writeNotNull('can_change_info', instance.canChangeInfo); + writeNotNull('can_invite_users', instance.canInviteUsers); + writeNotNull('can_pin_messages', instance.canPinMessages); + writeNotNull('can_manage_topics', instance.canManageTopics); return val; } -PollOption _$PollOptionFromJson(Map json) => PollOption( - text: json['text'] as String, - voter_count: json['voter_count'] as int, +ChatPhoto _$ChatPhotoFromJson(Map json) => ChatPhoto( + smallFileId: json['small_file_id'] as String, + smallFileUniqueId: json['small_file_unique_id'] as String, + bigFileId: json['big_file_id'] as String, + bigFileUniqueId: json['big_file_unique_id'] as String, ); -Map _$PollOptionToJson(PollOption instance) => - { - 'text': instance.text, - 'voter_count': instance.voter_count, +Map _$ChatPhotoToJson(ChatPhoto instance) => { + 'small_file_id': instance.smallFileId, + 'small_file_unique_id': instance.smallFileUniqueId, + 'big_file_id': instance.bigFileId, + 'big_file_unique_id': instance.bigFileUniqueId, }; -PollAnswer _$PollAnswerFromJson(Map json) => PollAnswer( - poll_id: json['poll_id'] as String, - user: User.fromJson(json['user'] as Map), - option_ids: - (json['option_ids'] as List).map((e) => e as int).toList(), +ChatShared _$ChatSharedFromJson(Map json) => ChatShared( + requestId: json['request_id'] as int, + userId: json['user_id'] as int, ); -Map _$PollAnswerToJson(PollAnswer instance) => +Map _$ChatSharedToJson(ChatShared instance) => { - 'poll_id': instance.poll_id, - 'user': instance.user.toJson(), - 'option_ids': instance.option_ids, + 'request_id': instance.requestId, + 'user_id': instance.userId, }; -Poll _$PollFromJson(Map json) => Poll( - id: json['id'] as String, - question: json['question'] as String, - options: (json['options'] as List) - .map((e) => PollOption.fromJson(e as Map)) - .toList(), - total_voter_count: json['total_voter_count'] as int, - is_closed: json['is_closed'] as bool, - is_anonymous: json['is_anonymous'] as bool, +Chat _$ChatFromJson(Map json) => Chat( + id: json['id'] as int, type: json['type'] as String, - allows_multiple_answers: json['allows_multiple_answers'] as bool, - correct_option_id: json['correct_option_id'] as int?, - explanation: json['explanation'] as String?, - explanation_entities: (json['explanation_entities'] as List?) - ?.map((e) => MessageEntity.fromJson(e as Map)) + title: json['title'] as String?, + username: json['username'] as String?, + firstName: json['first_name'] as String?, + lastName: json['last_name'] as String?, + isForum: json['is_forum'] as bool?, + photo: json['photo'] == null + ? null + : ChatPhoto.fromJson(json['photo'] as Map), + activeUsernames: (json['active_usernames'] as List?) + ?.map((e) => e as String) .toList(), - open_period: json['open_period'] as int?, - close_date: json['close_date'] as int?, + emojiStatusCustomEmojiId: json['emoji_status_custom_emoji_id'] as String?, + emojiStatusExpirationDate: + json['emoji_status_expiration_date'] as String?, + bio: json['bio'] as String?, + hasPrivateForwards: json['has_private_forwards'] as bool?, + hasRestrictedVoiceAndVideoMessages: + json['has_restricted_voice_and_video_messages'] as bool?, + joinToSendMessages: json['join_to_send_messages'] as bool?, + joinByRequest: json['join_by_request'] as bool?, + description: json['description'] as String?, + inviteLink: json['invite_link'] as String?, + pinnedMessage: json['pinned_message'] == null + ? null + : Message.fromJson(json['pinned_message'] as Map), + permissions: json['permissions'] == null + ? null + : ChatPermissions.fromJson( + json['permissions'] as Map), + slowModeDelay: json['slow_mode_delay'] as int?, + messageAutoDeleteTime: json['message_auto_delete_time'] as int?, + hasAggressiveAntiSpamEnabled: + json['has_aggressive_anti_spam_enabled'] as bool?, + hasHiddenMembers: json['has_hidden_members'] as bool?, + hasProtectedContent: json['has_protected_content'] as bool?, + stickerSetName: json['sticker_set_name'] as String?, + canSetStickerSet: json['can_set_sticker_set'] as bool?, + linkedChatId: json['linked_chat_id'] as int?, + location: json['location'] == null + ? null + : ChatLocation.fromJson(json['location'] as Map), ); -Map _$PollToJson(Poll instance) { +Map _$ChatToJson(Chat instance) { final val = { 'id': instance.id, - 'question': instance.question, - 'options': instance.options.map((e) => e.toJson()).toList(), - 'total_voter_count': instance.total_voter_count, - 'is_closed': instance.is_closed, - 'is_anonymous': instance.is_anonymous, 'type': instance.type, - 'allows_multiple_answers': instance.allows_multiple_answers, }; void writeNotNull(String key, dynamic value) { @@ -873,90 +756,56 @@ Map _$PollToJson(Poll instance) { } } - writeNotNull('correct_option_id', instance.correct_option_id); - writeNotNull('explanation', instance.explanation); - writeNotNull('explanation_entities', - instance.explanation_entities?.map((e) => e.toJson()).toList()); - writeNotNull('open_period', instance.open_period); - writeNotNull('close_date', instance.close_date); + writeNotNull('title', instance.title); + writeNotNull('username', instance.username); + writeNotNull('first_name', instance.firstName); + writeNotNull('last_name', instance.lastName); + writeNotNull('is_forum', instance.isForum); + writeNotNull('photo', instance.photo?.toJson()); + writeNotNull('active_usernames', instance.activeUsernames); + writeNotNull( + 'emoji_status_custom_emoji_id', instance.emojiStatusCustomEmojiId); + writeNotNull( + 'emoji_status_expiration_date', instance.emojiStatusExpirationDate); + writeNotNull('bio', instance.bio); + writeNotNull('has_private_forwards', instance.hasPrivateForwards); + writeNotNull('has_restricted_voice_and_video_messages', + instance.hasRestrictedVoiceAndVideoMessages); + writeNotNull('join_to_send_messages', instance.joinToSendMessages); + writeNotNull('join_by_request', instance.joinByRequest); + writeNotNull('description', instance.description); + writeNotNull('invite_link', instance.inviteLink); + writeNotNull('pinned_message', instance.pinnedMessage?.toJson()); + writeNotNull('permissions', instance.permissions?.toJson()); + writeNotNull('slow_mode_delay', instance.slowModeDelay); + writeNotNull('message_auto_delete_time', instance.messageAutoDeleteTime); + writeNotNull('has_aggressive_anti_spam_enabled', + instance.hasAggressiveAntiSpamEnabled); + writeNotNull('has_hidden_members', instance.hasHiddenMembers); + writeNotNull('has_protected_content', instance.hasProtectedContent); + writeNotNull('sticker_set_name', instance.stickerSetName); + writeNotNull('can_set_sticker_set', instance.canSetStickerSet); + writeNotNull('linked_chat_id', instance.linkedChatId); + writeNotNull('location', instance.location?.toJson()); return val; } -Dice _$DiceFromJson(Map json) => Dice( - value: json['value'] as int, - emoji: json['emoji'] as String, - ); - -Map _$DiceToJson(Dice instance) => { - 'value': instance.value, - 'emoji': instance.emoji, - }; - -ProximityAlertTriggered _$ProximityAlertTriggeredFromJson( - Map json) => - ProximityAlertTriggered( - traveler: User.fromJson(json['traveler'] as Map), - watcher: User.fromJson(json['watcher'] as Map), - distance: json['distance'] as int, - ); - -Map _$ProximityAlertTriggeredToJson( - ProximityAlertTriggered instance) => - { - 'traveler': instance.traveler.toJson(), - 'watcher': instance.watcher.toJson(), - 'distance': instance.distance, - }; - -MessageAutoDeleteTimerChanged _$MessageAutoDeleteTimerChangedFromJson( - Map json) => - MessageAutoDeleteTimerChanged( - message_auto_delete_time: json['message_auto_delete_time'] as int, - ); - -Map _$MessageAutoDeleteTimerChangedToJson( - MessageAutoDeleteTimerChanged instance) => - { - 'message_auto_delete_time': instance.message_auto_delete_time, - }; - -VoiceChatScheduled _$VoiceChatScheduledFromJson(Map json) => - VoiceChatScheduled( - json['start_date'] as int, - ); - -Map _$VoiceChatScheduledToJson(VoiceChatScheduled instance) => - { - 'start_date': instance.start_date, - }; - -VoiceChatStarted _$VoiceChatStartedFromJson(Map json) => - VoiceChatStarted(); - -Map _$VoiceChatStartedToJson(VoiceChatStarted instance) => - {}; - -VoiceChatEnded _$VoiceChatEndedFromJson(Map json) => - VoiceChatEnded( - duration: json['duration'] as int, - ); - -Map _$VoiceChatEndedToJson(VoiceChatEnded instance) => - { - 'duration': instance.duration, - }; - -VoiceChatParticipantsInvited _$VoiceChatParticipantsInvitedFromJson( - Map json) => - VoiceChatParticipantsInvited( - users: (json['users'] as List?) - ?.map((e) => User.fromJson(e as Map)) - .toList(), +ChosenInlineResult _$ChosenInlineResultFromJson(Map json) => + ChosenInlineResult( + resultId: json['result_id'] as String, + from: User.fromJson(json['from'] as Map), + location: json['location'] == null + ? null + : Location.fromJson(json['location'] as Map), + inlineMessageId: json['inline_message_id'] as String?, + query: json['query'] as String, ); -Map _$VoiceChatParticipantsInvitedToJson( - VoiceChatParticipantsInvited instance) { - final val = {}; +Map _$ChosenInlineResultToJson(ChosenInlineResult instance) { + final val = { + 'result_id': instance.resultId, + 'from': instance.from.toJson(), + }; void writeNotNull(String key, dynamic value) { if (value != null) { @@ -964,39 +813,24 @@ Map _$VoiceChatParticipantsInvitedToJson( } } - writeNotNull('users', instance.users?.map((e) => e.toJson()).toList()); + writeNotNull('location', instance.location?.toJson()); + writeNotNull('inline_message_id', instance.inlineMessageId); + val['query'] = instance.query; return val; } -UserProfilePhotos _$UserProfilePhotosFromJson(Map json) => - UserProfilePhotos( - total_count: json['total_count'] as int, - photos: (json['photos'] as List) - .map((e) => (e as List) - .map((e) => PhotoSize.fromJson(e as Map)) - .toList()) - .toList(), - ); - -Map _$UserProfilePhotosToJson(UserProfilePhotos instance) => - { - 'total_count': instance.total_count, - 'photos': instance.photos - .map((e) => e.map((e) => e.toJson()).toList()) - .toList(), - }; - -File _$FileFromJson(Map json) => File( - file_id: json['file_id'] as String, - file_unique_id: json['file_unique_id'] as String, - file_size: json['file_size'] as int?, - file_path: json['file_path'] as String?, +Contact _$ContactFromJson(Map json) => Contact( + phoneNumber: json['phone_number'] as String, + firstName: json['first_name'] as String, + lastName: json['last_name'] as String?, + userId: json['user_id'] as int?, + vcard: json['vcard'] as String?, ); -Map _$FileToJson(File instance) { +Map _$ContactToJson(Contact instance) { final val = { - 'file_id': instance.file_id, - 'file_unique_id': instance.file_unique_id, + 'phone_number': instance.phoneNumber, + 'first_name': instance.firstName, }; void writeNotNull(String key, dynamic value) { @@ -1005,34 +839,37 @@ Map _$FileToJson(File instance) { } } - writeNotNull('file_size', instance.file_size); - writeNotNull('file_path', instance.file_path); + writeNotNull('last_name', instance.lastName); + writeNotNull('user_id', instance.userId); + writeNotNull('vcard', instance.vcard); return val; } -ReplyMarkup _$ReplyMarkupFromJson(Map json) => ReplyMarkup(); +Dice _$DiceFromJson(Map json) => Dice( + value: json['value'] as int, + emoji: json['emoji'] as String, + ); -Map _$ReplyMarkupToJson(ReplyMarkup instance) => - {}; +Map _$DiceToJson(Dice instance) => { + 'value': instance.value, + 'emoji': instance.emoji, + }; -ReplyKeyboardMarkup _$ReplyKeyboardMarkupFromJson(Map json) => - ReplyKeyboardMarkup( - keyboard: (json['keyboard'] as List) - .map((e) => (e as List) - .map((e) => KeyboardButton.fromJson(e as Map)) - .toList()) - .toList(), - resize_keyboard: json['resize_keyboard'] as bool?, - one_time_keyboard: json['one_time_keyboard'] as bool?, - input_field_placeholder: json['input_field_placeholder'] as String?, - selective: json['selective'] as bool?, +Document _$DocumentFromJson(Map json) => Document( + fileId: json['file_id'] as String, + fileUniqueId: json['file_unique_id'] as String, + thumbnail: json['thumbnail'] == null + ? null + : PhotoSize.fromJson(json['thumbnail'] as Map), + fileName: json['file_name'] as String?, + mimeType: json['mime_type'] as String?, + fileSize: json['file_size'] as int?, ); -Map _$ReplyKeyboardMarkupToJson(ReplyKeyboardMarkup instance) { +Map _$DocumentToJson(Document instance) { final val = { - 'keyboard': instance.keyboard - .map((e) => e.map((e) => e.toJson()).toList()) - .toList(), + 'file_id': instance.fileId, + 'file_unique_id': instance.fileUniqueId, }; void writeNotNull(String key, dynamic value) { @@ -1041,27 +878,58 @@ Map _$ReplyKeyboardMarkupToJson(ReplyKeyboardMarkup instance) { } } - writeNotNull('resize_keyboard', instance.resize_keyboard); - writeNotNull('one_time_keyboard', instance.one_time_keyboard); - writeNotNull('input_field_placeholder', instance.input_field_placeholder); - writeNotNull('selective', instance.selective); + writeNotNull('thumbnail', instance.thumbnail?.toJson()); + writeNotNull('file_name', instance.fileName); + writeNotNull('mime_type', instance.mimeType); + writeNotNull('file_size', instance.fileSize); return val; } -KeyboardButton _$KeyboardButtonFromJson(Map json) => - KeyboardButton( - text: json['text'] as String, - request_contact: json['request_contact'] as bool?, - request_location: json['request_location'] as bool?, - request_poll: json['request_poll'] == null - ? null - : KeyboardButtonPollType.fromJson( - json['request_poll'] as Map), +EncryptedCredentials _$EncryptedCredentialsFromJson( + Map json) => + EncryptedCredentials( + data: json['data'] as String, + hash: json['hash'] as String, + secret: json['secret'] as String, ); -Map _$KeyboardButtonToJson(KeyboardButton instance) { - final val = { - 'text': instance.text, +Map _$EncryptedCredentialsToJson( + EncryptedCredentials instance) => + { + 'data': instance.data, + 'hash': instance.hash, + 'secret': instance.secret, + }; + +EncryptedPassportElement _$EncryptedPassportElementFromJson( + Map json) => + EncryptedPassportElement( + type: json['type'] as String, + data: json['data'] as String?, + phoneNumber: json['phone_number'] as String?, + email: json['email'] as String?, + files: (json['files'] as List?) + ?.map((e) => PassportFile.fromJson(e as Map)) + .toList(), + frontSide: json['front_side'] == null + ? null + : PassportFile.fromJson(json['front_side'] as Map), + reverseSide: json['reverse_side'] == null + ? null + : PassportFile.fromJson(json['reverse_side'] as Map), + selfie: json['selfie'] == null + ? null + : PassportFile.fromJson(json['selfie'] as Map), + translation: (json['translation'] as List?) + ?.map((e) => PassportFile.fromJson(e as Map)) + .toList(), + hash: json['hash'] as String, + ); + +Map _$EncryptedPassportElementToJson( + EncryptedPassportElement instance) { + final val = { + 'type': instance.type, }; void writeNotNull(String key, dynamic value) { @@ -1070,21 +938,31 @@ Map _$KeyboardButtonToJson(KeyboardButton instance) { } } - writeNotNull('request_contact', instance.request_contact); - writeNotNull('request_location', instance.request_location); - writeNotNull('request_poll', instance.request_poll?.toJson()); + writeNotNull('data', instance.data); + writeNotNull('phone_number', instance.phoneNumber); + writeNotNull('email', instance.email); + writeNotNull('files', instance.files?.map((e) => e.toJson()).toList()); + writeNotNull('front_side', instance.frontSide?.toJson()); + writeNotNull('reverse_side', instance.reverseSide?.toJson()); + writeNotNull('selfie', instance.selfie?.toJson()); + writeNotNull( + 'translation', instance.translation?.map((e) => e.toJson()).toList()); + val['hash'] = instance.hash; return val; } -KeyboardButtonPollType _$KeyboardButtonPollTypeFromJson( - Map json) => - KeyboardButtonPollType( - type: json['type'] as String?, +File _$FileFromJson(Map json) => File( + fileId: json['file_id'] as String, + fileUniqueId: json['file_unique_id'] as String, + fileSize: json['file_size'] as int?, + filePath: json['file_path'] as String?, ); -Map _$KeyboardButtonPollTypeToJson( - KeyboardButtonPollType instance) { - final val = {}; +Map _$FileToJson(File instance) { + final val = { + 'file_id': instance.fileId, + 'file_unique_id': instance.fileUniqueId, + }; void writeNotNull(String key, dynamic value) { if (value != null) { @@ -1092,19 +970,20 @@ Map _$KeyboardButtonPollTypeToJson( } } - writeNotNull('type', instance.type); + writeNotNull('file_size', instance.fileSize); + writeNotNull('file_path', instance.filePath); return val; } -ReplyKeyboardRemove _$ReplyKeyboardRemoveFromJson(Map json) => - ReplyKeyboardRemove( - remove_keyboard: json['remove_keyboard'] as bool, +ForceReply _$ForceReplyFromJson(Map json) => ForceReply( + forceReply: json['force_reply'] as bool, + inputFieldPlaceholder: json['input_field_placeholder'] as String?, selective: json['selective'] as bool?, ); -Map _$ReplyKeyboardRemoveToJson(ReplyKeyboardRemove instance) { +Map _$ForceReplyToJson(ForceReply instance) { final val = { - 'remove_keyboard': instance.remove_keyboard, + 'force_reply': instance.forceReply, }; void writeNotNull(String key, dynamic value) { @@ -1113,52 +992,28 @@ Map _$ReplyKeyboardRemoveToJson(ReplyKeyboardRemove instance) { } } + writeNotNull('input_field_placeholder', instance.inputFieldPlaceholder); writeNotNull('selective', instance.selective); return val; } -InlineKeyboardMarkup _$InlineKeyboardMarkupFromJson( - Map json) => - InlineKeyboardMarkup( - inline_keyboard: (json['inline_keyboard'] as List) - .map((e) => (e as List) - .map((e) => - InlineKeyboardButton.fromJson(e as Map)) - .toList()) - .toList(), - ); +ForumTopicClosed _$ForumTopicClosedFromJson(Map json) => + ForumTopicClosed(); -Map _$InlineKeyboardMarkupToJson( - InlineKeyboardMarkup instance) => - { - 'inline_keyboard': instance.inline_keyboard - .map((e) => e.map((e) => e.toJson()).toList()) - .toList(), - }; +Map _$ForumTopicClosedToJson(ForumTopicClosed instance) => + {}; -InlineKeyboardButton _$InlineKeyboardButtonFromJson( - Map json) => - InlineKeyboardButton( - text: json['text'] as String, - url: json['url'] as String?, - login_url: json['login_url'] == null - ? null - : LoginUrl.fromJson(json['login_url'] as Map), - callback_data: json['callback_data'] as String?, - switch_inline_query: json['switch_inline_query'] as String?, - switch_inline_query_current_chat: - json['switch_inline_query_current_chat'] as String?, - callback_game: json['callback_game'] == null - ? null - : CallbackGame.fromJson( - json['callback_game'] as Map), - pay: json['pay'] as bool?, +ForumTopicCreated _$ForumTopicCreatedFromJson(Map json) => + ForumTopicCreated( + name: json['name'] as String, + iconColor: json['icon_color'] as int, + iconCustomEmojiId: json['icon_custom_emoji_id'] as String?, ); -Map _$InlineKeyboardButtonToJson( - InlineKeyboardButton instance) { +Map _$ForumTopicCreatedToJson(ForumTopicCreated instance) { final val = { - 'text': instance.text, + 'name': instance.name, + 'icon_color': instance.iconColor, }; void writeNotNull(String key, dynamic value) { @@ -1167,35 +1022,18 @@ Map _$InlineKeyboardButtonToJson( } } - writeNotNull('url', instance.url); - writeNotNull('login_url', instance.login_url?.toJson()); - writeNotNull('callback_data', instance.callback_data); - writeNotNull('switch_inline_query', instance.switch_inline_query); - writeNotNull('switch_inline_query_current_chat', - instance.switch_inline_query_current_chat); - writeNotNull('callback_game', instance.callback_game?.toJson()); - writeNotNull('pay', instance.pay); + writeNotNull('icon_custom_emoji_id', instance.iconCustomEmojiId); return val; } -CallbackQuery _$CallbackQueryFromJson(Map json) => - CallbackQuery( - id: json['id'] as String, - from: User.fromJson(json['from'] as Map), - message: json['message'] == null - ? null - : Message.fromJson(json['message'] as Map), - inline_message_id: json['inline_message_id'] as String?, - chat_instance: json['chat_instance'] as String?, - data: json['data'] as String?, - game_short_name: json['game_short_name'] as String?, +ForumTopicEdited _$ForumTopicEditedFromJson(Map json) => + ForumTopicEdited( + name: json['name'] as String?, + iconCustomEmojiId: json['icon_custom_emoji_id'] as String?, ); -Map _$CallbackQueryToJson(CallbackQuery instance) { - final val = { - 'id': instance.id, - 'from': instance.from.toJson(), - }; +Map _$ForumTopicEditedToJson(ForumTopicEdited instance) { + final val = {}; void writeNotNull(String key, dynamic value) { if (value != null) { @@ -1203,23 +1041,29 @@ Map _$CallbackQueryToJson(CallbackQuery instance) { } } - writeNotNull('message', instance.message?.toJson()); - writeNotNull('inline_message_id', instance.inline_message_id); - writeNotNull('chat_instance', instance.chat_instance); - writeNotNull('data', instance.data); - writeNotNull('game_short_name', instance.game_short_name); + writeNotNull('name', instance.name); + writeNotNull('icon_custom_emoji_id', instance.iconCustomEmojiId); return val; } -ForceReply _$ForceReplyFromJson(Map json) => ForceReply( - force_reply: json['force_reply'] as bool, - input_field_placeholder: json['input_field_placeholder'] as String?, - selective: json['selective'] as bool?, +ForumTopicReopened _$ForumTopicReopenedFromJson(Map json) => + ForumTopicReopened(); + +Map _$ForumTopicReopenedToJson(ForumTopicReopened instance) => + {}; + +ForumTopic _$ForumTopicFromJson(Map json) => ForumTopic( + messageThreadId: json['message_thread_id'] as String, + name: json['name'] as String, + iconColor: json['icon_color'] as int, + iconCustomEmojiId: json['icon_custom_emoji_id'] as String?, ); -Map _$ForceReplyToJson(ForceReply instance) { +Map _$ForumTopicToJson(ForumTopic instance) { final val = { - 'force_reply': instance.force_reply, + 'message_thread_id': instance.messageThreadId, + 'name': instance.name, + 'icon_color': instance.iconColor, }; void writeNotNull(String key, dynamic value) { @@ -1228,45 +1072,44 @@ Map _$ForceReplyToJson(ForceReply instance) { } } - writeNotNull('input_field_placeholder', instance.input_field_placeholder); - writeNotNull('selective', instance.selective); + writeNotNull('icon_custom_emoji_id', instance.iconCustomEmojiId); return val; } -ChatPhoto _$ChatPhotoFromJson(Map json) => ChatPhoto( - small_file_id: json['small_file_id'] as String, - small_file_unique_id: json['small_file_unique_id'] as String, - big_file_id: json['big_file_id'] as String, - big_file_unique_id: json['big_file_unique_id'] as String, +GameHighScore _$GameHighScoreFromJson(Map json) => + GameHighScore( + position: json['position'] as int, + user: User.fromJson(json['user'] as Map), + score: json['score'] as int, ); -Map _$ChatPhotoToJson(ChatPhoto instance) => { - 'small_file_id': instance.small_file_id, - 'small_file_unique_id': instance.small_file_unique_id, - 'big_file_id': instance.big_file_id, - 'big_file_unique_id': instance.big_file_unique_id, +Map _$GameHighScoreToJson(GameHighScore instance) => + { + 'position': instance.position, + 'user': instance.user.toJson(), + 'score': instance.score, }; -ChatInviteLink _$ChatInviteLinkFromJson(Map json) => - ChatInviteLink( - invite_link: json['invite_link'] as String, - creator: User.fromJson(json['creator'] as Map), - creates_join_request: json['creates_join_request'] as bool, - is_primary: json['is_primary'] as bool, - is_revoked: json['is_revoked'] as bool, - name: json['name'] as String?, - expire_date: json['expire_date'] as int?, - member_limit: json['member_limit'] as int?, - pending_join_request_count: json['pending_join_request_count'] as int?, +Game _$GameFromJson(Map json) => Game( + title: json['title'] as String, + description: json['description'] as String, + photo: (json['photo'] as List) + .map((e) => PhotoSize.fromJson(e as Map)) + .toList(), + text: json['text'] as String?, + textEntities: (json['text_entities'] as List?) + ?.map((e) => MessageEntity.fromJson(e as Map)) + .toList(), + animation: json['animation'] == null + ? null + : Animation.fromJson(json['animation'] as Map), ); -Map _$ChatInviteLinkToJson(ChatInviteLink instance) { +Map _$GameToJson(Game instance) { final val = { - 'invite_link': instance.invite_link, - 'creator': instance.creator.toJson(), - 'creates_join_request': instance.creates_join_request, - 'is_primary': instance.is_primary, - 'is_revoked': instance.is_revoked, + 'title': instance.title, + 'description': instance.description, + 'photo': instance.photo.map((e) => e.toJson()).toList(), }; void writeNotNull(String key, dynamic value) { @@ -1275,38 +1118,60 @@ Map _$ChatInviteLinkToJson(ChatInviteLink instance) { } } - writeNotNull('name', instance.name); - writeNotNull('expire_date', instance.expire_date); - writeNotNull('member_limit', instance.member_limit); + writeNotNull('text', instance.text); writeNotNull( - 'pending_join_request_count', instance.pending_join_request_count); + 'text_entities', instance.textEntities?.map((e) => e.toJson()).toList()); + writeNotNull('animation', instance.animation?.toJson()); return val; } -ChatMember _$ChatMemberFromJson(Map json) => ChatMember( - status: json['status'] as String, - user: User.fromJson(json['user'] as Map), - ); +GeneralForumTopicHidden _$GeneralForumTopicHiddenFromJson( + Map json) => + GeneralForumTopicHidden(); -Map _$ChatMemberToJson(ChatMember instance) => - { - 'status': instance.status, - 'user': instance.user.toJson(), - }; +Map _$GeneralForumTopicHiddenToJson( + GeneralForumTopicHidden instance) => + {}; -ChatMemberOwner _$ChatMemberOwnerFromJson(Map json) => - ChatMemberOwner( - user: User.fromJson(json['user'] as Map), - status: json['status'] as String, - is_anonymous: json['is_anonymous'] as bool, - custom_title: json['custom_title'] as String?, +GeneralForumTopicUnhidden _$GeneralForumTopicUnhiddenFromJson( + Map json) => + GeneralForumTopicUnhidden(); + +Map _$GeneralForumTopicUnhiddenToJson( + GeneralForumTopicUnhidden instance) => + {}; + +InlineKeyboardButton _$InlineKeyboardButtonFromJson( + Map json) => + InlineKeyboardButton( + text: json['text'] as String, + url: json['url'] as String?, + callbackData: json['callback_data'] as String?, + webApp: json['web_app'] == null + ? null + : WebAppInfo.fromJson(json['web_app'] as Map), + loginUrl: json['login_url'] == null + ? null + : LoginUrl.fromJson(json['login_url'] as Map), + switchInlineQuery: json['switch_inline_query'] as String?, + switchInlineQueryCurrentChat: + json['switch_inline_query_current_chat'] as String?, + callbackGame: json['callback_game'] == null + ? null + : CallbackGame.fromJson( + json['callback_game'] as Map), + pay: json['pay'] as bool?, + switchInlineQueryChosenChat: json['switch_inline_query_chosen_chat'] == + null + ? null + : SwitchInlineQueryChosenChat.fromJson( + json['switch_inline_query_chosen_chat'] as Map), ); -Map _$ChatMemberOwnerToJson(ChatMemberOwner instance) { +Map _$InlineKeyboardButtonToJson( + InlineKeyboardButton instance) { final val = { - 'status': instance.status, - 'user': instance.user.toJson(), - 'is_anonymous': instance.is_anonymous, + 'text': instance.text, }; void writeNotNull(String key, dynamic value) { @@ -1315,44 +1180,66 @@ Map _$ChatMemberOwnerToJson(ChatMemberOwner instance) { } } - writeNotNull('custom_title', instance.custom_title); + writeNotNull('url', instance.url); + writeNotNull('callback_data', instance.callbackData); + writeNotNull('web_app', instance.webApp?.toJson()); + writeNotNull('login_url', instance.loginUrl?.toJson()); + writeNotNull('switch_inline_query', instance.switchInlineQuery); + writeNotNull('switch_inline_query_current_chat', + instance.switchInlineQueryCurrentChat); + writeNotNull('callback_game', instance.callbackGame?.toJson()); + writeNotNull('pay', instance.pay); + writeNotNull('switch_inline_query_chosen_chat', + instance.switchInlineQueryChosenChat?.toJson()); return val; } -ChatMemberAdministrator _$ChatMemberAdministratorFromJson( +InlineKeyboardMarkup _$InlineKeyboardMarkupFromJson( Map json) => - ChatMemberAdministrator( - status: json['status'] as String, - user: User.fromJson(json['user'] as Map), - can_be_edited: json['can_be_edited'] as bool? ?? false, - is_anonymous: json['is_anonymous'] as bool? ?? false, - can_manage_chat: json['can_manage_chat'] as bool? ?? false, - can_delete_messages: json['can_delete_messages'] as bool? ?? false, - can_manage_voice_chats: json['can_manage_voice_chats'] as bool? ?? false, - can_restrict_members: json['can_restrict_members'] as bool? ?? false, - can_promote_members: json['can_promote_members'] as bool? ?? false, - can_change_info: json['can_change_info'] as bool? ?? false, - can_invite_users: json['can_invite_users'] as bool? ?? false, - can_post_messages: json['can_post_messages'] as bool?, - can_edit_messages: json['can_edit_messages'] as bool?, - can_pin_messages: json['can_pin_messages'] as bool?, - custom_title: json['custom_title'] as String?, + InlineKeyboardMarkup( + inlineKeyboard: (json['inline_keyboard'] as List) + .map((e) => (e as List) + .map((e) => + InlineKeyboardButton.fromJson(e as Map)) + .toList()) + .toList(), ); -Map _$ChatMemberAdministratorToJson( - ChatMemberAdministrator instance) { +Map _$InlineKeyboardMarkupToJson( + InlineKeyboardMarkup instance) => + { + 'inline_keyboard': instance.inlineKeyboard + .map((e) => e.map((e) => e.toJson()).toList()) + .toList(), + }; + +InlineQueryResultArticle _$InlineQueryResultArticleFromJson( + Map json) => + InlineQueryResultArticle( + id: json['id'] as String, + type: json['type'] as String? ?? InlineQueryResult.typeArticle, + title: json['title'] as String, + inputMessageContent: InputMessageContent.fromJson( + json['input_message_content'] as Map), + replyMarkup: json['reply_markup'] == null + ? null + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), + url: json['url'] as String?, + hideUrl: json['hide_url'] as bool?, + description: json['description'] as String?, + thumbnailUrl: json['thumbnail_url'] as String?, + thumbnailWidth: json['thumbnail_width'] as String?, + thumbnailHeight: json['thumbnail_height'] as String?, + ); + +Map _$InlineQueryResultArticleToJson( + InlineQueryResultArticle instance) { final val = { - 'status': instance.status, - 'user': instance.user.toJson(), - 'can_be_edited': instance.can_be_edited, - 'is_anonymous': instance.is_anonymous, - 'can_manage_chat': instance.can_manage_chat, - 'can_delete_messages': instance.can_delete_messages, - 'can_manage_voice_chats': instance.can_manage_voice_chats, - 'can_restrict_members': instance.can_restrict_members, - 'can_promote_members': instance.can_promote_members, - 'can_change_info': instance.can_change_info, - 'can_invite_users': instance.can_invite_users, + 'id': instance.id, + 'type': instance.type, + 'title': instance.title, + 'input_message_content': instance.inputMessageContent.toJson(), }; void writeNotNull(String key, dynamic value) { @@ -1361,112 +1248,48 @@ Map _$ChatMemberAdministratorToJson( } } - writeNotNull('can_post_messages', instance.can_post_messages); - writeNotNull('can_edit_messages', instance.can_edit_messages); - writeNotNull('can_pin_messages', instance.can_pin_messages); - writeNotNull('custom_title', instance.custom_title); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('url', instance.url); + writeNotNull('hide_url', instance.hideUrl); + writeNotNull('description', instance.description); + writeNotNull('thumbnail_url', instance.thumbnailUrl); + writeNotNull('thumbnail_width', instance.thumbnailWidth); + writeNotNull('thumbnail_height', instance.thumbnailHeight); return val; } -ChatMemberMember _$ChatMemberMemberFromJson(Map json) => - ChatMemberMember( - status: json['status'] as String, - user: User.fromJson(json['user'] as Map), - ); - -Map _$ChatMemberMemberToJson(ChatMemberMember instance) => - { - 'status': instance.status, - 'user': instance.user.toJson(), - }; - -ChatMemberRestricted _$ChatMemberRestrictedFromJson( +InlineQueryResultAudio _$InlineQueryResultAudioFromJson( Map json) => - ChatMemberRestricted( - status: json['status'] as String, - user: User.fromJson(json['user'] as Map), - is_member: json['is_member'] as bool? ?? false, - can_change_info: json['can_change_info'] as bool? ?? false, - can_invite_users: json['can_invite_users'] as bool? ?? false, - can_pin_messages: json['can_pin_messages'] as bool? ?? false, - can_send_messages: json['can_send_messages'] as bool? ?? false, - can_send_media_messages: - json['can_send_media_messages'] as bool? ?? false, - can_send_polls: json['can_send_polls'] as bool? ?? false, - can_send_other_messages: - json['can_send_other_messages'] as bool? ?? false, - can_add_web_page_previews: - json['can_add_web_page_previews'] as bool? ?? false, - until_date: json['until_date'] as int, - ); - -Map _$ChatMemberRestrictedToJson( - ChatMemberRestricted instance) => - { - 'status': instance.status, - 'user': instance.user.toJson(), - 'is_member': instance.is_member, - 'can_change_info': instance.can_change_info, - 'can_invite_users': instance.can_invite_users, - 'can_pin_messages': instance.can_pin_messages, - 'can_send_messages': instance.can_send_messages, - 'can_send_media_messages': instance.can_send_media_messages, - 'can_send_polls': instance.can_send_polls, - 'can_send_other_messages': instance.can_send_other_messages, - 'can_add_web_page_previews': instance.can_add_web_page_previews, - 'until_date': instance.until_date, - }; - -ChatMemberLeft _$ChatMemberLeftFromJson(Map json) => - ChatMemberLeft( - status: json['status'] as String, - user: User.fromJson(json['user'] as Map), - ); - -Map _$ChatMemberLeftToJson(ChatMemberLeft instance) => - { - 'status': instance.status, - 'user': instance.user.toJson(), - }; - -ChatMemberBanned _$ChatMemberBannedFromJson(Map json) => - ChatMemberBanned( - status: json['status'] as String, - user: User.fromJson(json['user'] as Map), - until_date: json['until_date'] as int, - ); - -Map _$ChatMemberBannedToJson(ChatMemberBanned instance) => - { - 'status': instance.status, - 'user': instance.user.toJson(), - 'until_date': instance.until_date, - }; - -ChatMemberUpdated _$ChatMemberUpdatedFromJson(Map json) => - ChatMemberUpdated( - chat: json['chat'] == null - ? null - : Chat.fromJson(json['chat'] as Map), - from: json['from'] == null - ? null - : User.fromJson(json['from'] as Map), - old_chat_member: json['old_chat_member'] == null - ? null - : ChatMember.fromJson( - json['old_chat_member'] as Map), - new_chat_member: json['new_chat_member'] == null + InlineQueryResultAudio( + id: json['id'] as String, + type: json['type'] as String? ?? InlineQueryResult.typeAudio, + audioUrl: json['audio_url'] as String, + title: json['title'] as String, + caption: json['caption'] as String?, + parseMode: json['parse_mode'] as String?, + performer: json['performer'] as String?, + audioDuration: json['audio_duration'] as int?, + captionEntities: (json['caption_entities'] as List?) + ?.map((e) => MessageEntity.fromJson(e as Map)) + .toList(), + replyMarkup: json['reply_markup'] == null ? null - : ChatMember.fromJson( - json['new_chat_member'] as Map), - invite_link: json['invite_link'] == null + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), + inputMessageContent: json['input_message_content'] == null ? null - : ChatInviteLink.fromJson( - json['invite_link'] as Map), - )..date = json['date'] as int?; + : InputMessageContent.fromJson( + json['input_message_content'] as Map), + ); -Map _$ChatMemberUpdatedToJson(ChatMemberUpdated instance) { - final val = {}; +Map _$InlineQueryResultAudioToJson( + InlineQueryResultAudio instance) { + final val = { + 'id': instance.id, + 'type': instance.type, + 'audio_url': instance.audioUrl, + 'title': instance.title, + }; void writeNotNull(String key, dynamic value) { if (value != null) { @@ -1474,32 +1297,44 @@ Map _$ChatMemberUpdatedToJson(ChatMemberUpdated instance) { } } - writeNotNull('chat', instance.chat?.toJson()); - writeNotNull('from', instance.from?.toJson()); - writeNotNull('date', instance.date); - writeNotNull('old_chat_member', instance.old_chat_member?.toJson()); - writeNotNull('new_chat_member', instance.new_chat_member?.toJson()); - writeNotNull('invite_link', instance.invite_link?.toJson()); + writeNotNull('caption', instance.caption); + writeNotNull('parse_mode', instance.parseMode); + writeNotNull('performer', instance.performer); + writeNotNull('audio_duration', instance.audioDuration); + writeNotNull('caption_entities', + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); return val; } -ChatJoinRequest _$ChatJoinRequestFromJson(Map json) => - ChatJoinRequest( - chat: Chat.fromJson(json['chat'] as Map), - from: User.fromJson(json['from'] as Map), - date: json['date'] as int, - bio: json['bio'] as String?, - invite_link: json['invite_link'] == null +InlineQueryResultCachedAudio _$InlineQueryResultCachedAudioFromJson( + Map json) => + InlineQueryResultCachedAudio( + id: json['id'] as String, + type: json['type'] as String? ?? InlineQueryResult.typeAudio, + audioFileId: json['audio_file_id'] as String, + caption: json['caption'] as String?, + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) + ?.map((e) => MessageEntity.fromJson(e as Map)) + .toList(), + replyMarkup: json['reply_markup'] == null ? null - : ChatInviteLink.fromJson( - json['invite_link'] as Map), + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), + inputMessageContent: json['input_message_content'] == null + ? null + : InputMessageContent.fromJson( + json['input_message_content'] as Map), ); -Map _$ChatJoinRequestToJson(ChatJoinRequest instance) { +Map _$InlineQueryResultCachedAudioToJson( + InlineQueryResultCachedAudio instance) { final val = { - 'chat': instance.chat.toJson(), - 'from': instance.from.toJson(), - 'date': instance.date, + 'id': instance.id, + 'type': instance.type, + 'audio_file_id': instance.audioFileId, }; void writeNotNull(String key, dynamic value) { @@ -1508,25 +1343,46 @@ Map _$ChatJoinRequestToJson(ChatJoinRequest instance) { } } - writeNotNull('bio', instance.bio); - writeNotNull('invite_link', instance.invite_link?.toJson()); + writeNotNull('caption', instance.caption); + writeNotNull('parse_mode', instance.parseMode); + writeNotNull('caption_entities', + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); return val; } -ChatPermissions _$ChatPermissionsFromJson(Map json) => - ChatPermissions( - can_send_messages: json['can_send_messages'] as bool?, - can_send_media_messages: json['can_send_media_messages'] as bool?, - can_send_polls: json['can_send_polls'] as bool?, - can_send_other_messages: json['can_send_other_messages'] as bool?, - can_add_web_page_previews: json['can_add_web_page_previews'] as bool?, - can_change_info: json['can_change_info'] as bool?, - can_invite_users: json['can_invite_users'] as bool?, - can_pin_messages: json['can_pin_messages'] as bool?, +InlineQueryResultCachedDocument _$InlineQueryResultCachedDocumentFromJson( + Map json) => + InlineQueryResultCachedDocument( + id: json['id'] as String, + type: json['type'] as String? ?? InlineQueryResult.typeDocument, + title: json['title'] as String, + documentFileId: json['document_file_id'] as String, + description: json['description'] as String?, + caption: json['caption'] as String?, + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) + ?.map((e) => MessageEntity.fromJson(e as Map)) + .toList(), + replyMarkup: json['reply_markup'] == null + ? null + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), + inputMessageContent: json['input_message_content'] == null + ? null + : InputMessageContent.fromJson( + json['input_message_content'] as Map), ); -Map _$ChatPermissionsToJson(ChatPermissions instance) { - final val = {}; +Map _$InlineQueryResultCachedDocumentToJson( + InlineQueryResultCachedDocument instance) { + final val = { + 'id': instance.id, + 'type': instance.type, + 'title': instance.title, + 'document_file_id': instance.documentFileId, + }; void writeNotNull(String key, dynamic value) { if (value != null) { @@ -1534,107 +1390,44 @@ Map _$ChatPermissionsToJson(ChatPermissions instance) { } } - writeNotNull('can_send_messages', instance.can_send_messages); - writeNotNull('can_send_media_messages', instance.can_send_media_messages); - writeNotNull('can_send_polls', instance.can_send_polls); - writeNotNull('can_send_other_messages', instance.can_send_other_messages); - writeNotNull('can_add_web_page_previews', instance.can_add_web_page_previews); - writeNotNull('can_change_info', instance.can_change_info); - writeNotNull('can_invite_users', instance.can_invite_users); - writeNotNull('can_pin_messages', instance.can_pin_messages); + writeNotNull('description', instance.description); + writeNotNull('caption', instance.caption); + writeNotNull('parse_mode', instance.parseMode); + writeNotNull('caption_entities', + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); return val; } -ChatLocation _$ChatLocationFromJson(Map json) => ChatLocation( - location: Location.fromJson(json['location'] as Map), - address: json['address'] as String, - ); - -Map _$ChatLocationToJson(ChatLocation instance) => - { - 'location': instance.location.toJson(), - 'address': instance.address, - }; - -BotCommand _$BotCommandFromJson(Map json) => BotCommand( - command: json['command'] as String, - description: json['description'] as String, - ); - -Map _$BotCommandToJson(BotCommand instance) => - { - 'command': instance.command, - 'description': instance.description, - }; - -BotCommandScope _$BotCommandScopeFromJson(Map json) => - BotCommandScope( - type: json['type'] as String, - ); - -Map _$BotCommandScopeToJson(BotCommandScope instance) => - { - 'type': instance.type, - }; - -BotCommandScopeDefault _$BotCommandScopeDefaultFromJson( - Map json) => - BotCommandScopeDefault( - type: json['type'] as String? ?? BotCommandScope.DEFAULT, - ); - -Map _$BotCommandScopeDefaultToJson( - BotCommandScopeDefault instance) => - { - 'type': instance.type, - }; - -BotCommandScopeAllPrivateChats _$BotCommandScopeAllPrivateChatsFromJson( - Map json) => - BotCommandScopeAllPrivateChats( - type: json['type'] as String? ?? BotCommandScope.ALL_PRIVATE_CHATS, - ); - -Map _$BotCommandScopeAllPrivateChatsToJson( - BotCommandScopeAllPrivateChats instance) => - { - 'type': instance.type, - }; - -BotCommandScopeAllGroupChats _$BotCommandScopeAllGroupChatsFromJson( +InlineQueryResultCachedGif _$InlineQueryResultCachedGifFromJson( Map json) => - BotCommandScopeAllGroupChats( - type: json['type'] as String? ?? BotCommandScope.ALL_GROUP_CHATS, - ); - -Map _$BotCommandScopeAllGroupChatsToJson( - BotCommandScopeAllGroupChats instance) => - { - 'type': instance.type, - }; - -BotCommandScopeAllChatAdministrators - _$BotCommandScopeAllChatAdministratorsFromJson(Map json) => - BotCommandScopeAllChatAdministrators( - type: json['type'] as String? ?? - BotCommandScope.ALL_CHAT_ADMINISTRATORS, - ); - -Map _$BotCommandScopeAllChatAdministratorsToJson( - BotCommandScopeAllChatAdministrators instance) => - { - 'type': instance.type, - }; - -BotCommandScopeChat _$BotCommandScopeChatFromJson(Map json) => - BotCommandScopeChat( - type: json['type'] as String? ?? BotCommandScope.CHAT, - chat_id: json['chat_id'], + InlineQueryResultCachedGif( + id: json['id'] as String, + type: json['type'] as String? ?? InlineQueryResult.typeGif, + gifFileId: json['gif_file_id'] as String, + title: json['title'] as String?, + caption: json['caption'] as String?, + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) + ?.map((e) => MessageEntity.fromJson(e as Map)) + .toList(), + replyMarkup: json['reply_markup'] == null + ? null + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), + inputMessageContent: json['input_message_content'] == null + ? null + : InputMessageContent.fromJson( + json['input_message_content'] as Map), ); -Map _$BotCommandScopeChatToJson(BotCommandScopeChat instance) { +Map _$InlineQueryResultCachedGifToJson( + InlineQueryResultCachedGif instance) { final val = { + 'id': instance.id, 'type': instance.type, + 'gif_file_id': instance.gifFileId, }; void writeNotNull(String key, dynamic value) { @@ -1643,21 +1436,44 @@ Map _$BotCommandScopeChatToJson(BotCommandScopeChat instance) { } } - writeNotNull('chat_id', instance.chat_id); + writeNotNull('title', instance.title); + writeNotNull('caption', instance.caption); + writeNotNull('parse_mode', instance.parseMode); + writeNotNull('caption_entities', + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); return val; } -BotCommandScopeChatAdministrators _$BotCommandScopeChatAdministratorsFromJson( +InlineQueryResultCachedMpeg4Gif _$InlineQueryResultCachedMpeg4GifFromJson( Map json) => - BotCommandScopeChatAdministrators( - type: json['type'] as String? ?? BotCommandScope.CHAT_ADMINISTRATORS, - chat_id: json['chat_id'], + InlineQueryResultCachedMpeg4Gif( + id: json['id'] as String, + type: json['type'] as String? ?? InlineQueryResult.typeMpeg4Gif, + mpeg4FileId: json['mpeg4_file_id'] as String, + title: json['title'] as String?, + caption: json['caption'] as String?, + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) + ?.map((e) => MessageEntity.fromJson(e as Map)) + .toList(), + replyMarkup: json['reply_markup'] == null + ? null + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), + inputMessageContent: json['input_message_content'] == null + ? null + : InputMessageContent.fromJson( + json['input_message_content'] as Map), ); -Map _$BotCommandScopeChatAdministratorsToJson( - BotCommandScopeChatAdministrators instance) { +Map _$InlineQueryResultCachedMpeg4GifToJson( + InlineQueryResultCachedMpeg4Gif instance) { final val = { + 'id': instance.id, 'type': instance.type, + 'mpeg4_file_id': instance.mpeg4FileId, }; void writeNotNull(String key, dynamic value) { @@ -1666,21 +1482,45 @@ Map _$BotCommandScopeChatAdministratorsToJson( } } - writeNotNull('chat_id', instance.chat_id); + writeNotNull('title', instance.title); + writeNotNull('caption', instance.caption); + writeNotNull('parse_mode', instance.parseMode); + writeNotNull('caption_entities', + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); return val; } -BotCommandScopeChatMember _$BotCommandScopeChatMemberFromJson( +InlineQueryResultCachedPhoto _$InlineQueryResultCachedPhotoFromJson( Map json) => - BotCommandScopeChatMember( - type: json['type'] as String? ?? BotCommandScope.CHAT_MEMBER, - chat_id: json['chat_id'], + InlineQueryResultCachedPhoto( + id: json['id'] as String, + type: json['type'] as String? ?? InlineQueryResult.typePhoto, + photoFileId: json['photo_file_id'] as String, + title: json['title'] as String?, + description: json['description'] as String?, + caption: json['caption'] as String?, + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) + ?.map((e) => MessageEntity.fromJson(e as Map)) + .toList(), + replyMarkup: json['reply_markup'] == null + ? null + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), + inputMessageContent: json['input_message_content'] == null + ? null + : InputMessageContent.fromJson( + json['input_message_content'] as Map), ); -Map _$BotCommandScopeChatMemberToJson( - BotCommandScopeChatMember instance) { +Map _$InlineQueryResultCachedPhotoToJson( + InlineQueryResultCachedPhoto instance) { final val = { + 'id': instance.id, 'type': instance.type, + 'photo_file_id': instance.photoFileId, }; void writeNotNull(String key, dynamic value) { @@ -1689,18 +1529,39 @@ Map _$BotCommandScopeChatMemberToJson( } } - writeNotNull('chat_id', instance.chat_id); + writeNotNull('title', instance.title); + writeNotNull('description', instance.description); + writeNotNull('caption', instance.caption); + writeNotNull('parse_mode', instance.parseMode); + writeNotNull('caption_entities', + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); return val; } -ResponseParameters _$ResponseParametersFromJson(Map json) => - ResponseParameters( - migrate_to_chat_id: json['migrate_to_chat_id'] as int?, - retry_after: json['retry_after'] as int?, +InlineQueryResultCachedSticker _$InlineQueryResultCachedStickerFromJson( + Map json) => + InlineQueryResultCachedSticker( + id: json['id'] as String, + type: json['type'] as String? ?? InlineQueryResult.typeSticker, + stickerFileId: json['sticker_file_id'] as String?, + replyMarkup: json['reply_markup'] == null + ? null + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), + inputMessageContent: json['input_message_content'] == null + ? null + : InputMessageContent.fromJson( + json['input_message_content'] as Map), ); -Map _$ResponseParametersToJson(ResponseParameters instance) { - final val = {}; +Map _$InlineQueryResultCachedStickerToJson( + InlineQueryResultCachedSticker instance) { + final val = { + 'id': instance.id, + 'type': instance.type, + }; void writeNotNull(String key, dynamic value) { if (value != null) { @@ -1708,25 +1569,42 @@ Map _$ResponseParametersToJson(ResponseParameters instance) { } } - writeNotNull('migrate_to_chat_id', instance.migrate_to_chat_id); - writeNotNull('retry_after', instance.retry_after); + writeNotNull('sticker_file_id', instance.stickerFileId); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); return val; } -InputMedia _$InputMediaFromJson(Map json) => InputMedia( - type: json['type'] as String, - media: json['media'] as String, +InlineQueryResultCachedVideo _$InlineQueryResultCachedVideoFromJson( + Map json) => + InlineQueryResultCachedVideo( + id: json['id'] as String, + type: json['type'] as String? ?? InlineQueryResult.typeVideo, + videoFileId: json['video_file_id'] as String, + title: json['title'] as String, + description: json['description'] as String?, caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) ?.map((e) => MessageEntity.fromJson(e as Map)) .toList(), + replyMarkup: json['reply_markup'] == null + ? null + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), + inputMessageContent: json['input_message_content'] == null + ? null + : InputMessageContent.fromJson( + json['input_message_content'] as Map), ); -Map _$InputMediaToJson(InputMedia instance) { +Map _$InlineQueryResultCachedVideoToJson( + InlineQueryResultCachedVideo instance) { final val = { + 'id': instance.id, 'type': instance.type, - 'media': instance.media, + 'video_file_id': instance.videoFileId, + 'title': instance.title, }; void writeNotNull(String key, dynamic value) { @@ -1735,28 +1613,45 @@ Map _$InputMediaToJson(InputMedia instance) { } } + writeNotNull('description', instance.description); writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); + writeNotNull('parse_mode', instance.parseMode); writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); return val; } -InputMediaPhoto _$InputMediaPhotoFromJson(Map json) => - InputMediaPhoto( - type: json['type'] as String? ?? InputMedia.PHOTO, - media: json['media'] as String, +InlineQueryResultCachedVoice _$InlineQueryResultCachedVoiceFromJson( + Map json) => + InlineQueryResultCachedVoice( + id: json['id'] as String, + type: json['type'] as String? ?? InlineQueryResult.typeVoice, + voiceFileId: json['voice_file_id'] as String, + title: json['title'] as String, caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) ?.map((e) => MessageEntity.fromJson(e as Map)) .toList(), + replyMarkup: json['reply_markup'] == null + ? null + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), + inputMessageContent: json['input_message_content'] == null + ? null + : InputMessageContent.fromJson( + json['input_message_content'] as Map), ); -Map _$InputMediaPhotoToJson(InputMediaPhoto instance) { +Map _$InlineQueryResultCachedVoiceToJson( + InlineQueryResultCachedVoice instance) { final val = { + 'id': instance.id, 'type': instance.type, - 'media': instance.media, + 'voice_file_id': instance.voiceFileId, + 'title': instance.title, }; void writeNotNull(String key, dynamic value) { @@ -1766,32 +1661,43 @@ Map _$InputMediaPhotoToJson(InputMediaPhoto instance) { } writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); + writeNotNull('parse_mode', instance.parseMode); writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); return val; } -InputMediaVideo _$InputMediaVideoFromJson(Map json) => - InputMediaVideo( - type: json['type'] as String? ?? InputMedia.VIDEO, - media: json['media'] as String, - caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) - ?.map((e) => MessageEntity.fromJson(e as Map)) - .toList(), - thumb: json['thumb'], - width: json['width'] as int?, - height: json['height'] as int?, - duration: json['duration'] as int?, - supports_streaming: json['supports_streaming'] as bool?, +InlineQueryResultContact _$InlineQueryResultContactFromJson( + Map json) => + InlineQueryResultContact( + id: json['id'] as String, + type: json['type'] as String? ?? InlineQueryResult.typeContact, + phoneNumber: json['phone_number'] as String, + firstName: json['first_name'] as String, + lastName: json['last_name'] as String?, + vcard: json['vcard'] as String?, + replyMarkup: json['reply_markup'] == null + ? null + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), + inputMessageContent: json['input_message_content'] == null + ? null + : InputMessageContent.fromJson( + json['input_message_content'] as Map), + thumbnailUrl: json['thumbnail_url'] as String?, + thumbnailWidth: json['thumbnail_width'] as int?, + thumbnailHeight: json['thumbnail_height'] as int?, ); -Map _$InputMediaVideoToJson(InputMediaVideo instance) { +Map _$InlineQueryResultContactToJson( + InlineQueryResultContact instance) { final val = { + 'id': instance.id, 'type': instance.type, - 'media': instance.media, + 'phone_number': instance.phoneNumber, + 'first_name': instance.firstName, }; void writeNotNull(String key, dynamic value) { @@ -1800,37 +1706,49 @@ Map _$InputMediaVideoToJson(InputMediaVideo instance) { } } - writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); - writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('thumb', instance.thumb); - writeNotNull('width', instance.width); - writeNotNull('height', instance.height); - writeNotNull('duration', instance.duration); - writeNotNull('supports_streaming', instance.supports_streaming); + writeNotNull('last_name', instance.lastName); + writeNotNull('vcard', instance.vcard); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); + writeNotNull('thumbnail_url', instance.thumbnailUrl); + writeNotNull('thumbnail_width', instance.thumbnailWidth); + writeNotNull('thumbnail_height', instance.thumbnailHeight); return val; } -InputMediaAnimation _$InputMediaAnimationFromJson(Map json) => - InputMediaAnimation( - type: json['type'] as String? ?? InputMedia.ANIMATION, - media: json['media'] as String, - thumb: json['thumb'], +InlineQueryResultDocument _$InlineQueryResultDocumentFromJson( + Map json) => + InlineQueryResultDocument( + id: json['id'] as String, + type: json['type'] as String? ?? InlineQueryResult.typeDocument, + title: json['title'] as String, caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) ?.map((e) => MessageEntity.fromJson(e as Map)) .toList(), - width: json['width'] as int?, - height: json['height'] as int?, - duration: json['duration'] as int?, + documentUrl: json['document_url'] as String, + mimeType: json['mime_type'] as String, + description: json['description'] as String?, + replyMarkup: json['reply_markup'] == null + ? null + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), + inputMessageContent: json['input_message_content'] == null + ? null + : InputMessageContent.fromJson( + json['input_message_content'] as Map), + thumbnailUrl: json['thumbnail_url'] as String?, + thumbnailWidth: json['thumbnail_width'] as int?, + thumbnailHeight: json['thumbnail_height'] as int?, ); -Map _$InputMediaAnimationToJson(InputMediaAnimation instance) { +Map _$InlineQueryResultDocumentToJson( + InlineQueryResultDocument instance) { final val = { + 'id': instance.id, 'type': instance.type, - 'media': instance.media, + 'title': instance.title, }; void writeNotNull(String key, dynamic value) { @@ -1840,35 +1758,38 @@ Map _$InputMediaAnimationToJson(InputMediaAnimation instance) { } writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); + writeNotNull('parse_mode', instance.parseMode); writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('thumb', instance.thumb); - writeNotNull('width', instance.width); - writeNotNull('height', instance.height); - writeNotNull('duration', instance.duration); + instance.captionEntities?.map((e) => e.toJson()).toList()); + val['document_url'] = instance.documentUrl; + val['mime_type'] = instance.mimeType; + writeNotNull('description', instance.description); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); + writeNotNull('thumbnail_url', instance.thumbnailUrl); + writeNotNull('thumbnail_width', instance.thumbnailWidth); + writeNotNull('thumbnail_height', instance.thumbnailHeight); return val; } -InputMediaAudio _$InputMediaAudioFromJson(Map json) => - InputMediaAudio( - type: json['type'] as String? ?? InputMedia.AUDIO, - media: json['media'] as String, - thumb: json['thumb'], - caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) - ?.map((e) => MessageEntity.fromJson(e as Map)) - .toList(), - duration: json['duration'] as int?, - performer: json['performer'] as String?, - title: json['title'] as String?, +InlineQueryResultGame _$InlineQueryResultGameFromJson( + Map json) => + InlineQueryResultGame( + id: json['id'] as String, + type: json['type'] as String? ?? InlineQueryResult.typeGame, + gameShortName: json['game_short_name'] as String, + replyMarkup: json['reply_markup'] == null + ? null + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), ); -Map _$InputMediaAudioToJson(InputMediaAudio instance) { +Map _$InlineQueryResultGameToJson( + InlineQueryResultGame instance) { final val = { + 'id': instance.id, 'type': instance.type, - 'media': instance.media, + 'game_short_name': instance.gameShortName, }; void writeNotNull(String key, dynamic value) { @@ -1877,35 +1798,43 @@ Map _$InputMediaAudioToJson(InputMediaAudio instance) { } } - writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); - writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('thumb', instance.thumb); - writeNotNull('duration', instance.duration); - writeNotNull('performer', instance.performer); - writeNotNull('title', instance.title); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); return val; } -InputMediaDocument _$InputMediaDocumentFromJson(Map json) => - InputMediaDocument( - type: json['type'] as String? ?? InputMedia.DOCUMENT, - media: json['media'] as String, - thumb: json['thumb'], +InlineQueryResultGif _$InlineQueryResultGifFromJson( + Map json) => + InlineQueryResultGif( + id: json['id'] as String, + type: json['type'] as String? ?? InlineQueryResult.typeGif, + gifUrl: json['gif_url'] as String, + gifWidth: json['gif_width'] as int?, + gifHeight: json['gif_height'] as int?, + gifDuration: json['gif_duration'] as int?, + thumbnailUrl: json['thumbnail_url'] as String, + thumbnailMimeType: json['thumbnail_mime_type'] as String?, + title: json['title'] as String?, caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) ?.map((e) => MessageEntity.fromJson(e as Map)) .toList(), - disable_content_type_detection: - json['disable_content_type_detection'] as bool?, + replyMarkup: json['reply_markup'] == null + ? null + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), + inputMessageContent: json['input_message_content'] == null + ? null + : InputMessageContent.fromJson( + json['input_message_content'] as Map), ); -Map _$InputMediaDocumentToJson(InputMediaDocument instance) { +Map _$InlineQueryResultGifToJson( + InlineQueryResultGif instance) { final val = { + 'id': instance.id, 'type': instance.type, - 'media': instance.media, + 'gif_url': instance.gifUrl, }; void writeNotNull(String key, dynamic value) { @@ -1914,43 +1843,54 @@ Map _$InputMediaDocumentToJson(InputMediaDocument instance) { } } + writeNotNull('gif_width', instance.gifWidth); + writeNotNull('gif_height', instance.gifHeight); + writeNotNull('gif_duration', instance.gifDuration); + val['thumbnail_url'] = instance.thumbnailUrl; + writeNotNull('thumbnail_mime_type', instance.thumbnailMimeType); + writeNotNull('title', instance.title); writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); + writeNotNull('parse_mode', instance.parseMode); writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('thumb', instance.thumb); - writeNotNull('disable_content_type_detection', - instance.disable_content_type_detection); + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); return val; } -Sticker _$StickerFromJson(Map json) => Sticker( - file_id: json['file_id'] as String, - file_unique_id: json['file_unique_id'] as String, - width: json['width'] as int, - height: json['height'] as int, - is_animated: json['is_animated'] as bool, - is_video: json['is_video'] as bool, - thumb: json['thumb'] == null +InlineQueryResultLocation _$InlineQueryResultLocationFromJson( + Map json) => + InlineQueryResultLocation( + id: json['id'] as String, + type: json['type'] as String? ?? InlineQueryResult.typeLocation, + latitude: (json['latitude'] as num).toDouble(), + longitude: (json['longitude'] as num).toDouble(), + title: json['title'] as String, + horizontalAccuracy: (json['horizontal_accuracy'] as num?)?.toDouble(), + livePeriod: json['live_period'] as int?, + heading: json['heading'] as int?, + proximityAlertRadius: json['proximity_alert_radius'] as int?, + replyMarkup: json['reply_markup'] == null ? null - : PhotoSize.fromJson(json['thumb'] as Map), - emoji: json['emoji'] as String?, - set_name: json['set_name'] as String?, - mask_position: json['mask_position'] == null + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), + inputMessageContent: json['input_message_content'] == null ? null - : MaskPosition.fromJson( - json['mask_position'] as Map), - file_size: json['file_size'] as int?, + : InputMessageContent.fromJson( + json['input_message_content'] as Map), + thumbnailUrl: json['thumbnail_url'] as String?, + thumbnailWidth: json['thumbnail_width'] as int?, + thumbnailHeight: json['thumbnail_height'] as int?, ); -Map _$StickerToJson(Sticker instance) { +Map _$InlineQueryResultLocationToJson( + InlineQueryResultLocation instance) { final val = { - 'file_id': instance.file_id, - 'file_unique_id': instance.file_unique_id, - 'width': instance.width, - 'height': instance.height, - 'is_animated': instance.is_animated, - 'is_video': instance.is_video, + 'id': instance.id, + 'type': instance.type, + 'latitude': instance.latitude, + 'longitude': instance.longitude, + 'title': instance.title, }; void writeNotNull(String key, dynamic value) { @@ -1959,36 +1899,51 @@ Map _$StickerToJson(Sticker instance) { } } - writeNotNull('thumb', instance.thumb?.toJson()); - writeNotNull('emoji', instance.emoji); - writeNotNull('set_name', instance.set_name); - writeNotNull('mask_position', instance.mask_position?.toJson()); - writeNotNull('file_size', instance.file_size); + writeNotNull('horizontal_accuracy', instance.horizontalAccuracy); + writeNotNull('live_period', instance.livePeriod); + writeNotNull('heading', instance.heading); + writeNotNull('proximity_alert_radius', instance.proximityAlertRadius); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); + writeNotNull('thumbnail_url', instance.thumbnailUrl); + writeNotNull('thumbnail_width', instance.thumbnailWidth); + writeNotNull('thumbnail_height', instance.thumbnailHeight); return val; } -StickerSet _$StickerSetFromJson(Map json) => StickerSet( - name: json['name'] as String, - title: json['title'] as String, - is_animated: json['is_animated'] as bool, - is_video: json['is_video'] as bool, - contains_masks: json['contains_masks'] as bool, - stickers: (json['stickers'] as List) - .map((e) => Sticker.fromJson(e as Map)) +InlineQueryResultMpeg4Gif _$InlineQueryResultMpeg4GifFromJson( + Map json) => + InlineQueryResultMpeg4Gif( + id: json['id'] as String, + type: json['type'] as String? ?? InlineQueryResult.typeMpeg4Gif, + mpeg4Url: json['mpeg4_url'] as String, + mpeg4Width: json['mpeg4_width'] as int?, + mpeg4Height: json['mpeg4_height'] as int?, + mpeg4Duration: json['mpeg4_duration'] as int?, + thumbnailUrl: json['thumbnail_url'] as String, + thumbnailMimeType: json['thumbnail_mime_type'] as String?, + title: json['title'] as String?, + caption: json['caption'] as String?, + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) + ?.map((e) => MessageEntity.fromJson(e as Map)) .toList(), - thumb: json['thumb'] == null + replyMarkup: json['reply_markup'] == null + ? null + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), + inputMessageContent: json['input_message_content'] == null ? null - : PhotoSize.fromJson(json['thumb'] as Map), + : InputMessageContent.fromJson( + json['input_message_content'] as Map), ); -Map _$StickerSetToJson(StickerSet instance) { +Map _$InlineQueryResultMpeg4GifToJson( + InlineQueryResultMpeg4Gif instance) { final val = { - 'name': instance.name, - 'title': instance.title, - 'is_animated': instance.is_animated, - 'is_video': instance.is_video, - 'contains_masks': instance.contains_masks, - 'stickers': instance.stickers.map((e) => e.toJson()).toList(), + 'id': instance.id, + 'type': instance.type, + 'mpeg4_url': instance.mpeg4Url, }; void writeNotNull(String key, dynamic value) { @@ -1997,123 +1952,18 @@ Map _$StickerSetToJson(StickerSet instance) { } } - writeNotNull('thumb', instance.thumb?.toJson()); - return val; -} - -MaskPosition _$MaskPositionFromJson(Map json) => MaskPosition( - point: json['point'] as String, - x_shift: (json['x_shift'] as num).toDouble(), - y_shift: (json['y_shift'] as num).toDouble(), - scale: (json['scale'] as num).toDouble(), - ); - -Map _$MaskPositionToJson(MaskPosition instance) => - { - 'point': instance.point, - 'x_shift': instance.x_shift, - 'y_shift': instance.y_shift, - 'scale': instance.scale, - }; - -InlineQuery _$InlineQueryFromJson(Map json) => InlineQuery( - id: json['id'] as String, - from: User.fromJson(json['from'] as Map), - query: json['query'] as String, - offset: json['offset'] as String, - chat_type: json['chat_type'] as String?, - location: json['location'] == null - ? null - : Location.fromJson(json['location'] as Map), - ); - -Map _$InlineQueryToJson(InlineQuery instance) { - final val = { - 'id': instance.id, - 'from': instance.from.toJson(), - 'query': instance.query, - 'offset': instance.offset, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('chat_type', instance.chat_type); - writeNotNull('location', instance.location?.toJson()); - return val; -} - -InlineQueryResult _$InlineQueryResultFromJson(Map json) => - InlineQueryResult( - type: json['type'] as String, - id: json['id'] as String, - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), - ); - -Map _$InlineQueryResultToJson(InlineQueryResult instance) { - final val = { - 'type': instance.type, - 'id': instance.id, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - return val; -} - -InlineQueryResultArticle _$InlineQueryResultArticleFromJson( - Map json) => - InlineQueryResultArticle( - id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.ARTICLE, - title: json['title'] as String, - input_message_content: InputMessageContent.fromJson( - json['input_message_content'] as Map), - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), - url: json['url'] as String?, - hide_url: json['hide_url'] as bool?, - description: json['description'] as String?, - thumb_url: json['thumb_url'] as String?, - thumb_width: json['thumb_width'] as String?, - thumb_height: json['thumb_height'] as String?, - ); - -Map _$InlineQueryResultArticleToJson( - InlineQueryResultArticle instance) { - final val = { - 'id': instance.id, - 'type': instance.type, - 'title': instance.title, - 'input_message_content': instance.input_message_content.toJson(), - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull('url', instance.url); - writeNotNull('hide_url', instance.hide_url); - writeNotNull('description', instance.description); - writeNotNull('thumb_url', instance.thumb_url); - writeNotNull('thumb_width', instance.thumb_width); - writeNotNull('thumb_height', instance.thumb_height); + writeNotNull('mpeg4_width', instance.mpeg4Width); + writeNotNull('mpeg4_height', instance.mpeg4Height); + writeNotNull('mpeg4_duration', instance.mpeg4Duration); + val['thumbnail_url'] = instance.thumbnailUrl; + writeNotNull('thumbnail_mime_type', instance.thumbnailMimeType); + writeNotNull('title', instance.title); + writeNotNull('caption', instance.caption); + writeNotNull('parse_mode', instance.parseMode); + writeNotNull('caption_entities', + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); return val; } @@ -2121,23 +1971,23 @@ InlineQueryResultPhoto _$InlineQueryResultPhotoFromJson( Map json) => InlineQueryResultPhoto( id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.PHOTO, - photo_url: json['photo_url'] as String, - thumb_url: json['thumb_url'] as String, - photo_width: json['photo_width'] as int?, - photo_height: json['photo_height'] as int?, + type: json['type'] as String? ?? InlineQueryResult.typePhoto, + photoUrl: json['photo_url'] as String, + thumbnailUrl: json['thumbnail_url'] as String, + photoWidth: json['photo_width'] as int?, + photoHeight: json['photo_height'] as int?, title: json['title'] as String?, description: json['description'] as String?, caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) ?.map((e) => MessageEntity.fromJson(e as Map)) .toList(), - reply_markup: json['reply_markup'] == null + replyMarkup: json['reply_markup'] == null ? null : InlineKeyboardMarkup.fromJson( json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null + inputMessageContent: json['input_message_content'] == null ? null : InputMessageContent.fromJson( json['input_message_content'] as Map), @@ -2148,8 +1998,8 @@ Map _$InlineQueryResultPhotoToJson( final val = { 'id': instance.id, 'type': instance.type, - 'photo_url': instance.photo_url, - 'thumb_url': instance.thumb_url, + 'photo_url': instance.photoUrl, + 'thumbnail_url': instance.thumbnailUrl, }; void writeNotNull(String key, dynamic value) { @@ -2158,53 +2008,54 @@ Map _$InlineQueryResultPhotoToJson( } } - writeNotNull('photo_width', instance.photo_width); - writeNotNull('photo_height', instance.photo_height); + writeNotNull('photo_width', instance.photoWidth); + writeNotNull('photo_height', instance.photoHeight); writeNotNull('title', instance.title); writeNotNull('description', instance.description); writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); + writeNotNull('parse_mode', instance.parseMode); writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); return val; } -InlineQueryResultGif _$InlineQueryResultGifFromJson( +InlineQueryResultVenue _$InlineQueryResultVenueFromJson( Map json) => - InlineQueryResultGif( + InlineQueryResultVenue( id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.GIF, - gif_url: json['gif_url'] as String, - gif_width: json['gif_width'] as int?, - gif_height: json['gif_height'] as int?, - gif_duration: json['gif_duration'] as int?, - thumb_url: json['thumb_url'] as String, - thumb_mime_type: json['thumb_mime_type'] as String?, - title: json['title'] as String?, - caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) - ?.map((e) => MessageEntity.fromJson(e as Map)) - .toList(), - reply_markup: json['reply_markup'] == null + type: json['type'] as String? ?? InlineQueryResult.typeVenue, + latitude: (json['latitude'] as num).toDouble(), + longitude: (json['longitude'] as num).toDouble(), + title: json['title'] as String, + address: json['address'] as String, + foursquareId: json['foursquare_id'] as String?, + foursquareType: json['foursquare_type'] as String?, + googlePlaceId: json['google_place_id'] as String?, + googlePlaceType: json['google_place_type'] as String?, + replyMarkup: json['reply_markup'] == null ? null : InlineKeyboardMarkup.fromJson( json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null + inputMessageContent: json['input_message_content'] == null ? null : InputMessageContent.fromJson( json['input_message_content'] as Map), + thumbnailUrl: json['thumbnail_url'] as String?, + thumbnailWidth: json['thumbnail_width'] as int?, + thumbnailHeight: json['thumbnail_height'] as int?, ); -Map _$InlineQueryResultGifToJson( - InlineQueryResultGif instance) { +Map _$InlineQueryResultVenueToJson( + InlineQueryResultVenue instance) { final val = { 'id': instance.id, 'type': instance.type, - 'gif_url': instance.gif_url, + 'latitude': instance.latitude, + 'longitude': instance.longitude, + 'title': instance.title, + 'address': instance.address, }; void writeNotNull(String key, dynamic value) { @@ -2213,55 +2064,55 @@ Map _$InlineQueryResultGifToJson( } } - writeNotNull('gif_width', instance.gif_width); - writeNotNull('gif_height', instance.gif_height); - writeNotNull('gif_duration', instance.gif_duration); - val['thumb_url'] = instance.thumb_url; - writeNotNull('thumb_mime_type', instance.thumb_mime_type); - writeNotNull('title', instance.title); - writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); - writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); + writeNotNull('foursquare_id', instance.foursquareId); + writeNotNull('foursquare_type', instance.foursquareType); + writeNotNull('google_place_id', instance.googlePlaceId); + writeNotNull('google_place_type', instance.googlePlaceType); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); + writeNotNull('thumbnail_url', instance.thumbnailUrl); + writeNotNull('thumbnail_width', instance.thumbnailWidth); + writeNotNull('thumbnail_height', instance.thumbnailHeight); return val; } -InlineQueryResultMpeg4Gif _$InlineQueryResultMpeg4GifFromJson( +InlineQueryResultVideo _$InlineQueryResultVideoFromJson( Map json) => - InlineQueryResultMpeg4Gif( + InlineQueryResultVideo( id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.MPEG4_GIF, - mpeg4_url: json['mpeg4_url'] as String, - mpeg4_width: json['mpeg4_width'] as int?, - mpeg4_height: json['mpeg4_height'] as int?, - mpeg4_duration: json['mpeg4_duration'] as int?, - thumb_url: json['thumb_url'] as String, - thumb_mime_type: json['thumb_mime_type'] as String?, - title: json['title'] as String?, + type: json['type'] as String? ?? InlineQueryResult.typeVideo, + videoUrl: json['video_url'] as String, + mimeType: json['mime_type'] as String, + thumbnailUrl: json['thumbnail_url'] as String, + title: json['title'] as String, caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) + parseMode: json['parse_mode'] as String?, + videoWidth: json['video_width'] as int?, + videoHeight: json['video_height'] as int?, + videoDuration: json['video_duration'] as int?, + description: json['description'] as String?, + captionEntities: (json['caption_entities'] as List?) ?.map((e) => MessageEntity.fromJson(e as Map)) .toList(), - reply_markup: json['reply_markup'] == null + replyMarkup: json['reply_markup'] == null ? null : InlineKeyboardMarkup.fromJson( json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null + inputMessageContent: json['input_message_content'] == null ? null : InputMessageContent.fromJson( json['input_message_content'] as Map), ); -Map _$InlineQueryResultMpeg4GifToJson( - InlineQueryResultMpeg4Gif instance) { +Map _$InlineQueryResultVideoToJson( + InlineQueryResultVideo instance) { final val = { 'id': instance.id, 'type': instance.type, - 'mpeg4_url': instance.mpeg4_url, + 'video_url': instance.videoUrl, + 'mime_type': instance.mimeType, + 'thumbnail_url': instance.thumbnailUrl, + 'title': instance.title, }; void writeNotNull(String key, dynamic value) { @@ -2270,58 +2121,48 @@ Map _$InlineQueryResultMpeg4GifToJson( } } - writeNotNull('mpeg4_width', instance.mpeg4_width); - writeNotNull('mpeg4_height', instance.mpeg4_height); - writeNotNull('mpeg4_duration', instance.mpeg4_duration); - val['thumb_url'] = instance.thumb_url; - writeNotNull('thumb_mime_type', instance.thumb_mime_type); - writeNotNull('title', instance.title); writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); + writeNotNull('parse_mode', instance.parseMode); + writeNotNull('video_width', instance.videoWidth); + writeNotNull('video_height', instance.videoHeight); + writeNotNull('video_duration', instance.videoDuration); + writeNotNull('description', instance.description); writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); return val; } -InlineQueryResultVideo _$InlineQueryResultVideoFromJson( +InlineQueryResultVoice _$InlineQueryResultVoiceFromJson( Map json) => - InlineQueryResultVideo( + InlineQueryResultVoice( id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.VIDEO, - video_url: json['video_url'] as String, - mime_type: json['mime_type'] as String, - thumb_url: json['thumb_url'] as String, + type: json['type'] as String? ?? InlineQueryResult.typeVoice, + voiceUrl: json['voice_url'] as String, title: json['title'] as String, caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - video_width: json['video_width'] as int?, - video_height: json['video_height'] as int?, - video_duration: json['video_duration'] as int?, - description: json['description'] as String?, - caption_entities: (json['caption_entities'] as List?) + parseMode: json['parse_mode'] as String?, + voiceDuration: json['voice_duration'] as int?, + captionEntities: (json['caption_entities'] as List?) ?.map((e) => MessageEntity.fromJson(e as Map)) .toList(), - reply_markup: json['reply_markup'] == null + replyMarkup: json['reply_markup'] == null ? null : InlineKeyboardMarkup.fromJson( json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null + inputMessageContent: json['input_message_content'] == null ? null : InputMessageContent.fromJson( json['input_message_content'] as Map), ); -Map _$InlineQueryResultVideoToJson( - InlineQueryResultVideo instance) { +Map _$InlineQueryResultVoiceToJson( + InlineQueryResultVoice instance) { final val = { 'id': instance.id, 'type': instance.type, - 'video_url': instance.video_url, - 'mime_type': instance.mime_type, - 'thumb_url': instance.thumb_url, + 'voice_url': instance.voiceUrl, 'title': instance.title, }; @@ -2332,50 +2173,29 @@ Map _$InlineQueryResultVideoToJson( } writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); - writeNotNull('video_width', instance.video_width); - writeNotNull('video_height', instance.video_height); - writeNotNull('video_duration', instance.video_duration); - writeNotNull('description', instance.description); + writeNotNull('parse_mode', instance.parseMode); + writeNotNull('voice_duration', instance.voiceDuration); writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); return val; } -InlineQueryResultAudio _$InlineQueryResultAudioFromJson( - Map json) => - InlineQueryResultAudio( +InlineQueryResult _$InlineQueryResultFromJson(Map json) => + InlineQueryResult( + type: json['type'] as String, id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.AUDIO, - audio_url: json['audio_url'] as String, - title: json['title'] as String, - caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - performer: json['performer'] as String?, - audio_duration: json['audio_duration'] as int?, - caption_entities: (json['caption_entities'] as List?) - ?.map((e) => MessageEntity.fromJson(e as Map)) - .toList(), - reply_markup: json['reply_markup'] == null + replyMarkup: json['reply_markup'] == null ? null : InlineKeyboardMarkup.fromJson( json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null - ? null - : InputMessageContent.fromJson( - json['input_message_content'] as Map), ); -Map _$InlineQueryResultAudioToJson( - InlineQueryResultAudio instance) { +Map _$InlineQueryResultToJson(InlineQueryResult instance) { final val = { - 'id': instance.id, 'type': instance.type, - 'audio_url': instance.audio_url, - 'title': instance.title, + 'id': instance.id, }; void writeNotNull(String key, dynamic value) { @@ -2384,48 +2204,24 @@ Map _$InlineQueryResultAudioToJson( } } - writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); - writeNotNull('performer', instance.performer); - writeNotNull('audio_duration', instance.audio_duration); - writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); return val; } -InlineQueryResultVoice _$InlineQueryResultVoiceFromJson( +InlineQueryResultsButton _$InlineQueryResultsButtonFromJson( Map json) => - InlineQueryResultVoice( - id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.VOICE, - voice_url: json['voice_url'] as String, - title: json['title'] as String, - caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - voice_duration: json['voice_duration'] as int?, - caption_entities: (json['caption_entities'] as List?) - ?.map((e) => MessageEntity.fromJson(e as Map)) - .toList(), - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null + InlineQueryResultsButton( + text: json['text'] as String, + webApp: json['web_app'] == null ? null - : InputMessageContent.fromJson( - json['input_message_content'] as Map), + : WebAppInfo.fromJson(json['web_app'] as Map), + startParameter: json['start_parameter'] as String?, ); -Map _$InlineQueryResultVoiceToJson( - InlineQueryResultVoice instance) { +Map _$InlineQueryResultsButtonToJson( + InlineQueryResultsButton instance) { final val = { - 'id': instance.id, - 'type': instance.type, - 'voice_url': instance.voice_url, - 'title': instance.title, + 'text': instance.text, }; void writeNotNull(String key, dynamic value) { @@ -2434,50 +2230,28 @@ Map _$InlineQueryResultVoiceToJson( } } - writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); - writeNotNull('voice_duration', instance.voice_duration); - writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); + writeNotNull('web_app', instance.webApp?.toJson()); + writeNotNull('start_parameter', instance.startParameter); return val; } -InlineQueryResultDocument _$InlineQueryResultDocumentFromJson( - Map json) => - InlineQueryResultDocument( +InlineQuery _$InlineQueryFromJson(Map json) => InlineQuery( id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.DOCUMENT, - title: json['title'] as String, - caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) - ?.map((e) => MessageEntity.fromJson(e as Map)) - .toList(), - document_url: json['document_url'] as String, - mime_type: json['mime_type'] as String, - description: json['description'] as String?, - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null + from: User.fromJson(json['from'] as Map), + query: json['query'] as String, + offset: json['offset'] as String, + chatType: json['chat_type'] as String?, + location: json['location'] == null ? null - : InputMessageContent.fromJson( - json['input_message_content'] as Map), - thumb_url: json['thumb_url'] as String?, - thumb_width: json['thumb_width'] as int?, - thumb_height: json['thumb_height'] as int?, + : Location.fromJson(json['location'] as Map), ); -Map _$InlineQueryResultDocumentToJson( - InlineQueryResultDocument instance) { +Map _$InlineQueryToJson(InlineQuery instance) { final val = { 'id': instance.id, - 'type': instance.type, - 'title': instance.title, + 'from': instance.from.toJson(), + 'query': instance.query, + 'offset': instance.offset, }; void writeNotNull(String key, dynamic value) { @@ -2486,55 +2260,25 @@ Map _$InlineQueryResultDocumentToJson( } } - writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); - writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - val['document_url'] = instance.document_url; - val['mime_type'] = instance.mime_type; - writeNotNull('description', instance.description); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); - writeNotNull('thumb_url', instance.thumb_url); - writeNotNull('thumb_width', instance.thumb_width); - writeNotNull('thumb_height', instance.thumb_height); + writeNotNull('chat_type', instance.chatType); + writeNotNull('location', instance.location?.toJson()); return val; } -InlineQueryResultLocation _$InlineQueryResultLocationFromJson( +InputContactMessageContent _$InputContactMessageContentFromJson( Map json) => - InlineQueryResultLocation( - id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.LOCATION, - latitude: (json['latitude'] as num).toDouble(), - longitude: (json['longitude'] as num).toDouble(), - title: json['title'] as String, - horizontal_accuracy: (json['horizontal_accuracy'] as num?)?.toDouble(), - live_period: json['live_period'] as int?, - heading: json['heading'] as int?, - proximity_alert_radius: json['proximity_alert_radius'] as int?, - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null - ? null - : InputMessageContent.fromJson( - json['input_message_content'] as Map), - thumb_url: json['thumb_url'] as String?, - thumb_width: json['thumb_width'] as int?, - thumb_height: json['thumb_height'] as int?, + InputContactMessageContent( + phoneNumber: json['phone_number'] as String, + firstName: json['first_name'] as String, + lastName: json['last_name'] as String?, + vcard: json['vcard'] as String?, ); -Map _$InlineQueryResultLocationToJson( - InlineQueryResultLocation instance) { +Map _$InputContactMessageContentToJson( + InputContactMessageContent instance) { final val = { - 'id': instance.id, - 'type': instance.type, - 'latitude': instance.latitude, - 'longitude': instance.longitude, - 'title': instance.title, + 'phone_number': instance.phoneNumber, + 'first_name': instance.firstName, }; void writeNotNull(String key, dynamic value) { @@ -2543,54 +2287,48 @@ Map _$InlineQueryResultLocationToJson( } } - writeNotNull('horizontal_accuracy', instance.horizontal_accuracy); - writeNotNull('live_period', instance.live_period); - writeNotNull('heading', instance.heading); - writeNotNull('proximity_alert_radius', instance.proximity_alert_radius); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); - writeNotNull('thumb_url', instance.thumb_url); - writeNotNull('thumb_width', instance.thumb_width); - writeNotNull('thumb_height', instance.thumb_height); + writeNotNull('last_name', instance.lastName); + writeNotNull('vcard', instance.vcard); return val; } -InlineQueryResultVenue _$InlineQueryResultVenueFromJson( +InputInvoiceMessageContent _$InputInvoiceMessageContentFromJson( Map json) => - InlineQueryResultVenue( - id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.VENUE, - latitude: (json['latitude'] as num).toDouble(), - longitude: (json['longitude'] as num).toDouble(), + InputInvoiceMessageContent( title: json['title'] as String, - address: json['address'] as String, - foursquare_id: json['foursquare_id'] as String?, - foursquare_type: json['foursquare_type'] as String?, - google_place_id: json['google_place_id'] as String?, - google_place_type: json['google_place_type'] as String?, - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null - ? null - : InputMessageContent.fromJson( - json['input_message_content'] as Map), - thumb_url: json['thumb_url'] as String?, - thumb_width: json['thumb_width'] as int?, - thumb_height: json['thumb_height'] as int?, - ); + description: json['description'] as String, + payload: json['payload'] as String, + providerToken: json['provider_token'] as String, + currency: json['currency'] as String, + prices: (json['prices'] as List) + .map((e) => LabeledPrice.fromJson(e as Map)) + .toList(), + maxTipAmount: json['max_tip_amount'] as int?, + suggestedTipAmounts: (json['suggested_tip_amounts'] as List?) + ?.map((e) => e as int) + .toList(), + providerData: json['provider_data'] as String?, + photoSize: json['photo_size'] as int?, + photoWidth: json['photo_width'] as int?, + photoHeight: json['photo_height'] as int?, + needName: json['need_name'] as bool?, + needPhoneNumber: json['need_phone_number'] as bool?, + needEmail: json['need_email'] as bool?, + needShippingAddress: json['need_shipping_address'] as bool?, + sendPhoneNumberToProvider: json['send_phone_number_to_provider'] as bool?, + sendEmailToProvider: json['send_email_to_provider'] as bool?, + isFlexible: json['is_flexible'] as bool?, + )..photoUrl = json['photo_url'] as String?; -Map _$InlineQueryResultVenueToJson( - InlineQueryResultVenue instance) { +Map _$InputInvoiceMessageContentToJson( + InputInvoiceMessageContent instance) { final val = { - 'id': instance.id, - 'type': instance.type, - 'latitude': instance.latitude, - 'longitude': instance.longitude, 'title': instance.title, - 'address': instance.address, + 'description': instance.description, + 'payload': instance.payload, + 'provider_token': instance.providerToken, + 'currency': instance.currency, + 'prices': instance.prices.map((e) => e.toJson()).toList(), }; void writeNotNull(String key, dynamic value) { @@ -2599,48 +2337,40 @@ Map _$InlineQueryResultVenueToJson( } } - writeNotNull('foursquare_id', instance.foursquare_id); - writeNotNull('foursquare_type', instance.foursquare_type); - writeNotNull('google_place_id', instance.google_place_id); - writeNotNull('google_place_type', instance.google_place_type); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); + writeNotNull('max_tip_amount', instance.maxTipAmount); + writeNotNull('suggested_tip_amounts', instance.suggestedTipAmounts); + writeNotNull('provider_data', instance.providerData); + writeNotNull('photo_url', instance.photoUrl); + writeNotNull('photo_size', instance.photoSize); + writeNotNull('photo_width', instance.photoWidth); + writeNotNull('photo_height', instance.photoHeight); + writeNotNull('need_name', instance.needName); + writeNotNull('need_phone_number', instance.needPhoneNumber); + writeNotNull('need_email', instance.needEmail); + writeNotNull('need_shipping_address', instance.needShippingAddress); writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); - writeNotNull('thumb_url', instance.thumb_url); - writeNotNull('thumb_width', instance.thumb_width); - writeNotNull('thumb_height', instance.thumb_height); + 'send_phone_number_to_provider', instance.sendPhoneNumberToProvider); + writeNotNull('send_email_to_provider', instance.sendEmailToProvider); + writeNotNull('is_flexible', instance.isFlexible); return val; } -InlineQueryResultContact _$InlineQueryResultContactFromJson( +InputLocationMessageContent _$InputLocationMessageContentFromJson( Map json) => - InlineQueryResultContact( - id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.CONTACT, - phone_number: json['phone_number'] as String, - first_name: json['first_name'] as String, - last_name: json['last_name'] as String?, - vcard: json['vcard'] as String?, - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null - ? null - : InputMessageContent.fromJson( - json['input_message_content'] as Map), - thumb_url: json['thumb_url'] as String?, - thumb_width: json['thumb_width'] as int?, - thumb_height: json['thumb_height'] as int?, + InputLocationMessageContent( + latitude: (json['latitude'] as num).toDouble(), + longitude: (json['longitude'] as num).toDouble(), + horizontalAccuracy: (json['horizontal_accuracy'] as num?)?.toDouble(), + livePeriod: json['live_period'] as int?, + heading: json['heading'] as int?, + proximityAlertRadius: json['proximity_alert_radius'] as int?, ); -Map _$InlineQueryResultContactToJson( - InlineQueryResultContact instance) { +Map _$InputLocationMessageContentToJson( + InputLocationMessageContent instance) { final val = { - 'id': instance.id, - 'type': instance.type, - 'phone_number': instance.phone_number, - 'first_name': instance.first_name, + 'latitude': instance.latitude, + 'longitude': instance.longitude, }; void writeNotNull(String key, dynamic value) { @@ -2649,35 +2379,33 @@ Map _$InlineQueryResultContactToJson( } } - writeNotNull('last_name', instance.last_name); - writeNotNull('vcard', instance.vcard); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); - writeNotNull('thumb_url', instance.thumb_url); - writeNotNull('thumb_width', instance.thumb_width); - writeNotNull('thumb_height', instance.thumb_height); + writeNotNull('horizontal_accuracy', instance.horizontalAccuracy); + writeNotNull('live_period', instance.livePeriod); + writeNotNull('heading', instance.heading); + writeNotNull('proximity_alert_radius', instance.proximityAlertRadius); return val; } -InlineQueryResultGame _$InlineQueryResultGameFromJson( - Map json) => - InlineQueryResultGame( - id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.GAME, - game_short_name: json['game_short_name'] as String, - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), +InputMediaAnimation _$InputMediaAnimationFromJson(Map json) => + InputMediaAnimation( + type: json['type'] as String? ?? InputMedia.typeAnimation, + media: json['media'] as String, + thumbnail: json['thumbnail'] as String?, + caption: json['caption'] as String?, + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) + ?.map((e) => MessageEntity.fromJson(e as Map)) + .toList(), + width: json['width'] as int?, + height: json['height'] as int?, + duration: json['duration'] as int?, + hasSpoiler: json['has_spoiler'] as bool?, ); -Map _$InlineQueryResultGameToJson( - InlineQueryResultGame instance) { +Map _$InputMediaAnimationToJson(InputMediaAnimation instance) { final val = { - 'id': instance.id, 'type': instance.type, - 'game_short_name': instance.game_short_name, + 'media': instance.media, }; void writeNotNull(String key, dynamic value) { @@ -2686,39 +2414,37 @@ Map _$InlineQueryResultGameToJson( } } - writeNotNull('reply_markup', instance.reply_markup?.toJson()); + writeNotNull('caption', instance.caption); + writeNotNull('parse_mode', instance.parseMode); + writeNotNull('caption_entities', + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('thumbnail', instance.thumbnail); + writeNotNull('width', instance.width); + writeNotNull('height', instance.height); + writeNotNull('duration', instance.duration); + writeNotNull('has_spoiler', instance.hasSpoiler); return val; } -InlineQueryResultCachedPhoto _$InlineQueryResultCachedPhotoFromJson( - Map json) => - InlineQueryResultCachedPhoto( - id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.PHOTO, - photo_file_id: json['photo_file_id'] as String, - title: json['title'] as String?, - description: json['description'] as String?, +InputMediaAudio _$InputMediaAudioFromJson(Map json) => + InputMediaAudio( + type: json['type'] as String? ?? InputMedia.typeAudio, + media: json['media'] as String, + thumbnail: json['thumbnail'] as String?, caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) ?.map((e) => MessageEntity.fromJson(e as Map)) .toList(), - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null - ? null - : InputMessageContent.fromJson( - json['input_message_content'] as Map), + duration: json['duration'] as int?, + performer: json['performer'] as String?, + title: json['title'] as String?, ); -Map _$InlineQueryResultCachedPhotoToJson( - InlineQueryResultCachedPhoto instance) { +Map _$InputMediaAudioToJson(InputMediaAudio instance) { final val = { - 'id': instance.id, 'type': instance.type, - 'photo_file_id': instance.photo_file_id, + 'media': instance.media, }; void writeNotNull(String key, dynamic value) { @@ -2727,46 +2453,35 @@ Map _$InlineQueryResultCachedPhotoToJson( } } - writeNotNull('title', instance.title); - writeNotNull('description', instance.description); writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); + writeNotNull('parse_mode', instance.parseMode); writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('thumbnail', instance.thumbnail); + writeNotNull('duration', instance.duration); + writeNotNull('performer', instance.performer); + writeNotNull('title', instance.title); return val; } -InlineQueryResultCachedGif _$InlineQueryResultCachedGifFromJson( - Map json) => - InlineQueryResultCachedGif( - id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.GIF, - gif_file_id: json['gif_file_id'] as String, - title: json['title'] as String?, +InputMediaDocument _$InputMediaDocumentFromJson(Map json) => + InputMediaDocument( + type: json['type'] as String? ?? InputMedia.typeDocument, + media: json['media'] as String, + thumbnail: json['thumbnail'] as String?, caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) ?.map((e) => MessageEntity.fromJson(e as Map)) .toList(), - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null - ? null - : InputMessageContent.fromJson( - json['input_message_content'] as Map), + disableContentTypeDetection: + json['disable_content_type_detection'] as bool?, ); -Map _$InlineQueryResultCachedGifToJson( - InlineQueryResultCachedGif instance) { +Map _$InputMediaDocumentToJson(InputMediaDocument instance) { final val = { - 'id': instance.id, 'type': instance.type, - 'gif_file_id': instance.gif_file_id, + 'media': instance.media, }; void writeNotNull(String key, dynamic value) { @@ -2775,45 +2490,32 @@ Map _$InlineQueryResultCachedGifToJson( } } - writeNotNull('title', instance.title); writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); + writeNotNull('parse_mode', instance.parseMode); writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('thumbnail', instance.thumbnail); writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); + 'disable_content_type_detection', instance.disableContentTypeDetection); return val; } -InlineQueryResultCachedMpeg4Gif _$InlineQueryResultCachedMpeg4GifFromJson( - Map json) => - InlineQueryResultCachedMpeg4Gif( - id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.MPEG4_GIF, - mpeg4_file_id: json['mpeg4_file_id'] as String, - title: json['title'] as String?, +InputMediaPhoto _$InputMediaPhotoFromJson(Map json) => + InputMediaPhoto( + type: json['type'] as String? ?? InputMedia.typePhoto, + media: json['media'] as String, caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) ?.map((e) => MessageEntity.fromJson(e as Map)) .toList(), - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null - ? null - : InputMessageContent.fromJson( - json['input_message_content'] as Map), + hasSpoiler: json['has_spoiler'] as bool?, ); -Map _$InlineQueryResultCachedMpeg4GifToJson( - InlineQueryResultCachedMpeg4Gif instance) { +Map _$InputMediaPhotoToJson(InputMediaPhoto instance) { final val = { - 'id': instance.id, 'type': instance.type, - 'mpeg4_file_id': instance.mpeg4_file_id, + 'media': instance.media, }; void writeNotNull(String key, dynamic value) { @@ -2822,38 +2524,35 @@ Map _$InlineQueryResultCachedMpeg4GifToJson( } } - writeNotNull('title', instance.title); writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); + writeNotNull('parse_mode', instance.parseMode); writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('has_spoiler', instance.hasSpoiler); return val; } -InlineQueryResultCachedSticker _$InlineQueryResultCachedStickerFromJson( - Map json) => - InlineQueryResultCachedSticker( - id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.STICKER, - sticker_file_id: json['sticker_file_id'] as String?, - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null - ? null - : InputMessageContent.fromJson( - json['input_message_content'] as Map), +InputMediaVideo _$InputMediaVideoFromJson(Map json) => + InputMediaVideo( + type: json['type'] as String? ?? InputMedia.typeVideo, + media: json['media'] as String, + caption: json['caption'] as String?, + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) + ?.map((e) => MessageEntity.fromJson(e as Map)) + .toList(), + thumbnail: json['thumbnail'] as String?, + width: json['width'] as int?, + height: json['height'] as int?, + duration: json['duration'] as int?, + supportsStreaming: json['supports_streaming'] as bool?, + hasSpoiler: json['has_spoiler'] as bool?, ); -Map _$InlineQueryResultCachedStickerToJson( - InlineQueryResultCachedSticker instance) { +Map _$InputMediaVideoToJson(InputMediaVideo instance) { final val = { - 'id': instance.id, 'type': instance.type, + 'media': instance.media, }; void writeNotNull(String key, dynamic value) { @@ -2862,43 +2561,37 @@ Map _$InlineQueryResultCachedStickerToJson( } } - writeNotNull('sticker_file_id', instance.sticker_file_id); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); + writeNotNull('caption', instance.caption); + writeNotNull('parse_mode', instance.parseMode); + writeNotNull('caption_entities', + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('thumbnail', instance.thumbnail); + writeNotNull('width', instance.width); + writeNotNull('height', instance.height); + writeNotNull('duration', instance.duration); + writeNotNull('supports_streaming', instance.supportsStreaming); + writeNotNull('has_spoiler', instance.hasSpoiler); return val; } -InlineQueryResultCachedDocument _$InlineQueryResultCachedDocumentFromJson( +InputMediaWithThumbnail _$InputMediaWithThumbnailFromJson( Map json) => - InlineQueryResultCachedDocument( - id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.DOCUMENT, - title: json['title'] as String, - document_file_id: json['document_file_id'] as String, - description: json['description'] as String?, + InputMediaWithThumbnail( + type: json['type'] as String, + media: json['media'] as String, + thumbnail: json['thumbnail'] as String?, caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) ?.map((e) => MessageEntity.fromJson(e as Map)) .toList(), - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null - ? null - : InputMessageContent.fromJson( - json['input_message_content'] as Map), ); -Map _$InlineQueryResultCachedDocumentToJson( - InlineQueryResultCachedDocument instance) { +Map _$InputMediaWithThumbnailToJson( + InputMediaWithThumbnail instance) { final val = { - 'id': instance.id, 'type': instance.type, - 'title': instance.title, - 'document_file_id': instance.document_file_id, + 'media': instance.media, }; void writeNotNull(String key, dynamic value) { @@ -2907,47 +2600,28 @@ Map _$InlineQueryResultCachedDocumentToJson( } } - writeNotNull('description', instance.description); writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); + writeNotNull('parse_mode', instance.parseMode); writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('thumbnail', instance.thumbnail); return val; } -InlineQueryResultCachedVideo _$InlineQueryResultCachedVideoFromJson( - Map json) => - InlineQueryResultCachedVideo( - id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.VIDEO, - video_file_id: json['video_file_id'] as String, - title: json['title'] as String, - description: json['description'] as String?, +InputMedia _$InputMediaFromJson(Map json) => InputMedia( + type: json['type'] as String, + media: json['media'] as String, caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) + parseMode: json['parse_mode'] as String?, + captionEntities: (json['caption_entities'] as List?) ?.map((e) => MessageEntity.fromJson(e as Map)) .toList(), - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null - ? null - : InputMessageContent.fromJson( - json['input_message_content'] as Map), ); -Map _$InlineQueryResultCachedVideoToJson( - InlineQueryResultCachedVideo instance) { +Map _$InputMediaToJson(InputMedia instance) { final val = { - 'id': instance.id, 'type': instance.type, - 'video_file_id': instance.video_file_id, - 'title': instance.title, + 'media': instance.media, }; void writeNotNull(String key, dynamic value) { @@ -2956,46 +2630,38 @@ Map _$InlineQueryResultCachedVideoToJson( } } - writeNotNull('description', instance.description); writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); + writeNotNull('parse_mode', instance.parseMode); writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); + instance.captionEntities?.map((e) => e.toJson()).toList()); return val; } -InlineQueryResultCachedVoice _$InlineQueryResultCachedVoiceFromJson( - Map json) => - InlineQueryResultCachedVoice( - id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.VOICE, - voice_file_id: json['voice_file_id'] as String, - title: json['title'] as String, - caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) - ?.map((e) => MessageEntity.fromJson(e as Map)) +InputMessageContent _$InputMessageContentFromJson(Map json) => + InputMessageContent(); + +Map _$InputMessageContentToJson( + InputMessageContent instance) => + {}; + +InputSticker _$InputStickerFromJson(Map json) => InputSticker( + sticker: json['sticker'] as String, + emojiList: (json['emoji_list'] as List) + .map((e) => e as String) .toList(), - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null + maskPosition: json['mask_position'] == null ? null - : InputMessageContent.fromJson( - json['input_message_content'] as Map), + : MaskPosition.fromJson( + json['mask_position'] as Map), + keywords: (json['keywords'] as List?) + ?.map((e) => e as String) + .toList(), ); -Map _$InlineQueryResultCachedVoiceToJson( - InlineQueryResultCachedVoice instance) { +Map _$InputStickerToJson(InputSticker instance) { final val = { - 'id': instance.id, - 'type': instance.type, - 'voice_file_id': instance.voice_file_id, - 'title': instance.title, + 'sticker': instance.sticker, + 'emoji_list': instance.emojiList, }; void writeNotNull(String key, dynamic value) { @@ -3004,74 +2670,17 @@ Map _$InlineQueryResultCachedVoiceToJson( } } - writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); - writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); - return val; -} - -InlineQueryResultCachedAudio _$InlineQueryResultCachedAudioFromJson( - Map json) => - InlineQueryResultCachedAudio( - id: json['id'] as String, - type: json['type'] as String? ?? InlineQueryResult.AUDIO, - audio_file_id: json['audio_file_id'] as String, - caption: json['caption'] as String?, - parse_mode: json['parse_mode'] as String?, - caption_entities: (json['caption_entities'] as List?) - ?.map((e) => MessageEntity.fromJson(e as Map)) - .toList(), - reply_markup: json['reply_markup'] == null - ? null - : InlineKeyboardMarkup.fromJson( - json['reply_markup'] as Map), - input_message_content: json['input_message_content'] == null - ? null - : InputMessageContent.fromJson( - json['input_message_content'] as Map), - ); - -Map _$InlineQueryResultCachedAudioToJson( - InlineQueryResultCachedAudio instance) { - final val = { - 'id': instance.id, - 'type': instance.type, - 'audio_file_id': instance.audio_file_id, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('caption', instance.caption); - writeNotNull('parse_mode', instance.parse_mode); - writeNotNull('caption_entities', - instance.caption_entities?.map((e) => e.toJson()).toList()); - writeNotNull('reply_markup', instance.reply_markup?.toJson()); - writeNotNull( - 'input_message_content', instance.input_message_content?.toJson()); + writeNotNull('mask_position', instance.maskPosition?.toJson()); + writeNotNull('keywords', instance.keywords); return val; } -InputMessageContent _$InputMessageContentFromJson(Map json) => - InputMessageContent(); - -Map _$InputMessageContentToJson( - InputMessageContent instance) => - {}; - InputTextMessageContent _$InputTextMessageContentFromJson( Map json) => InputTextMessageContent( - message_text: json['message_text'] as String, - parse_mode: json['parse_mode'] as String?, - disable_web_page_preview: json['disable_web_page_preview'] as bool?, + messageText: json['message_text'] as String, + parseMode: json['parse_mode'] as String?, + disableWebPagePreview: json['disable_web_page_preview'] as bool?, )..entities = (json['entities'] as List?) ?.map((e) => MessageEntity.fromJson(e as Map)) .toList(); @@ -3079,7 +2688,7 @@ InputTextMessageContent _$InputTextMessageContentFromJson( Map _$InputTextMessageContentToJson( InputTextMessageContent instance) { final val = { - 'message_text': instance.message_text, + 'message_text': instance.messageText, }; void writeNotNull(String key, dynamic value) { @@ -3088,28 +2697,32 @@ Map _$InputTextMessageContentToJson( } } - writeNotNull('parse_mode', instance.parse_mode); + writeNotNull('parse_mode', instance.parseMode); writeNotNull('entities', instance.entities?.map((e) => e.toJson()).toList()); - writeNotNull('disable_web_page_preview', instance.disable_web_page_preview); + writeNotNull('disable_web_page_preview', instance.disableWebPagePreview); return val; } -InputLocationMessageContent _$InputLocationMessageContentFromJson( +InputVenueMessageContent _$InputVenueMessageContentFromJson( Map json) => - InputLocationMessageContent( + InputVenueMessageContent( latitude: (json['latitude'] as num).toDouble(), longitude: (json['longitude'] as num).toDouble(), - horizontal_accuracy: (json['horizontal_accuracy'] as num?)?.toDouble(), - live_period: json['live_period'] as int?, - heading: json['heading'] as int?, - proximity_alert_radius: json['proximity_alert_radius'] as int?, + title: json['title'] as String, + address: json['address'] as String, + foursquareId: json['foursquare_id'] as String?, + foursquareType: json['foursquare_type'] as String?, + googlePlaceId: json['google_place_id'] as String?, + googlePlaceType: json['google_place_type'] as String?, ); -Map _$InputLocationMessageContentToJson( - InputLocationMessageContent instance) { +Map _$InputVenueMessageContentToJson( + InputVenueMessageContent instance) { final val = { 'latitude': instance.latitude, 'longitude': instance.longitude, + 'title': instance.title, + 'address': instance.address, }; void writeNotNull(String key, dynamic value) { @@ -3118,34 +2731,38 @@ Map _$InputLocationMessageContentToJson( } } - writeNotNull('horizontal_accuracy', instance.horizontal_accuracy); - writeNotNull('live_period', instance.live_period); - writeNotNull('heading', instance.heading); - writeNotNull('proximity_alert_radius', instance.proximity_alert_radius); + writeNotNull('foursquare_id', instance.foursquareId); + writeNotNull('foursquare_type', instance.foursquareType); + writeNotNull('google_place_id', instance.googlePlaceId); + writeNotNull('google_place_type', instance.googlePlaceType); return val; } -InputVenueMessageContent _$InputVenueMessageContentFromJson( - Map json) => - InputVenueMessageContent( - latitude: (json['latitude'] as num).toDouble(), - longitude: (json['longitude'] as num).toDouble(), +Invoice _$InvoiceFromJson(Map json) => Invoice( title: json['title'] as String, - address: json['address'] as String, - foursquare_id: json['foursquare_id'] as String?, - foursquare_type: json['foursquare_type'] as String?, - google_place_id: json['google_place_id'] as String?, - google_place_type: json['google_place_type'] as String?, + description: json['description'] as String, + startParameter: json['start_parameter'] as String, + currency: json['currency'] as String, + totalAmount: json['total_amount'] as int, ); -Map _$InputVenueMessageContentToJson( - InputVenueMessageContent instance) { - final val = { - 'latitude': instance.latitude, - 'longitude': instance.longitude, - 'title': instance.title, - 'address': instance.address, - }; +Map _$InvoiceToJson(Invoice instance) => { + 'title': instance.title, + 'description': instance.description, + 'start_parameter': instance.startParameter, + 'currency': instance.currency, + 'total_amount': instance.totalAmount, + }; + +KeyboardButtonPollType _$KeyboardButtonPollTypeFromJson( + Map json) => + KeyboardButtonPollType( + type: json['type'] as String?, + ); + +Map _$KeyboardButtonPollTypeToJson( + KeyboardButtonPollType instance) { + final val = {}; void writeNotNull(String key, dynamic value) { if (value != null) { @@ -3153,27 +2770,34 @@ Map _$InputVenueMessageContentToJson( } } - writeNotNull('foursquare_id', instance.foursquare_id); - writeNotNull('foursquare_type', instance.foursquare_type); - writeNotNull('google_place_id', instance.google_place_id); - writeNotNull('google_place_type', instance.google_place_type); + writeNotNull('type', instance.type); return val; } -InputContactMessageContent _$InputContactMessageContentFromJson( +KeyboardButtonRequestChat _$KeyboardButtonRequestChatFromJson( Map json) => - InputContactMessageContent( - phone_number: json['phone_number'] as String, - first_name: json['first_name'] as String, - last_name: json['last_name'] as String?, - vcard: json['vcard'] as String?, + KeyboardButtonRequestChat( + requestId: json['request_id'] as int, + chatIsChannel: json['chat_is_channel'] as bool, + charIsForum: json['char_is_forum'] as bool?, + chatHasUsername: json['chat_has_username'] as bool?, + chatIsCreated: json['chat_is_created'] as bool?, + userAdministratorRights: json['user_administrator_rights'] == null + ? null + : ChatAdministratorRights.fromJson( + json['user_administrator_rights'] as Map), + botAdministratorRights: json['bot_administrator_rights'] == null + ? null + : ChatAdministratorRights.fromJson( + json['bot_administrator_rights'] as Map), + botIsMember: json['bot_is_member'] as bool?, ); -Map _$InputContactMessageContentToJson( - InputContactMessageContent instance) { +Map _$KeyboardButtonRequestChatToJson( + KeyboardButtonRequestChat instance) { final val = { - 'phone_number': instance.phone_number, - 'first_name': instance.first_name, + 'request_id': instance.requestId, + 'chat_is_channel': instance.chatIsChannel, }; void writeNotNull(String key, dynamic value) { @@ -3182,49 +2806,29 @@ Map _$InputContactMessageContentToJson( } } - writeNotNull('last_name', instance.last_name); - writeNotNull('vcard', instance.vcard); + writeNotNull('char_is_forum', instance.charIsForum); + writeNotNull('chat_has_username', instance.chatHasUsername); + writeNotNull('chat_is_created', instance.chatIsCreated); + writeNotNull( + 'user_administrator_rights', instance.userAdministratorRights?.toJson()); + writeNotNull( + 'bot_administrator_rights', instance.botAdministratorRights?.toJson()); + writeNotNull('bot_is_member', instance.botIsMember); return val; } -InputInvoiceMessageContent _$InputInvoiceMessageContentFromJson( +KeyboardButtonRequestUser _$KeyboardButtonRequestUserFromJson( Map json) => - InputInvoiceMessageContent( - title: json['title'] as String, - description: json['description'] as String, - payload: json['payload'] as String, - provider_token: json['provider_token'] as String, - currency: json['currency'] as String, - prices: (json['prices'] as List) - .map((e) => LabeledPrice.fromJson(e as Map)) - .toList(), - max_tip_amount: json['max_tip_amount'] as int?, - suggested_tip_amounts: (json['suggested_tip_amounts'] as List?) - ?.map((e) => e as int) - .toList(), - provider_data: json['provider_data'] as String?, - photo_size: json['photo_size'] as int?, - photo_width: json['photo_width'] as int?, - photo_height: json['photo_height'] as int?, - need_name: json['need_name'] as bool?, - need_phone_number: json['need_phone_number'] as bool?, - need_email: json['need_email'] as bool?, - need_shipping_address: json['need_shipping_address'] as bool?, - send_phone_number_to_provider: - json['send_phone_number_to_provider'] as bool?, - send_email_to_provider: json['send_email_to_provider'] as bool?, - is_flexible: json['is_flexible'] as bool?, - )..photo_url = json['photo_url'] as String?; + KeyboardButtonRequestUser( + requestId: json['request_id'] as int, + userIsBot: json['user_is_bot'] as bool?, + userIsPremium: json['user_is_premium'] as bool?, + ); -Map _$InputInvoiceMessageContentToJson( - InputInvoiceMessageContent instance) { +Map _$KeyboardButtonRequestUserToJson( + KeyboardButtonRequestUser instance) { final val = { - 'title': instance.title, - 'description': instance.description, - 'payload': instance.payload, - 'provider_token': instance.provider_token, - 'currency': instance.currency, - 'prices': instance.prices.map((e) => e.toJson()).toList(), + 'request_id': instance.requestId, }; void writeNotNull(String key, dynamic value) { @@ -3233,39 +2837,35 @@ Map _$InputInvoiceMessageContentToJson( } } - writeNotNull('max_tip_amount', instance.max_tip_amount); - writeNotNull('suggested_tip_amounts', instance.suggested_tip_amounts); - writeNotNull('provider_data', instance.provider_data); - writeNotNull('photo_url', instance.photo_url); - writeNotNull('photo_size', instance.photo_size); - writeNotNull('photo_width', instance.photo_width); - writeNotNull('photo_height', instance.photo_height); - writeNotNull('need_name', instance.need_name); - writeNotNull('need_phone_number', instance.need_phone_number); - writeNotNull('need_email', instance.need_email); - writeNotNull('need_shipping_address', instance.need_shipping_address); - writeNotNull( - 'send_phone_number_to_provider', instance.send_phone_number_to_provider); - writeNotNull('send_email_to_provider', instance.send_email_to_provider); - writeNotNull('is_flexible', instance.is_flexible); + writeNotNull('user_is_bot', instance.userIsBot); + writeNotNull('user_is_premium', instance.userIsPremium); return val; } -ChosenInlineResult _$ChosenInlineResultFromJson(Map json) => - ChosenInlineResult( - result_id: json['result_id'] as String, - from: User.fromJson(json['from'] as Map), - location: json['location'] == null +KeyboardButton _$KeyboardButtonFromJson(Map json) => + KeyboardButton( + text: json['text'] as String, + requestUser: json['request_user'] == null ? null - : Location.fromJson(json['location'] as Map), - inline_message_id: json['inline_message_id'] as String?, - query: json['query'] as String, - ); + : KeyboardButtonRequestUser.fromJson( + json['request_user'] as Map), + requestContact: json['request_contact'] as bool?, + requestLocation: json['request_location'] as bool?, + requestPoll: json['request_poll'] == null + ? null + : KeyboardButtonPollType.fromJson( + json['request_poll'] as Map), + webApp: json['web_app'] == null + ? null + : WebAppInfo.fromJson(json['web_app'] as Map), + )..requestChat = json['request_chat'] == null + ? null + : KeyboardButtonRequestChat.fromJson( + json['request_chat'] as Map); -Map _$ChosenInlineResultToJson(ChosenInlineResult instance) { +Map _$KeyboardButtonToJson(KeyboardButton instance) { final val = { - 'result_id': instance.result_id, - 'from': instance.from.toJson(), + 'text': instance.text, }; void writeNotNull(String key, dynamic value) { @@ -3274,9 +2874,12 @@ Map _$ChosenInlineResultToJson(ChosenInlineResult instance) { } } - writeNotNull('location', instance.location?.toJson()); - writeNotNull('inline_message_id', instance.inline_message_id); - val['query'] = instance.query; + writeNotNull('request_user', instance.requestUser?.toJson()); + writeNotNull('request_chat', instance.requestChat?.toJson()); + writeNotNull('request_contact', instance.requestContact); + writeNotNull('request_location', instance.requestLocation); + writeNotNull('request_poll', instance.requestPoll?.toJson()); + writeNotNull('web_app', instance.webApp?.toJson()); return val; } @@ -3291,54 +2894,20 @@ Map _$LabeledPriceToJson(LabeledPrice instance) => 'amount': instance.amount, }; -Invoice _$InvoiceFromJson(Map json) => Invoice( - title: json['title'] as String, - description: json['description'] as String, - start_parameter: json['start_parameter'] as String, - currency: json['currency'] as String, - total_amount: json['total_amount'] as int, - ); - -Map _$InvoiceToJson(Invoice instance) => { - 'title': instance.title, - 'description': instance.description, - 'start_parameter': instance.start_parameter, - 'currency': instance.currency, - 'total_amount': instance.total_amount, - }; - -ShippingAddress _$ShippingAddressFromJson(Map json) => - ShippingAddress( - country_code: json['country_code'] as String, - state: json['state'] as String, - city: json['city'] as String, - street_line1: json['street_line1'] as String, - street_line2: json['street_line2'] as String, - post_code: json['post_code'] as String, - ); - -Map _$ShippingAddressToJson(ShippingAddress instance) => - { - 'country_code': instance.country_code, - 'state': instance.state, - 'city': instance.city, - 'street_line1': instance.street_line1, - 'street_line2': instance.street_line2, - 'post_code': instance.post_code, - }; - -OrderInfo _$OrderInfoFromJson(Map json) => OrderInfo( - name: json['name'] as String?, - phone_number: json['phone_number'] as String?, - email: json['email'] as String?, - shippingAddress: json['shippingAddress'] == null - ? null - : ShippingAddress.fromJson( - json['shippingAddress'] as Map), +Location _$LocationFromJson(Map json) => Location( + longitude: (json['longitude'] as num).toDouble(), + latitude: (json['latitude'] as num).toDouble(), + horizontalAccuracy: (json['horizontal_accuracy'] as num?)?.toDouble(), + livePeriod: json['live_period'] as int?, + heading: json['heading'] as int?, + proximityAlertRadius: json['proximity_alert_radius'] as int?, ); -Map _$OrderInfoToJson(OrderInfo instance) { - final val = {}; +Map _$LocationToJson(Location instance) { + final val = { + 'longitude': instance.longitude, + 'latitude': instance.latitude, + }; void writeNotNull(String key, dynamic value) { if (value != null) { @@ -3346,47 +2915,23 @@ Map _$OrderInfoToJson(OrderInfo instance) { } } - writeNotNull('name', instance.name); - writeNotNull('phone_number', instance.phone_number); - writeNotNull('email', instance.email); - writeNotNull('shippingAddress', instance.shippingAddress?.toJson()); + writeNotNull('horizontal_accuracy', instance.horizontalAccuracy); + writeNotNull('live_period', instance.livePeriod); + writeNotNull('heading', instance.heading); + writeNotNull('proximity_alert_radius', instance.proximityAlertRadius); return val; } -ShippingOption _$ShippingOptionFromJson(Map json) => - ShippingOption( - id: json['id'] as String, - title: json['title'] as String, - prices: (json['prices'] as List) - .map((e) => LabeledPrice.fromJson(e as Map)) - .toList(), - ); - -Map _$ShippingOptionToJson(ShippingOption instance) => - { - 'id': instance.id, - 'title': instance.title, - 'prices': instance.prices.map((e) => e.toJson()).toList(), - }; - -SuccessfulPayment _$SuccessfulPaymentFromJson(Map json) => - SuccessfulPayment( - currency: json['currency'] as String, - total_amount: json['total_amount'] as int, - invoice_payload: json['invoice_payload'] as String, - shipping_option_id: json['shipping_option_id'] as String?, - order_info: json['order_info'] == null - ? null - : OrderInfo.fromJson(json['order_info'] as Map), - telegram_payment_charge_id: json['telegram_payment_charge_id'] as String, - provider_payment_charge_id: json['provider_payment_charge_id'] as String, +LoginUrl _$LoginUrlFromJson(Map json) => LoginUrl( + url: json['url'] as String, + forwardText: json['forward_text'] as String?, + botUsername: json['bot_username'] as String?, + requestWriteAccess: json['request_write_access'] as bool?, ); -Map _$SuccessfulPaymentToJson(SuccessfulPayment instance) { +Map _$LoginUrlToJson(LoginUrl instance) { final val = { - 'currency': instance.currency, - 'total_amount': instance.total_amount, - 'invoice_payload': instance.invoice_payload, + 'url': instance.url, }; void writeNotNull(String key, dynamic value) { @@ -3395,122 +2940,1395 @@ Map _$SuccessfulPaymentToJson(SuccessfulPayment instance) { } } - writeNotNull('shipping_option_id', instance.shipping_option_id); - writeNotNull('order_info', instance.order_info?.toJson()); - val['telegram_payment_charge_id'] = instance.telegram_payment_charge_id; - val['provider_payment_charge_id'] = instance.provider_payment_charge_id; + writeNotNull('forward_text', instance.forwardText); + writeNotNull('bot_username', instance.botUsername); + writeNotNull('request_write_access', instance.requestWriteAccess); return val; } -ShippingQuery _$ShippingQueryFromJson(Map json) => - ShippingQuery( - id: json['id'] as String, - from: User.fromJson(json['from'] as Map), - invoice_payload: json['invoice_payload'] as String, - shipping_address: ShippingAddress.fromJson( - json['shipping_address'] as Map), +MaskPosition _$MaskPositionFromJson(Map json) => MaskPosition( + point: json['point'] as String, + xShift: (json['x_shift'] as num).toDouble(), + yShift: (json['y_shift'] as num).toDouble(), + scale: (json['scale'] as num).toDouble(), ); -Map _$ShippingQueryToJson(ShippingQuery instance) => +Map _$MaskPositionToJson(MaskPosition instance) => { - 'id': instance.id, - 'from': instance.from.toJson(), - 'invoice_payload': instance.invoice_payload, - 'shipping_address': instance.shipping_address.toJson(), + 'point': instance.point, + 'x_shift': instance.xShift, + 'y_shift': instance.yShift, + 'scale': instance.scale, }; -PreCheckoutQuery _$PreCheckoutQueryFromJson(Map json) => - PreCheckoutQuery( - id: json['id'] as String, - from: User.fromJson(json['from'] as Map), - currency: json['currency'] as String, - total_amount: json['total_amount'] as int, - invoice_payload: json['invoice_payload'] as String, - shipping_option_id: json['shipping_option_id'] as String?, - order_info: json['order_info'] == null - ? null - : OrderInfo.fromJson(json['order_info'] as Map), +MenuButtonCommands _$MenuButtonCommandsFromJson(Map json) => + MenuButtonCommands( + type: json['type'] as String? ?? MenuButton.typeCommands, ); -Map _$PreCheckoutQueryToJson(PreCheckoutQuery instance) { - final val = { - 'id': instance.id, - 'from': instance.from.toJson(), - 'currency': instance.currency, - 'total_amount': instance.total_amount, - 'invoice_payload': instance.invoice_payload, - }; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('shipping_option_id', instance.shipping_option_id); - writeNotNull('order_info', instance.order_info?.toJson()); - return val; -} +Map _$MenuButtonCommandsToJson(MenuButtonCommands instance) => + { + 'type': instance.type, + }; -PassportData _$PassportDataFromJson(Map json) => PassportData( - data: (json['data'] as List) - .map((e) => - EncryptedPassportElement.fromJson(e as Map)) - .toList(), - credentials: EncryptedCredentials.fromJson( - json['credentials'] as Map), +MenuButtonDefault _$MenuButtonDefaultFromJson(Map json) => + MenuButtonDefault( + type: json['type'] as String? ?? MenuButton.typeDefault, ); -Map _$PassportDataToJson(PassportData instance) => +Map _$MenuButtonDefaultToJson(MenuButtonDefault instance) => { - 'data': instance.data.map((e) => e.toJson()).toList(), - 'credentials': instance.credentials.toJson(), + 'type': instance.type, }; -PassportFile _$PassportFileFromJson(Map json) => PassportFile( - file_id: json['file_id'] as String, - file_unique_id: json['file_unique_id'] as String, - file_size: json['file_size'] as int, - file_date: json['file_date'] as int, +MenuButtonWebApp _$MenuButtonWebAppFromJson(Map json) => + MenuButtonWebApp( + type: json['type'] as String? ?? MenuButton.typeWebApp, + text: json['text'] as String, + webApp: WebAppInfo.fromJson(json['web_app'] as Map), ); -Map _$PassportFileToJson(PassportFile instance) => +Map _$MenuButtonWebAppToJson(MenuButtonWebApp instance) => { - 'file_id': instance.file_id, - 'file_unique_id': instance.file_unique_id, - 'file_size': instance.file_size, - 'file_date': instance.file_date, + 'type': instance.type, + 'text': instance.text, + 'web_app': instance.webApp.toJson(), }; -EncryptedPassportElement _$EncryptedPassportElementFromJson( +MenuButton _$MenuButtonFromJson(Map json) => MenuButton( + type: json['type'] as String, + ); + +Map _$MenuButtonToJson(MenuButton instance) => + { + 'type': instance.type, + }; + +MessageAutoDeleteTimerChanged _$MessageAutoDeleteTimerChangedFromJson( Map json) => - EncryptedPassportElement( + MessageAutoDeleteTimerChanged( + messageAutoDeleteTime: json['message_auto_delete_time'] as int, + ); + +Map _$MessageAutoDeleteTimerChangedToJson( + MessageAutoDeleteTimerChanged instance) => + { + 'message_auto_delete_time': instance.messageAutoDeleteTime, + }; + +MessageEntity _$MessageEntityFromJson(Map json) => + MessageEntity( type: json['type'] as String, - data: json['data'] as String?, - phone_number: json['phone_number'] as String?, - email: json['email'] as String?, - files: (json['files'] as List?) - ?.map((e) => PassportFile.fromJson(e as Map)) + offset: json['offset'] as int, + length: json['length'] as int, + url: json['url'] as String?, + user: json['user'] == null + ? null + : User.fromJson(json['user'] as Map), + language: json['language'] as String?, + customEmojiId: json['custom_emoji_id'] as String?, + ); + +Map _$MessageEntityToJson(MessageEntity instance) { + final val = { + 'type': instance.type, + 'offset': instance.offset, + 'length': instance.length, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('url', instance.url); + writeNotNull('user', instance.user?.toJson()); + writeNotNull('language', instance.language); + writeNotNull('custom_emoji_id', instance.customEmojiId); + return val; +} + +MessageId _$MessageIdFromJson(Map json) => MessageId( + messageId: json['message_id'] as int, + ); + +Map _$MessageIdToJson(MessageId instance) => { + 'message_id': instance.messageId, + }; + +Message _$MessageFromJson(Map json) => Message( + messageId: json['message_id'] as int, + messageThreadId: json['message_thread_id'] as int?, + from: json['from'] == null + ? null + : User.fromJson(json['from'] as Map), + senderChat: json['sender_chat'] == null + ? null + : Chat.fromJson(json['sender_chat'] as Map), + date: json['date'] as int, + chat: Chat.fromJson(json['chat'] as Map), + forwardFrom: json['forward_from'] == null + ? null + : User.fromJson(json['forward_from'] as Map), + forwardFromChat: json['forward_from_chat'] == null + ? null + : Chat.fromJson(json['forward_from_chat'] as Map), + forwardFromMessageId: json['forward_from_message_id'] as int?, + forwardSignature: json['forward_signature'] as String?, + forwardSenderName: json['forward_sender_name'] as String?, + forwardDate: json['forward_date'] as int?, + isTopicMessage: json['is_topic_message'] as bool?, + isAutomaticForward: json['is_automatic_forward'] as bool?, + replyToMessage: json['reply_to_message'] == null + ? null + : Message.fromJson(json['reply_to_message'] as Map), + viaBot: json['via_bot'] == null + ? null + : User.fromJson(json['via_bot'] as Map), + editDate: json['edit_date'] as int?, + hasProtectedContent: json['has_protected_content'] as bool?, + mediaGroupId: json['media_group_id'] as String?, + authorSignature: json['author_signature'] as String?, + text: json['text'] as String?, + entities: (json['entities'] as List?) + ?.map((e) => MessageEntity.fromJson(e as Map)) .toList(), - front_side: json['front_side'] == null + animation: json['animation'] == null ? null - : PassportFile.fromJson(json['front_side'] as Map), - reverse_side: json['reverse_side'] == null + : Animation.fromJson(json['animation'] as Map), + audio: json['audio'] == null ? null - : PassportFile.fromJson(json['reverse_side'] as Map), - selfie: json['selfie'] == null + : Audio.fromJson(json['audio'] as Map), + document: json['document'] == null ? null - : PassportFile.fromJson(json['selfie'] as Map), - translation: (json['translation'] as List?) - ?.map((e) => PassportFile.fromJson(e as Map)) + : Document.fromJson(json['document'] as Map), + photo: (json['photo'] as List?) + ?.map((e) => PhotoSize.fromJson(e as Map)) .toList(), - hash: json['hash'] as String, + sticker: json['sticker'] == null + ? null + : Sticker.fromJson(json['sticker'] as Map), + story: json['story'] == null + ? null + : Story.fromJson(json['story'] as Map), + video: json['video'] == null + ? null + : Video.fromJson(json['video'] as Map), + videoNote: json['video_note'] == null + ? null + : VideoNote.fromJson(json['video_note'] as Map), + voice: json['voice'] == null + ? null + : Voice.fromJson(json['voice'] as Map), + caption: json['caption'] as String?, + captionEntities: (json['caption_entities'] as List?) + ?.map((e) => MessageEntity.fromJson(e as Map)) + .toList(), + hasMediaSpoiler: json['has_media_spoiler'] as bool?, + contact: json['contact'] == null + ? null + : Contact.fromJson(json['contact'] as Map), + dice: json['dice'] == null + ? null + : Dice.fromJson(json['dice'] as Map), + game: json['game'] == null + ? null + : Game.fromJson(json['game'] as Map), + poll: json['poll'] == null + ? null + : Poll.fromJson(json['poll'] as Map), + venue: json['venue'] == null + ? null + : Venue.fromJson(json['venue'] as Map), + location: json['location'] == null + ? null + : Location.fromJson(json['location'] as Map), + newChatMembers: (json['new_chat_members'] as List?) + ?.map((e) => User.fromJson(e as Map)) + .toList(), + leftChatMember: json['left_chat_member'] == null + ? null + : User.fromJson(json['left_chat_member'] as Map), + newChatTitle: json['new_chat_title'] as String?, + newChatPhoto: (json['new_chat_photo'] as List?) + ?.map((e) => PhotoSize.fromJson(e as Map)) + .toList(), + deleteChatPhoto: json['delete_chat_photo'] as bool?, + groupChatCreated: json['group_chat_created'] as bool?, + supergroupChatCreated: json['supergroup_chat_created'] as bool?, + channelChatCreated: json['channel_chat_created'] as bool?, + messageAutoDeleteTimerChanged: + json['message_auto_delete_timer_changed'] == null + ? null + : MessageAutoDeleteTimerChanged.fromJson( + json['message_auto_delete_timer_changed'] + as Map), + migrateToChatId: json['migrate_to_chat_id'] as int?, + migrateFromChatId: json['migrate_from_chat_id'] as int?, + pinnedMessage: json['pinned_message'] == null + ? null + : Message.fromJson(json['pinned_message'] as Map), + invoice: json['invoice'] == null + ? null + : Invoice.fromJson(json['invoice'] as Map), + successfulPayment: json['successful_payment'] == null + ? null + : SuccessfulPayment.fromJson( + json['successful_payment'] as Map), + userShared: json['user_shared'] == null + ? null + : UserShared.fromJson(json['user_shared'] as Map), + chatShared: json['chat_shared'] == null + ? null + : ChatShared.fromJson(json['chat_shared'] as Map), + connectedWebsite: json['connected_website'] as String?, + writeAccessAllowed: json['write_access_allowed'] == null + ? null + : WriteAccessAllowed.fromJson( + json['write_access_allowed'] as Map), + passportData: json['passport_data'] == null + ? null + : PassportData.fromJson( + json['passport_data'] as Map), + proximityAlertTriggered: json['proximity_alert_triggered'] == null + ? null + : ProximityAlertTriggered.fromJson( + json['proximity_alert_triggered'] as Map), + forumTopicCreated: json['forum_topic_created'] == null + ? null + : ForumTopicCreated.fromJson( + json['forum_topic_created'] as Map), + forumTopicEdited: json['forum_topic_edited'] == null + ? null + : ForumTopicEdited.fromJson( + json['forum_topic_edited'] as Map), + forumTopicClosed: json['forum_topic_closed'] == null + ? null + : ForumTopicClosed.fromJson( + json['forum_topic_closed'] as Map), + forumTopicReopened: json['forum_topic_reopened'] == null + ? null + : ForumTopicReopened.fromJson( + json['forum_topic_reopened'] as Map), + generalForumTopicHidden: json['general_forum_topic_hidden'] == null + ? null + : GeneralForumTopicHidden.fromJson( + json['general_forum_topic_hidden'] as Map), + generalForumTopicUnhidden: json['general_forum_topic_unhidden'] == null + ? null + : GeneralForumTopicUnhidden.fromJson( + json['general_forum_topic_unhidden'] as Map), + videoChatScheduled: json['video_chat_scheduled'] == null + ? null + : VoiceChatScheduled.fromJson( + json['video_chat_scheduled'] as Map), + videoChatStarted: json['video_chat_started'] == null + ? null + : VoiceChatStarted.fromJson( + json['video_chat_started'] as Map), + videoChatEnded: json['video_chat_ended'] == null + ? null + : VoiceChatEnded.fromJson( + json['video_chat_ended'] as Map), + videoChatParticipantsInvited: json['video_chat_participants_invited'] == + null + ? null + : VoiceChatParticipantsInvited.fromJson( + json['video_chat_participants_invited'] as Map), + webAppData: json['web_app_data'] == null + ? null + : WebAppData.fromJson(json['web_app_data'] as Map), + replyMarkup: json['reply_markup'] == null + ? null + : InlineKeyboardMarkup.fromJson( + json['reply_markup'] as Map), + ); + +Map _$MessageToJson(Message instance) { + final val = { + 'message_id': instance.messageId, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('message_thread_id', instance.messageThreadId); + writeNotNull('from', instance.from?.toJson()); + writeNotNull('sender_chat', instance.senderChat?.toJson()); + val['date'] = instance.date; + val['chat'] = instance.chat.toJson(); + writeNotNull('forward_from', instance.forwardFrom?.toJson()); + writeNotNull('forward_from_chat', instance.forwardFromChat?.toJson()); + writeNotNull('forward_from_message_id', instance.forwardFromMessageId); + writeNotNull('forward_signature', instance.forwardSignature); + writeNotNull('forward_sender_name', instance.forwardSenderName); + writeNotNull('forward_date', instance.forwardDate); + writeNotNull('is_topic_message', instance.isTopicMessage); + writeNotNull('is_automatic_forward', instance.isAutomaticForward); + writeNotNull('reply_to_message', instance.replyToMessage?.toJson()); + writeNotNull('via_bot', instance.viaBot?.toJson()); + writeNotNull('edit_date', instance.editDate); + writeNotNull('has_protected_content', instance.hasProtectedContent); + writeNotNull('media_group_id', instance.mediaGroupId); + writeNotNull('author_signature', instance.authorSignature); + writeNotNull('text', instance.text); + writeNotNull('entities', instance.entities?.map((e) => e.toJson()).toList()); + writeNotNull('animation', instance.animation?.toJson()); + writeNotNull('audio', instance.audio?.toJson()); + writeNotNull('document', instance.document?.toJson()); + writeNotNull('photo', instance.photo?.map((e) => e.toJson()).toList()); + writeNotNull('sticker', instance.sticker?.toJson()); + writeNotNull('story', instance.story?.toJson()); + writeNotNull('video', instance.video?.toJson()); + writeNotNull('video_note', instance.videoNote?.toJson()); + writeNotNull('voice', instance.voice?.toJson()); + writeNotNull('caption', instance.caption); + writeNotNull('caption_entities', + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('has_media_spoiler', instance.hasMediaSpoiler); + writeNotNull('contact', instance.contact?.toJson()); + writeNotNull('dice', instance.dice?.toJson()); + writeNotNull('game', instance.game?.toJson()); + writeNotNull('poll', instance.poll?.toJson()); + writeNotNull('venue', instance.venue?.toJson()); + writeNotNull('location', instance.location?.toJson()); + writeNotNull('new_chat_members', + instance.newChatMembers?.map((e) => e.toJson()).toList()); + writeNotNull('left_chat_member', instance.leftChatMember?.toJson()); + writeNotNull('new_chat_title', instance.newChatTitle); + writeNotNull( + 'new_chat_photo', instance.newChatPhoto?.map((e) => e.toJson()).toList()); + writeNotNull('delete_chat_photo', instance.deleteChatPhoto); + writeNotNull('group_chat_created', instance.groupChatCreated); + writeNotNull('supergroup_chat_created', instance.supergroupChatCreated); + writeNotNull('channel_chat_created', instance.channelChatCreated); + writeNotNull('message_auto_delete_timer_changed', + instance.messageAutoDeleteTimerChanged?.toJson()); + writeNotNull('migrate_to_chat_id', instance.migrateToChatId); + writeNotNull('migrate_from_chat_id', instance.migrateFromChatId); + writeNotNull('pinned_message', instance.pinnedMessage?.toJson()); + writeNotNull('invoice', instance.invoice?.toJson()); + writeNotNull('successful_payment', instance.successfulPayment?.toJson()); + writeNotNull('user_shared', instance.userShared?.toJson()); + writeNotNull('chat_shared', instance.chatShared?.toJson()); + writeNotNull('connected_website', instance.connectedWebsite); + writeNotNull('write_access_allowed', instance.writeAccessAllowed?.toJson()); + writeNotNull('passport_data', instance.passportData?.toJson()); + writeNotNull( + 'proximity_alert_triggered', instance.proximityAlertTriggered?.toJson()); + writeNotNull('forum_topic_created', instance.forumTopicCreated?.toJson()); + writeNotNull('forum_topic_edited', instance.forumTopicEdited?.toJson()); + writeNotNull('forum_topic_closed', instance.forumTopicClosed?.toJson()); + writeNotNull('forum_topic_reopened', instance.forumTopicReopened?.toJson()); + writeNotNull( + 'general_forum_topic_hidden', instance.generalForumTopicHidden?.toJson()); + writeNotNull('general_forum_topic_unhidden', + instance.generalForumTopicUnhidden?.toJson()); + writeNotNull('video_chat_scheduled', instance.videoChatScheduled?.toJson()); + writeNotNull('video_chat_started', instance.videoChatStarted?.toJson()); + writeNotNull('video_chat_ended', instance.videoChatEnded?.toJson()); + writeNotNull('video_chat_participants_invited', + instance.videoChatParticipantsInvited?.toJson()); + writeNotNull('web_app_data', instance.webAppData?.toJson()); + writeNotNull('reply_markup', instance.replyMarkup?.toJson()); + return val; +} + +OrderInfo _$OrderInfoFromJson(Map json) => OrderInfo( + name: json['name'] as String?, + phoneNumber: json['phone_number'] as String?, + email: json['email'] as String?, + shippingAddress: json['shipping_address'] == null + ? null + : ShippingAddress.fromJson( + json['shipping_address'] as Map), + ); + +Map _$OrderInfoToJson(OrderInfo instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('name', instance.name); + writeNotNull('phone_number', instance.phoneNumber); + writeNotNull('email', instance.email); + writeNotNull('shipping_address', instance.shippingAddress?.toJson()); + return val; +} + +PassportData _$PassportDataFromJson(Map json) => PassportData( + data: (json['data'] as List) + .map((e) => + EncryptedPassportElement.fromJson(e as Map)) + .toList(), + credentials: EncryptedCredentials.fromJson( + json['credentials'] as Map), + ); + +Map _$PassportDataToJson(PassportData instance) => + { + 'data': instance.data.map((e) => e.toJson()).toList(), + 'credentials': instance.credentials.toJson(), + }; + +PassportElementErrorDataField _$PassportElementErrorDataFieldFromJson( + Map json) => + PassportElementErrorDataField( + source: json['source'] as String, + type: json['type'] as String, + message: json['message'] as String, + fieldName: json['field_name'] as String, + dataHash: json['data_hash'] as String, + ); + +Map _$PassportElementErrorDataFieldToJson( + PassportElementErrorDataField instance) => + { + 'source': instance.source, + 'type': instance.type, + 'message': instance.message, + 'field_name': instance.fieldName, + 'data_hash': instance.dataHash, + }; + +PassportElementErrorFile _$PassportElementErrorFileFromJson( + Map json) => + PassportElementErrorFile( + source: json['source'] as String, + type: json['type'] as String, + message: json['message'] as String, + fileHash: json['file_hash'] as String, + ); + +Map _$PassportElementErrorFileToJson( + PassportElementErrorFile instance) => + { + 'source': instance.source, + 'type': instance.type, + 'message': instance.message, + 'file_hash': instance.fileHash, + }; + +PassportElementErrorFiles _$PassportElementErrorFilesFromJson( + Map json) => + PassportElementErrorFiles( + source: json['source'] as String, + type: json['type'] as String, + message: json['message'] as String, + fileHashes: (json['file_hashes'] as List) + .map((e) => e as String) + .toList(), + ); + +Map _$PassportElementErrorFilesToJson( + PassportElementErrorFiles instance) => + { + 'source': instance.source, + 'type': instance.type, + 'message': instance.message, + 'file_hashes': instance.fileHashes, + }; + +PassportElementErrorFrontSide _$PassportElementErrorFrontSideFromJson( + Map json) => + PassportElementErrorFrontSide( + source: json['source'] as String, + type: json['type'] as String, + message: json['message'] as String, + fileHash: json['file_hash'] as String, + ); + +Map _$PassportElementErrorFrontSideToJson( + PassportElementErrorFrontSide instance) => + { + 'source': instance.source, + 'type': instance.type, + 'message': instance.message, + 'file_hash': instance.fileHash, + }; + +PassportElementErrorReverseSide _$PassportElementErrorReverseSideFromJson( + Map json) => + PassportElementErrorReverseSide( + source: json['source'] as String, + type: json['type'] as String, + message: json['message'] as String, + fileHash: json['file_hash'] as String, + ); + +Map _$PassportElementErrorReverseSideToJson( + PassportElementErrorReverseSide instance) => + { + 'source': instance.source, + 'type': instance.type, + 'message': instance.message, + 'file_hash': instance.fileHash, + }; + +PassportElementErrorSelfie _$PassportElementErrorSelfieFromJson( + Map json) => + PassportElementErrorSelfie( + source: json['source'] as String, + type: json['type'] as String, + message: json['message'] as String, + fileHash: json['file_hash'] as String, + ); + +Map _$PassportElementErrorSelfieToJson( + PassportElementErrorSelfie instance) => + { + 'source': instance.source, + 'type': instance.type, + 'message': instance.message, + 'file_hash': instance.fileHash, + }; + +PassportElementErrorTranslationFile + _$PassportElementErrorTranslationFileFromJson(Map json) => + PassportElementErrorTranslationFile( + source: json['source'] as String, + type: json['type'] as String, + message: json['message'] as String, + fileHash: json['file_hash'] as String, + ); + +Map _$PassportElementErrorTranslationFileToJson( + PassportElementErrorTranslationFile instance) => + { + 'source': instance.source, + 'type': instance.type, + 'message': instance.message, + 'file_hash': instance.fileHash, + }; + +PassportElementErrorTranslationFiles + _$PassportElementErrorTranslationFilesFromJson(Map json) => + PassportElementErrorTranslationFiles( + source: json['source'] as String, + type: json['type'] as String, + message: json['message'] as String, + fileHashes: (json['file_hashes'] as List) + .map((e) => e as String) + .toList(), + ); + +Map _$PassportElementErrorTranslationFilesToJson( + PassportElementErrorTranslationFiles instance) => + { + 'source': instance.source, + 'type': instance.type, + 'message': instance.message, + 'file_hashes': instance.fileHashes, + }; + +PassportElementErrorUnspecified _$PassportElementErrorUnspecifiedFromJson( + Map json) => + PassportElementErrorUnspecified( + source: json['source'] as String, + type: json['type'] as String, + message: json['message'] as String, + elementHash: json['element_hash'] as String, + ); + +Map _$PassportElementErrorUnspecifiedToJson( + PassportElementErrorUnspecified instance) => + { + 'source': instance.source, + 'type': instance.type, + 'message': instance.message, + 'element_hash': instance.elementHash, + }; + +PassportElementError _$PassportElementErrorFromJson( + Map json) => + PassportElementError( + source: json['source'] as String, + type: json['type'] as String, + message: json['message'] as String, + ); + +Map _$PassportElementErrorToJson( + PassportElementError instance) => + { + 'source': instance.source, + 'type': instance.type, + 'message': instance.message, + }; + +PassportFile _$PassportFileFromJson(Map json) => PassportFile( + fileId: json['file_id'] as String, + fileUniqueId: json['file_unique_id'] as String, + fileSize: json['file_size'] as int, + fileDate: json['file_date'] as int, + ); + +Map _$PassportFileToJson(PassportFile instance) => + { + 'file_id': instance.fileId, + 'file_unique_id': instance.fileUniqueId, + 'file_size': instance.fileSize, + 'file_date': instance.fileDate, + }; + +PhotoSize _$PhotoSizeFromJson(Map json) => PhotoSize( + fileId: json['file_id'] as String, + fileUniqueId: json['file_unique_id'] as String, + width: json['width'] as int, + height: json['height'] as int, + fileSize: json['file_size'] as int?, + ); + +Map _$PhotoSizeToJson(PhotoSize instance) { + final val = { + 'file_id': instance.fileId, + 'file_unique_id': instance.fileUniqueId, + 'width': instance.width, + 'height': instance.height, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('file_size', instance.fileSize); + return val; +} + +PollAnswer _$PollAnswerFromJson(Map json) => PollAnswer( + pollId: json['poll_id'] as String, + voterChat: json['voter_chat'] == null + ? null + : Chat.fromJson(json['voter_chat'] as Map), + user: json['user'] == null + ? null + : User.fromJson(json['user'] as Map), + optionIds: + (json['option_ids'] as List).map((e) => e as int).toList(), + ); + +Map _$PollAnswerToJson(PollAnswer instance) { + final val = { + 'poll_id': instance.pollId, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('voter_chat', instance.voterChat?.toJson()); + writeNotNull('user', instance.user?.toJson()); + val['option_ids'] = instance.optionIds; + return val; +} + +PollOption _$PollOptionFromJson(Map json) => PollOption( + text: json['text'] as String, + voterCount: json['voter_count'] as int, + ); + +Map _$PollOptionToJson(PollOption instance) => + { + 'text': instance.text, + 'voter_count': instance.voterCount, + }; + +Poll _$PollFromJson(Map json) => Poll( + id: json['id'] as String, + question: json['question'] as String, + options: (json['options'] as List) + .map((e) => PollOption.fromJson(e as Map)) + .toList(), + totalVoterCount: json['total_voter_count'] as int, + isClosed: json['is_closed'] as bool, + isAnonymous: json['is_anonymous'] as bool, + type: json['type'] as String, + allowsMultipleAnswers: json['allows_multiple_answers'] as bool, + correctOptionId: json['correct_option_id'] as int?, + explanation: json['explanation'] as String?, + explanationEntities: (json['explanation_entities'] as List?) + ?.map((e) => MessageEntity.fromJson(e as Map)) + .toList(), + openPeriod: json['open_period'] as int?, + closeDate: json['close_date'] as int?, + ); + +Map _$PollToJson(Poll instance) { + final val = { + 'id': instance.id, + 'question': instance.question, + 'options': instance.options.map((e) => e.toJson()).toList(), + 'total_voter_count': instance.totalVoterCount, + 'is_closed': instance.isClosed, + 'is_anonymous': instance.isAnonymous, + 'type': instance.type, + 'allows_multiple_answers': instance.allowsMultipleAnswers, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('correct_option_id', instance.correctOptionId); + writeNotNull('explanation', instance.explanation); + writeNotNull('explanation_entities', + instance.explanationEntities?.map((e) => e.toJson()).toList()); + writeNotNull('open_period', instance.openPeriod); + writeNotNull('close_date', instance.closeDate); + return val; +} + +PreCheckoutQuery _$PreCheckoutQueryFromJson(Map json) => + PreCheckoutQuery( + id: json['id'] as String, + from: User.fromJson(json['from'] as Map), + currency: json['currency'] as String, + totalAmount: json['total_amount'] as int, + invoicePayload: json['invoice_payload'] as String, + shippingOptionId: json['shipping_option_id'] as String?, + orderInfo: json['order_info'] == null + ? null + : OrderInfo.fromJson(json['order_info'] as Map), + ); + +Map _$PreCheckoutQueryToJson(PreCheckoutQuery instance) { + final val = { + 'id': instance.id, + 'from': instance.from.toJson(), + 'currency': instance.currency, + 'total_amount': instance.totalAmount, + 'invoice_payload': instance.invoicePayload, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('shipping_option_id', instance.shippingOptionId); + writeNotNull('order_info', instance.orderInfo?.toJson()); + return val; +} + +ProximityAlertTriggered _$ProximityAlertTriggeredFromJson( + Map json) => + ProximityAlertTriggered( + traveler: User.fromJson(json['traveler'] as Map), + watcher: User.fromJson(json['watcher'] as Map), + distance: json['distance'] as int, + ); + +Map _$ProximityAlertTriggeredToJson( + ProximityAlertTriggered instance) => + { + 'traveler': instance.traveler.toJson(), + 'watcher': instance.watcher.toJson(), + 'distance': instance.distance, + }; + +ReplyKeyboardMarkup _$ReplyKeyboardMarkupFromJson(Map json) => + ReplyKeyboardMarkup( + keyboard: (json['keyboard'] as List) + .map((e) => (e as List) + .map((e) => KeyboardButton.fromJson(e as Map)) + .toList()) + .toList(), + isPersistent: json['is_persistent'] as bool?, + resizeKeyboard: json['resize_keyboard'] as bool?, + oneTimeKeyboard: json['one_time_keyboard'] as bool?, + inputFieldPlaceholder: json['input_field_placeholder'] as String?, + selective: json['selective'] as bool?, + ); + +Map _$ReplyKeyboardMarkupToJson(ReplyKeyboardMarkup instance) { + final val = { + 'keyboard': instance.keyboard + .map((e) => e.map((e) => e.toJson()).toList()) + .toList(), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('is_persistent', instance.isPersistent); + writeNotNull('resize_keyboard', instance.resizeKeyboard); + writeNotNull('one_time_keyboard', instance.oneTimeKeyboard); + writeNotNull('input_field_placeholder', instance.inputFieldPlaceholder); + writeNotNull('selective', instance.selective); + return val; +} + +ReplyKeyboardRemove _$ReplyKeyboardRemoveFromJson(Map json) => + ReplyKeyboardRemove( + removeKeyboard: json['remove_keyboard'] as bool, + selective: json['selective'] as bool?, + ); + +Map _$ReplyKeyboardRemoveToJson(ReplyKeyboardRemove instance) { + final val = { + 'remove_keyboard': instance.removeKeyboard, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('selective', instance.selective); + return val; +} + +ReplyMarkup _$ReplyMarkupFromJson(Map json) => ReplyMarkup(); + +Map _$ReplyMarkupToJson(ReplyMarkup instance) => + {}; + +ResponseParameters _$ResponseParametersFromJson(Map json) => + ResponseParameters( + migrateToChatId: json['migrate_to_chat_id'] as int?, + retryAfter: json['retry_after'] as int?, + ); + +Map _$ResponseParametersToJson(ResponseParameters instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('migrate_to_chat_id', instance.migrateToChatId); + writeNotNull('retry_after', instance.retryAfter); + return val; +} + +Response _$ResponseFromJson(Map json) => Response( + ok: json['ok'] as bool, + ); + +Map _$ResponseToJson(Response instance) => { + 'ok': instance.ok, + }; + +SuccessResponse _$SuccessResponseFromJson(Map json) => + SuccessResponse( + ok: json['ok'] as bool, + result: json['result'], + ); + +Map _$SuccessResponseToJson(SuccessResponse instance) { + final val = { + 'ok': instance.ok, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('result', instance.result); + return val; +} + +ErrorResponse _$ErrorResponseFromJson(Map json) => + ErrorResponse( + ok: json['ok'] as bool, + description: json['description'] as String, + errorCode: json['error_code'] as int, + parameters: json['parameters'] == null + ? null + : ResponseParameters.fromJson( + json['parameters'] as Map), + ); + +Map _$ErrorResponseToJson(ErrorResponse instance) { + final val = { + 'ok': instance.ok, + 'description': instance.description, + 'error_code': instance.errorCode, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('parameters', instance.parameters?.toJson()); + return val; +} + +SentWebAppMessage _$SentWebAppMessageFromJson(Map json) => + SentWebAppMessage( + inlineMessageId: json['inline_message_id'] as String?, + ); + +Map _$SentWebAppMessageToJson(SentWebAppMessage instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('inline_message_id', instance.inlineMessageId); + return val; +} + +ShippingAddress _$ShippingAddressFromJson(Map json) => + ShippingAddress( + countryCode: json['country_code'] as String, + state: json['state'] as String, + city: json['city'] as String, + streetLine1: json['street_line1'] as String, + streetLine2: json['street_line2'] as String, + postCode: json['post_code'] as String, + ); + +Map _$ShippingAddressToJson(ShippingAddress instance) => + { + 'country_code': instance.countryCode, + 'state': instance.state, + 'city': instance.city, + 'street_line1': instance.streetLine1, + 'street_line2': instance.streetLine2, + 'post_code': instance.postCode, + }; + +ShippingOption _$ShippingOptionFromJson(Map json) => + ShippingOption( + id: json['id'] as String, + title: json['title'] as String, + prices: (json['prices'] as List) + .map((e) => LabeledPrice.fromJson(e as Map)) + .toList(), + ); + +Map _$ShippingOptionToJson(ShippingOption instance) => + { + 'id': instance.id, + 'title': instance.title, + 'prices': instance.prices.map((e) => e.toJson()).toList(), + }; + +ShippingQuery _$ShippingQueryFromJson(Map json) => + ShippingQuery( + id: json['id'] as String, + from: User.fromJson(json['from'] as Map), + invoicePayload: json['invoice_payload'] as String, + shippingAddress: ShippingAddress.fromJson( + json['shipping_address'] as Map), + ); + +Map _$ShippingQueryToJson(ShippingQuery instance) => + { + 'id': instance.id, + 'from': instance.from.toJson(), + 'invoice_payload': instance.invoicePayload, + 'shipping_address': instance.shippingAddress.toJson(), + }; + +StickerSet _$StickerSetFromJson(Map json) => StickerSet( + name: json['name'] as String, + title: json['title'] as String, + stickerType: json['sticker_type'] as String, + isAnimated: json['is_animated'] as bool, + isVideo: json['is_video'] as bool, + stickers: (json['stickers'] as List) + .map((e) => Sticker.fromJson(e as Map)) + .toList(), + thumbnail: json['thumbnail'] == null + ? null + : PhotoSize.fromJson(json['thumbnail'] as Map), + ); + +Map _$StickerSetToJson(StickerSet instance) { + final val = { + 'name': instance.name, + 'title': instance.title, + 'sticker_type': instance.stickerType, + 'is_animated': instance.isAnimated, + 'is_video': instance.isVideo, + 'stickers': instance.stickers.map((e) => e.toJson()).toList(), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('thumbnail', instance.thumbnail?.toJson()); + return val; +} + +Sticker _$StickerFromJson(Map json) => Sticker( + fileId: json['file_id'] as String, + fileUniqueId: json['file_unique_id'] as String, + width: json['width'] as int, + height: json['height'] as int, + isAnimated: json['is_animated'] as bool, + isVideo: json['is_video'] as bool, + thumbnail: json['thumbnail'] == null + ? null + : PhotoSize.fromJson(json['thumbnail'] as Map), + emoji: json['emoji'] as String?, + setName: json['set_name'] as String?, + premiumAnimation: json['premium_animation'] == null + ? null + : File.fromJson(json['premium_animation'] as Map), + maskPosition: json['mask_position'] == null + ? null + : MaskPosition.fromJson( + json['mask_position'] as Map), + customEmojiId: json['custom_emoji_id'] as String?, + needsRepainting: json['needs_repainting'] as bool?, + fileSize: json['file_size'] as int?, + ); + +Map _$StickerToJson(Sticker instance) { + final val = { + 'file_id': instance.fileId, + 'file_unique_id': instance.fileUniqueId, + 'width': instance.width, + 'height': instance.height, + 'is_animated': instance.isAnimated, + 'is_video': instance.isVideo, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('thumbnail', instance.thumbnail?.toJson()); + writeNotNull('emoji', instance.emoji); + writeNotNull('set_name', instance.setName); + writeNotNull('premium_animation', instance.premiumAnimation?.toJson()); + writeNotNull('mask_position', instance.maskPosition?.toJson()); + writeNotNull('custom_emoji_id', instance.customEmojiId); + writeNotNull('needs_repainting', instance.needsRepainting); + writeNotNull('file_size', instance.fileSize); + return val; +} + +Story _$StoryFromJson(Map json) => Story(); + +Map _$StoryToJson(Story instance) => {}; + +SuccessfulPayment _$SuccessfulPaymentFromJson(Map json) => + SuccessfulPayment( + currency: json['currency'] as String, + totalAmount: json['total_amount'] as int, + invoicePayload: json['invoice_payload'] as String, + shippingOptionId: json['shipping_option_id'] as String?, + orderInfo: json['order_info'] == null + ? null + : OrderInfo.fromJson(json['order_info'] as Map), + telegramPaymentChargeId: json['telegram_payment_charge_id'] as String, + providerPaymentChargeId: json['provider_payment_charge_id'] as String, + ); + +Map _$SuccessfulPaymentToJson(SuccessfulPayment instance) { + final val = { + 'currency': instance.currency, + 'total_amount': instance.totalAmount, + 'invoice_payload': instance.invoicePayload, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('shipping_option_id', instance.shippingOptionId); + writeNotNull('order_info', instance.orderInfo?.toJson()); + val['telegram_payment_charge_id'] = instance.telegramPaymentChargeId; + val['provider_payment_charge_id'] = instance.providerPaymentChargeId; + return val; +} + +SwitchInlineQueryChosenChat _$SwitchInlineQueryChosenChatFromJson( + Map json) => + SwitchInlineQueryChosenChat( + query: json['query'] as String?, + allowUserChats: json['allow_user_chats'] as bool?, + allowBotChats: json['allow_bot_chats'] as bool?, + allowGroupChats: json['allow_group_chats'] as bool?, + allowChannelChats: json['allow_channel_chats'] as bool?, + ); + +Map _$SwitchInlineQueryChosenChatToJson( + SwitchInlineQueryChosenChat instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('query', instance.query); + writeNotNull('allow_user_chats', instance.allowUserChats); + writeNotNull('allow_bot_chats', instance.allowBotChats); + writeNotNull('allow_group_chats', instance.allowGroupChats); + writeNotNull('allow_channel_chats', instance.allowChannelChats); + return val; +} + +Update _$UpdateFromJson(Map json) => Update( + updateId: json['update_id'] as int, + message: json['message'] == null + ? null + : Message.fromJson(json['message'] as Map), + editedMessage: json['edited_message'] == null + ? null + : Message.fromJson(json['edited_message'] as Map), + channelPost: json['channel_post'] == null + ? null + : Message.fromJson(json['channel_post'] as Map), + editedChannelPost: json['edited_channel_post'] == null + ? null + : Message.fromJson( + json['edited_channel_post'] as Map), + inlineQuery: json['inline_query'] == null + ? null + : InlineQuery.fromJson(json['inline_query'] as Map), + chosenInlineResult: json['chosen_inline_result'] == null + ? null + : ChosenInlineResult.fromJson( + json['chosen_inline_result'] as Map), + callbackQuery: json['callback_query'] == null + ? null + : CallbackQuery.fromJson( + json['callback_query'] as Map), + shippingQuery: json['shipping_query'] == null + ? null + : ShippingQuery.fromJson( + json['shipping_query'] as Map), + preCheckoutQuery: json['pre_checkout_query'] == null + ? null + : PreCheckoutQuery.fromJson( + json['pre_checkout_query'] as Map), + poll: json['poll'] == null + ? null + : Poll.fromJson(json['poll'] as Map), + pollAnswer: json['poll_answer'] == null + ? null + : PollAnswer.fromJson(json['poll_answer'] as Map), + myChatMember: json['my_chat_member'] == null + ? null + : ChatMemberUpdated.fromJson( + json['my_chat_member'] as Map), + chatMember: json['chat_member'] == null + ? null + : ChatMemberUpdated.fromJson( + json['chat_member'] as Map), + chatJoinRequest: json['chat_join_request'] == null + ? null + : ChatJoinRequest.fromJson( + json['chat_join_request'] as Map), + ); + +Map _$UpdateToJson(Update instance) { + final val = { + 'update_id': instance.updateId, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('message', instance.message?.toJson()); + writeNotNull('edited_message', instance.editedMessage?.toJson()); + writeNotNull('channel_post', instance.channelPost?.toJson()); + writeNotNull('edited_channel_post', instance.editedChannelPost?.toJson()); + writeNotNull('inline_query', instance.inlineQuery?.toJson()); + writeNotNull('chosen_inline_result', instance.chosenInlineResult?.toJson()); + writeNotNull('callback_query', instance.callbackQuery?.toJson()); + writeNotNull('shipping_query', instance.shippingQuery?.toJson()); + writeNotNull('pre_checkout_query', instance.preCheckoutQuery?.toJson()); + writeNotNull('poll', instance.poll?.toJson()); + writeNotNull('poll_answer', instance.pollAnswer?.toJson()); + writeNotNull('my_chat_member', instance.myChatMember?.toJson()); + writeNotNull('chat_member', instance.chatMember?.toJson()); + writeNotNull('chat_join_request', instance.chatJoinRequest?.toJson()); + return val; +} + +UserProfilePhotos _$UserProfilePhotosFromJson(Map json) => + UserProfilePhotos( + totalCount: json['total_count'] as int, + photos: (json['photos'] as List) + .map((e) => (e as List) + .map((e) => PhotoSize.fromJson(e as Map)) + .toList()) + .toList(), + ); + +Map _$UserProfilePhotosToJson(UserProfilePhotos instance) => + { + 'total_count': instance.totalCount, + 'photos': instance.photos + .map((e) => e.map((e) => e.toJson()).toList()) + .toList(), + }; + +UserShared _$UserSharedFromJson(Map json) => UserShared( + requestId: json['request_id'] as int, + userId: json['user_id'] as int, + ); + +Map _$UserSharedToJson(UserShared instance) => + { + 'request_id': instance.requestId, + 'user_id': instance.userId, + }; + +User _$UserFromJson(Map json) => User( + id: json['id'] as int, + isBot: json['is_bot'] as bool, + firstName: json['first_name'] as String, + lastName: json['last_name'] as String?, + username: json['username'] as String?, + languageCode: json['language_code'] as String?, + isPremium: json['is_premium'] as bool?, + addedToAttachmentMenu: json['added_to_attachment_menu'] as bool?, + canJoinGroups: json['can_join_groups'] as bool?, + canReadAllGroupMessages: json['can_read_all_group_messages'] as bool?, + supportsInlineQueries: json['supports_inline_queries'] as bool?, + ); + +Map _$UserToJson(User instance) { + final val = { + 'id': instance.id, + 'is_bot': instance.isBot, + 'first_name': instance.firstName, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('last_name', instance.lastName); + writeNotNull('username', instance.username); + writeNotNull('language_code', instance.languageCode); + writeNotNull('is_premium', instance.isPremium); + writeNotNull('added_to_attachment_menu', instance.addedToAttachmentMenu); + writeNotNull('can_join_groups', instance.canJoinGroups); + writeNotNull('can_read_all_group_messages', instance.canReadAllGroupMessages); + writeNotNull('supports_inline_queries', instance.supportsInlineQueries); + return val; +} + +Venue _$VenueFromJson(Map json) => Venue( + location: Location.fromJson(json['location'] as Map), + title: json['title'] as String, + address: json['address'] as String, + foursquareId: json['foursquare_id'] as String?, + foursquareType: json['foursquare_type'] as String?, + googlePlaceId: json['google_place_id'] as String?, + googlePlaceType: json['google_place_type'] as String?, + ); + +Map _$VenueToJson(Venue instance) { + final val = { + 'location': instance.location.toJson(), + 'title': instance.title, + 'address': instance.address, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('foursquare_id', instance.foursquareId); + writeNotNull('foursquare_type', instance.foursquareType); + writeNotNull('google_place_id', instance.googlePlaceId); + writeNotNull('google_place_type', instance.googlePlaceType); + return val; +} + +VideoNote _$VideoNoteFromJson(Map json) => VideoNote( + fileId: json['file_id'] as String, + fileUniqueId: json['file_unique_id'] as String, + length: json['length'] as int, + duration: json['duration'] as int, + thumbnail: json['thumbnail'] == null + ? null + : PhotoSize.fromJson(json['thumbnail'] as Map), + fileSize: json['file_size'] as int?, + ); + +Map _$VideoNoteToJson(VideoNote instance) { + final val = { + 'file_id': instance.fileId, + 'file_unique_id': instance.fileUniqueId, + 'length': instance.length, + 'duration': instance.duration, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('thumbnail', instance.thumbnail?.toJson()); + writeNotNull('file_size', instance.fileSize); + return val; +} + +Video _$VideoFromJson(Map json) => Video( + fileId: json['file_id'] as String, + fileUniqueId: json['file_unique_id'] as String, + width: json['width'] as int, + height: json['height'] as int, + duration: json['duration'] as int, + thumbnail: json['thumbnail'] == null + ? null + : PhotoSize.fromJson(json['thumbnail'] as Map), + fileName: json['file_name'] as String?, + mimeType: json['mime_type'] as String?, + fileSize: json['file_size'] as int?, ); -Map _$EncryptedPassportElementToJson( - EncryptedPassportElement instance) { +Map _$VideoToJson(Video instance) { final val = { - 'type': instance.type, + 'file_id': instance.fileId, + 'file_unique_id': instance.fileUniqueId, + 'width': instance.width, + 'height': instance.height, + 'duration': instance.duration, }; void writeNotNull(String key, dynamic value) { @@ -3519,239 +4337,127 @@ Map _$EncryptedPassportElementToJson( } } - writeNotNull('data', instance.data); - writeNotNull('phone_number', instance.phone_number); - writeNotNull('email', instance.email); - writeNotNull('files', instance.files?.map((e) => e.toJson()).toList()); - writeNotNull('front_side', instance.front_side?.toJson()); - writeNotNull('reverse_side', instance.reverse_side?.toJson()); - writeNotNull('selfie', instance.selfie?.toJson()); - writeNotNull( - 'translation', instance.translation?.map((e) => e.toJson()).toList()); - val['hash'] = instance.hash; + writeNotNull('thumbnail', instance.thumbnail?.toJson()); + writeNotNull('file_name', instance.fileName); + writeNotNull('mime_type', instance.mimeType); + writeNotNull('file_size', instance.fileSize); return val; } -EncryptedCredentials _$EncryptedCredentialsFromJson( - Map json) => - EncryptedCredentials( - data: json['data'] as String, - hash: json['hash'] as String, - secret: json['secret'] as String, +VoiceChatEnded _$VoiceChatEndedFromJson(Map json) => + VoiceChatEnded( + duration: json['duration'] as int, ); -Map _$EncryptedCredentialsToJson( - EncryptedCredentials instance) => +Map _$VoiceChatEndedToJson(VoiceChatEnded instance) => { - 'data': instance.data, - 'hash': instance.hash, - 'secret': instance.secret, + 'duration': instance.duration, }; -PassportElementError _$PassportElementErrorFromJson( +VoiceChatParticipantsInvited _$VoiceChatParticipantsInvitedFromJson( Map json) => - PassportElementError( - source: json['source'] as String, - type: json['type'] as String, - message: json['message'] as String, + VoiceChatParticipantsInvited( + users: (json['users'] as List?) + ?.map((e) => User.fromJson(e as Map)) + .toList(), ); -Map _$PassportElementErrorToJson( - PassportElementError instance) => - { - 'source': instance.source, - 'type': instance.type, - 'message': instance.message, - }; +Map _$VoiceChatParticipantsInvitedToJson( + VoiceChatParticipantsInvited instance) { + final val = {}; -PassportElementErrorDataField _$PassportElementErrorDataFieldFromJson( - Map json) => - PassportElementErrorDataField( - source: json['source'] as String, - type: json['type'] as String, - message: json['message'] as String, - field_name: json['field_name'] as String, - data_hash: json['data_hash'] as String, - ); + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } -Map _$PassportElementErrorDataFieldToJson( - PassportElementErrorDataField instance) => - { - 'source': instance.source, - 'type': instance.type, - 'message': instance.message, - 'field_name': instance.field_name, - 'data_hash': instance.data_hash, - }; + writeNotNull('users', instance.users?.map((e) => e.toJson()).toList()); + return val; +} -PassportElementErrorFrontSide _$PassportElementErrorFrontSideFromJson( - Map json) => - PassportElementErrorFrontSide( - source: json['source'] as String, - type: json['type'] as String, - message: json['message'] as String, - file_hash: json['file_hash'] as String, +VoiceChatScheduled _$VoiceChatScheduledFromJson(Map json) => + VoiceChatScheduled( + json['start_date'] as int, ); -Map _$PassportElementErrorFrontSideToJson( - PassportElementErrorFrontSide instance) => +Map _$VoiceChatScheduledToJson(VoiceChatScheduled instance) => { - 'source': instance.source, - 'type': instance.type, - 'message': instance.message, - 'file_hash': instance.file_hash, + 'start_date': instance.startDate, }; -PassportElementErrorReverseSide _$PassportElementErrorReverseSideFromJson( - Map json) => - PassportElementErrorReverseSide( - source: json['source'] as String, - type: json['type'] as String, - message: json['message'] as String, - file_hash: json['file_hash'] as String, - ); +VoiceChatStarted _$VoiceChatStartedFromJson(Map json) => + VoiceChatStarted(); -Map _$PassportElementErrorReverseSideToJson( - PassportElementErrorReverseSide instance) => - { - 'source': instance.source, - 'type': instance.type, - 'message': instance.message, - 'file_hash': instance.file_hash, - }; +Map _$VoiceChatStartedToJson(VoiceChatStarted instance) => + {}; -PassportElementErrorSelfie _$PassportElementErrorSelfieFromJson( - Map json) => - PassportElementErrorSelfie( - source: json['source'] as String, - type: json['type'] as String, - message: json['message'] as String, - file_hash: json['file_hash'] as String, +Voice _$VoiceFromJson(Map json) => Voice( + fileId: json['file_id'] as String, + fileUniqueId: json['file_unique_id'] as String, + duration: json['duration'] as int, + mimeType: json['mime_type'] as String?, + fileSize: json['file_size'] as int?, ); -Map _$PassportElementErrorSelfieToJson( - PassportElementErrorSelfie instance) => - { - 'source': instance.source, - 'type': instance.type, - 'message': instance.message, - 'file_hash': instance.file_hash, - }; +Map _$VoiceToJson(Voice instance) { + final val = { + 'file_id': instance.fileId, + 'file_unique_id': instance.fileUniqueId, + 'duration': instance.duration, + }; -PassportElementErrorFile _$PassportElementErrorFileFromJson( - Map json) => - PassportElementErrorFile( - source: json['source'] as String, - type: json['type'] as String, - message: json['message'] as String, - file_hash: json['file_hash'] as String, - ); + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } -Map _$PassportElementErrorFileToJson( - PassportElementErrorFile instance) => - { - 'source': instance.source, - 'type': instance.type, - 'message': instance.message, - 'file_hash': instance.file_hash, - }; + writeNotNull('mime_type', instance.mimeType); + writeNotNull('file_size', instance.fileSize); + return val; +} -PassportElementErrorFiles _$PassportElementErrorFilesFromJson( - Map json) => - PassportElementErrorFiles( - source: json['source'] as String, - type: json['type'] as String, - message: json['message'] as String, - file_hashes: (json['file_hashes'] as List) - .map((e) => e as String) - .toList(), +WebAppData _$WebAppDataFromJson(Map json) => WebAppData( + data: json['data'] as String, + buttonText: json['button_text'] as String, ); -Map _$PassportElementErrorFilesToJson( - PassportElementErrorFiles instance) => - { - 'source': instance.source, - 'type': instance.type, - 'message': instance.message, - 'file_hashes': instance.file_hashes, - }; - -PassportElementErrorTranslationFile - _$PassportElementErrorTranslationFileFromJson(Map json) => - PassportElementErrorTranslationFile( - source: json['source'] as String, - type: json['type'] as String, - message: json['message'] as String, - file_hash: json['file_hash'] as String, - ); - -Map _$PassportElementErrorTranslationFileToJson( - PassportElementErrorTranslationFile instance) => - { - 'source': instance.source, - 'type': instance.type, - 'message': instance.message, - 'file_hash': instance.file_hash, - }; - -PassportElementErrorTranslationFiles - _$PassportElementErrorTranslationFilesFromJson(Map json) => - PassportElementErrorTranslationFiles( - source: json['source'] as String, - type: json['type'] as String, - message: json['message'] as String, - file_hashes: (json['file_hashes'] as List) - .map((e) => e as String) - .toList(), - ); - -Map _$PassportElementErrorTranslationFilesToJson( - PassportElementErrorTranslationFiles instance) => +Map _$WebAppDataToJson(WebAppData instance) => { - 'source': instance.source, - 'type': instance.type, - 'message': instance.message, - 'file_hashes': instance.file_hashes, + 'data': instance.data, + 'button_text': instance.buttonText, }; -PassportElementErrorUnspecified _$PassportElementErrorUnspecifiedFromJson( - Map json) => - PassportElementErrorUnspecified( - source: json['source'] as String, - type: json['type'] as String, - message: json['message'] as String, - element_hash: json['element_hash'] as String, +WebAppInfo _$WebAppInfoFromJson(Map json) => WebAppInfo( + url: json['url'] as String, ); -Map _$PassportElementErrorUnspecifiedToJson( - PassportElementErrorUnspecified instance) => +Map _$WebAppInfoToJson(WebAppInfo instance) => { - 'source': instance.source, - 'type': instance.type, - 'message': instance.message, - 'element_hash': instance.element_hash, + 'url': instance.url, }; -Game _$GameFromJson(Map json) => Game( - title: json['title'] as String, - description: json['description'] as String, - photo: (json['photo'] as List) - .map((e) => PhotoSize.fromJson(e as Map)) - .toList(), - text: json['text'] as String?, - text_entities: (json['text_entities'] as List?) - ?.map((e) => MessageEntity.fromJson(e as Map)) +WebhookInfo _$WebhookInfoFromJson(Map json) => WebhookInfo( + url: json['url'] as String, + hasCustomCertificate: json['has_custom_certificate'] as bool, + pendingUpdateCount: json['pending_update_count'] as int, + ipAddress: json['ip_address'] as String?, + lastErrorDate: json['last_error_date'] as int?, + lastErrorMessage: json['last_error_message'] as String?, + lastSynchronizationErrorDate: + json['last_synchronization_error_date'] as int?, + maxConnections: json['max_connections'] as int?, + allowedUpdates: (json['allowed_updates'] as List?) + ?.map((e) => e as String) .toList(), - animation: json['animation'] == null - ? null - : Animation.fromJson(json['animation'] as Map), ); -Map _$GameToJson(Game instance) { +Map _$WebhookInfoToJson(WebhookInfo instance) { final val = { - 'title': instance.title, - 'description': instance.description, - 'photo': instance.photo.map((e) => e.toJson()).toList(), + 'url': instance.url, + 'has_custom_certificate': instance.hasCustomCertificate, + 'pending_update_count': instance.pendingUpdateCount, }; void writeNotNull(String key, dynamic value) { @@ -3760,29 +4466,30 @@ Map _$GameToJson(Game instance) { } } - writeNotNull('text', instance.text); + writeNotNull('ip_address', instance.ipAddress); + writeNotNull('last_error_date', instance.lastErrorDate); + writeNotNull('last_error_message', instance.lastErrorMessage); writeNotNull( - 'text_entities', instance.text_entities?.map((e) => e.toJson()).toList()); - writeNotNull('animation', instance.animation?.toJson()); + 'last_synchronization_error_date', instance.lastSynchronizationErrorDate); + writeNotNull('max_connections', instance.maxConnections); + writeNotNull('allowed_updates', instance.allowedUpdates); return val; } -CallbackGame _$CallbackGameFromJson(Map json) => - CallbackGame(); +WriteAccessAllowed _$WriteAccessAllowedFromJson(Map json) => + WriteAccessAllowed( + webAppName: json['web_app_name'] as String?, + ); -Map _$CallbackGameToJson(CallbackGame instance) => - {}; +Map _$WriteAccessAllowedToJson(WriteAccessAllowed instance) { + final val = {}; -GameHighScore _$GameHighScoreFromJson(Map json) => - GameHighScore( - position: json['position'] as int, - user: User.fromJson(json['user'] as Map), - score: json['score'] as int, - ); + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } -Map _$GameHighScoreToJson(GameHighScore instance) => - { - 'position': instance.position, - 'user': instance.user.toJson(), - 'score': instance.score, - }; + writeNotNull('web_app_name', instance.webAppName); + return val; +} diff --git a/lib/src/telegram/models/animation.dart b/lib/src/telegram/models/animation.dart index 1f8bebf4..567207a3 100644 --- a/lib/src/telegram/models/animation.dart +++ b/lib/src/telegram/models/animation.dart @@ -21,31 +21,31 @@ part of '../model.dart'; /// This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound). /// /// https://core.telegram.org/bots/api#animation -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class Animation { - String file_id; - String file_unique_id; + String fileId; + String fileUniqueId; int width; int height; int duration; - PhotoSize? thumb; - String? file_name; - String? mime_type; - int? file_size; + PhotoSize? thumbnail; + String? fileName; + String? mimeType; + int? fileSize; Animation({ - required this.file_id, - required this.file_unique_id, + required this.fileId, + required this.fileUniqueId, required this.width, required this.height, required this.duration, - this.thumb, - this.file_name, - this.mime_type, - this.file_size, + this.thumbnail, + this.fileName, + this.mimeType, + this.fileSize, }); - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) Duration get duration_ => TimeHelper.toDuration(duration); set duration_(Duration duration) => this.duration = TimeHelper.toSeconds(duration); diff --git a/lib/src/telegram/models/audio.dart b/lib/src/telegram/models/audio.dart index 680f16b2..bc1c3a5f 100644 --- a/lib/src/telegram/models/audio.dart +++ b/lib/src/telegram/models/audio.dart @@ -21,31 +21,31 @@ part of '../model.dart'; /// This object represents an audio file to be treated as music by the Telegram clients. /// /// https://core.telegram.org/bots/api#audio -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class Audio { - String file_id; - String file_unique_id; + String fileId; + String fileUniqueId; int duration; String? performer; String? title; - String? file_name; - String? mime_type; - int? file_size; - PhotoSize? thumb; + String? fileName; + String? mimeType; + int? fileSize; + PhotoSize? thumbnail; Audio({ - required this.file_id, - required this.file_unique_id, + required this.fileId, + required this.fileUniqueId, required this.duration, this.performer, this.title, - this.file_name, - this.mime_type, - this.file_size, - this.thumb, + this.fileName, + this.mimeType, + this.fileSize, + this.thumbnail, }); - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) Duration get duration_ => TimeHelper.toDuration(duration); set duration_(Duration duration) => this.duration = TimeHelper.toSeconds(duration); diff --git a/lib/src/telegram/models/bot_command.dart b/lib/src/telegram/models/bot_command.dart index 90c08e8a..38eb5bbe 100644 --- a/lib/src/telegram/models/bot_command.dart +++ b/lib/src/telegram/models/bot_command.dart @@ -21,7 +21,7 @@ part of '../model.dart'; /// This object represents a dice with random value from 1 to 6. (Yes, we're aware of the “proper” singular of die. But it's awkward, and we decided to help it change. One dice at a time!) /// /// https://core.telegram.org/bots/api#dice -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class BotCommand { String command; String description; diff --git a/lib/src/telegram/models/bot_command_scope.dart b/lib/src/telegram/models/bot_command_scope.dart index bacf6651..88775db7 100644 --- a/lib/src/telegram/models/bot_command_scope.dart +++ b/lib/src/telegram/models/bot_command_scope.dart @@ -30,15 +30,15 @@ part of '../model.dart'; /// * [BotCommandScopeChatMember](https://core.telegram.org/bots/api#botcommandscopechatmember) /// /// https://core.telegram.org/bots/api#botcommandscope -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class BotCommandScope { - static const DEFAULT = 'default'; - static const ALL_PRIVATE_CHATS = 'all_private_chats'; - static const ALL_GROUP_CHATS = 'all_group_chats'; - static const ALL_CHAT_ADMINISTRATORS = 'all_chat_administrators'; - static const CHAT = 'chat'; - static const CHAT_ADMINISTRATORS = 'chat_administrators'; - static const CHAT_MEMBER = 'chat_member'; + static const typeDefault = 'default'; + static const typeAllPrivateChats = 'all_private_chats'; + static const typeAllGroupChats = 'all_group_chats'; + static const typeAllChatAdministrators = 'all_chat_administrators'; + static const typeChat = 'chat'; + static const typeChatAdministrators = 'chat_administrators'; + static const typeChatMember = 'chat_member'; String type; diff --git a/lib/src/telegram/models/bot_command_scope_all_chats_administrators.dart b/lib/src/telegram/models/bot_command_scope_all_chats_administrators.dart index 0bb61c67..e75a36de 100644 --- a/lib/src/telegram/models/bot_command_scope_all_chats_administrators.dart +++ b/lib/src/telegram/models/bot_command_scope_all_chats_administrators.dart @@ -23,13 +23,13 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#botcommandscopeallchatadministrators /// /// [scope]: https://core.telegram.org/bots/api#botcommandscope -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class BotCommandScopeAllChatAdministrators implements BotCommandScope { @override String type; BotCommandScopeAllChatAdministrators( - {this.type = BotCommandScope.ALL_CHAT_ADMINISTRATORS}); + {this.type = BotCommandScope.typeAllChatAdministrators}); factory BotCommandScopeAllChatAdministrators.fromJson( Map json) => diff --git a/lib/src/telegram/models/bot_command_scope_all_group_chats.dart b/lib/src/telegram/models/bot_command_scope_all_group_chats.dart index 4e723bea..8d7ac748 100644 --- a/lib/src/telegram/models/bot_command_scope_all_group_chats.dart +++ b/lib/src/telegram/models/bot_command_scope_all_group_chats.dart @@ -23,12 +23,12 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#botcommandscopeallgroupchats /// /// [scope]: https://core.telegram.org/bots/api#botcommandscope -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class BotCommandScopeAllGroupChats implements BotCommandScope { @override String type; - BotCommandScopeAllGroupChats({this.type = BotCommandScope.ALL_GROUP_CHATS}); + BotCommandScopeAllGroupChats({this.type = BotCommandScope.typeAllGroupChats}); factory BotCommandScopeAllGroupChats.fromJson(Map json) => _$BotCommandScopeAllGroupChatsFromJson(json); diff --git a/lib/src/telegram/models/bot_command_scope_all_private_chats.dart b/lib/src/telegram/models/bot_command_scope_all_private_chats.dart index 2e38f435..905a205f 100644 --- a/lib/src/telegram/models/bot_command_scope_all_private_chats.dart +++ b/lib/src/telegram/models/bot_command_scope_all_private_chats.dart @@ -23,13 +23,13 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#botcommandscopeallprivatechats /// /// [scope]: https://core.telegram.org/bots/api#botcommandscope -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class BotCommandScopeAllPrivateChats implements BotCommandScope { @override String type; BotCommandScopeAllPrivateChats( - {this.type = BotCommandScope.ALL_PRIVATE_CHATS}); + {this.type = BotCommandScope.typeAllPrivateChats}); factory BotCommandScopeAllPrivateChats.fromJson(Map json) => _$BotCommandScopeAllPrivateChatsFromJson(json); diff --git a/lib/src/telegram/models/bot_command_scope_chat.dart b/lib/src/telegram/models/bot_command_scope_chat.dart index 76e264de..3298a8e1 100644 --- a/lib/src/telegram/models/bot_command_scope_chat.dart +++ b/lib/src/telegram/models/bot_command_scope_chat.dart @@ -23,15 +23,15 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#botcommandscopechat /// /// [scope]: https://core.telegram.org/bots/api#botcommandscope -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class BotCommandScopeChat implements BotCommandScope { @override String type; - dynamic chat_id; + dynamic chatId; BotCommandScopeChat({ - this.type = BotCommandScope.CHAT, - required this.chat_id, + this.type = BotCommandScope.typeChat, + required this.chatId, }); factory BotCommandScopeChat.fromJson(Map json) => diff --git a/lib/src/telegram/models/bot_command_scope_chat_administrators.dart b/lib/src/telegram/models/bot_command_scope_chat_administrators.dart index 70732e83..2e92dd9d 100644 --- a/lib/src/telegram/models/bot_command_scope_chat_administrators.dart +++ b/lib/src/telegram/models/bot_command_scope_chat_administrators.dart @@ -23,15 +23,15 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#botcommandscopechatadministrators /// /// [scope]: https://core.telegram.org/bots/api#botcommandscope -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class BotCommandScopeChatAdministrators implements BotCommandScope { @override String type; - dynamic chat_id; + dynamic chatId; BotCommandScopeChatAdministrators({ - this.type = BotCommandScope.CHAT_ADMINISTRATORS, - required this.chat_id, + this.type = BotCommandScope.typeAllChatAdministrators, + required this.chatId, }); factory BotCommandScopeChatAdministrators.fromJson( diff --git a/lib/src/telegram/models/bot_command_scope_chat_member.dart b/lib/src/telegram/models/bot_command_scope_chat_member.dart index 613cc736..a7eda4fa 100644 --- a/lib/src/telegram/models/bot_command_scope_chat_member.dart +++ b/lib/src/telegram/models/bot_command_scope_chat_member.dart @@ -23,15 +23,15 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#botcommandscopechatmember /// /// [scope]: https://core.telegram.org/bots/api#botcommandscope -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class BotCommandScopeChatMember implements BotCommandScope { @override String type; - dynamic chat_id; + dynamic chatId; BotCommandScopeChatMember({ - this.type = BotCommandScope.CHAT_MEMBER, - required this.chat_id, + this.type = BotCommandScope.typeChatMember, + required this.chatId, }); factory BotCommandScopeChatMember.fromJson(Map json) => diff --git a/lib/src/telegram/models/bot_command_scope_default.dart b/lib/src/telegram/models/bot_command_scope_default.dart index f5b0b9cd..77ad5ee8 100644 --- a/lib/src/telegram/models/bot_command_scope_default.dart +++ b/lib/src/telegram/models/bot_command_scope_default.dart @@ -26,12 +26,12 @@ part of '../model.dart'; /// /// [scope]: https://core.telegram.org/bots/api#botcommandscope /// [narrower scope]: https://core.telegram.org/bots/api#determining-list-of-commands -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class BotCommandScopeDefault implements BotCommandScope { @override String type; - BotCommandScopeDefault({this.type = BotCommandScope.DEFAULT}); + BotCommandScopeDefault({this.type = BotCommandScope.typeDefault}); factory BotCommandScopeDefault.fromJson(Map json) => _$BotCommandScopeDefaultFromJson(json); diff --git a/lib/src/telegram/models/bot_description.dart b/lib/src/telegram/models/bot_description.dart new file mode 100644 index 00000000..4ac2c27e --- /dev/null +++ b/lib/src/telegram/models/bot_description.dart @@ -0,0 +1,33 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object represents the bot's description. +/// +/// https://core.telegram.org/bots/api#botdescription +@JsonSerializable(fieldRename: FieldRename.snake) +class BotDescription { + String description; + BotDescription({ + required this.description, + }); + factory BotDescription.fromJson(Map json) => + _$BotDescriptionFromJson(json); + Map toJson() => _$BotDescriptionToJson(this); +} diff --git a/lib/src/telegram/models/bot_name.dart b/lib/src/telegram/models/bot_name.dart new file mode 100644 index 00000000..8352c92c --- /dev/null +++ b/lib/src/telegram/models/bot_name.dart @@ -0,0 +1,33 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object represents the bot's name +/// +/// https://core.telegram.org/bots/api#botname +@JsonSerializable(fieldRename: FieldRename.snake) +class BotName { + String name; + BotName({ + required this.name, + }); + factory BotName.fromJson(Map json) => + _$BotNameFromJson(json); + Map toJson() => _$BotNameToJson(this); +} diff --git a/lib/src/telegram/models/bot_short_description.dart b/lib/src/telegram/models/bot_short_description.dart new file mode 100644 index 00000000..f1eb799a --- /dev/null +++ b/lib/src/telegram/models/bot_short_description.dart @@ -0,0 +1,33 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object represents the bot's description. +/// +/// https://core.telegram.org/bots/api#botshortdescription +@JsonSerializable(fieldRename: FieldRename.snake) +class BotShortDescription { + String shortDescription; + BotShortDescription({ + required this.shortDescription, + }); + factory BotShortDescription.fromJson(Map json) => + _$BotShortDescriptionFromJson(json); + Map toJson() => _$BotShortDescriptionToJson(this); +} diff --git a/lib/src/telegram/models/callback_game.dart b/lib/src/telegram/models/callback_game.dart index c34e294c..9a2b19f4 100644 --- a/lib/src/telegram/models/callback_game.dart +++ b/lib/src/telegram/models/callback_game.dart @@ -25,7 +25,7 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#callbackgame /// /// [BotFather]: https://t.me/botfather -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class CallbackGame { CallbackGame(); factory CallbackGame.fromJson(Map json) => diff --git a/lib/src/telegram/models/callback_query.dart b/lib/src/telegram/models/callback_query.dart index 072b1b39..dd6935a7 100644 --- a/lib/src/telegram/models/callback_query.dart +++ b/lib/src/telegram/models/callback_query.dart @@ -36,23 +36,23 @@ part of '../model.dart'; /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [inline mode]: https://core.telegram.org/bots/api#inline-mode /// [answerCallbackQuery]: https://core.telegram.org/bots/api#answercallbackquery -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class CallbackQuery { String id; User from; Message? message; - String? inline_message_id; - String? chat_instance; + String? inlineMessageId; + String? chatInstance; String? data; - String? game_short_name; + String? gameShortName; CallbackQuery({ required this.id, required this.from, this.message, - this.inline_message_id, - this.chat_instance, + this.inlineMessageId, + this.chatInstance, this.data, - this.game_short_name, + this.gameShortName, }); factory CallbackQuery.fromJson(Map json) => _$CallbackQueryFromJson(json); diff --git a/lib/src/telegram/models/chat.dart b/lib/src/telegram/models/chat.dart index e7717212..6defc243 100644 --- a/lib/src/telegram/models/chat.dart +++ b/lib/src/telegram/models/chat.dart @@ -21,53 +21,75 @@ part of '../model.dart'; /// This object represents a chat. /// /// https://core.telegram.org/bots/api#chat -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class Chat { - static const PRIVATE = 'private'; - static const GROUP = 'group'; - static const SUPERGROUP = 'supergroup'; - static const CHANNEL = 'channel'; + static const typePrivate = 'private'; + static const typeGroup = 'group'; + static const typeSuperGroup = 'supergroup'; + static const typeChannel = 'channel'; int id; String type; String? title; String? username; - String? first_name; - String? last_name; + String? firstName; + String? lastName; + bool? isForum; ChatPhoto? photo; + List? activeUsernames; + String? emojiStatusCustomEmojiId; + String? emojiStatusExpirationDate; String? bio; - bool? has_private_forwards; + bool? hasPrivateForwards; + bool? hasRestrictedVoiceAndVideoMessages; + bool? joinToSendMessages; + bool? joinByRequest; String? description; - String? invite_link; - Message? pinned_message; + String? inviteLink; + Message? pinnedMessage; ChatPermissions? permissions; - int? slow_mode_delay; - bool? has_protected_content; - String? sticker_set_name; - bool? can_set_sticker_set; - int? linked_chat_id; + int? slowModeDelay; + int? messageAutoDeleteTime; + bool? hasAggressiveAntiSpamEnabled; + bool? hasHiddenMembers; + bool? hasProtectedContent; + String? stickerSetName; + bool? canSetStickerSet; + int? linkedChatId; ChatLocation? location; + Chat({ required this.id, required this.type, this.title, this.username, - this.first_name, - this.last_name, + this.firstName, + this.lastName, + this.isForum, this.photo, + this.activeUsernames, + this.emojiStatusCustomEmojiId, + this.emojiStatusExpirationDate, this.bio, - this.has_private_forwards, + this.hasPrivateForwards, + this.hasRestrictedVoiceAndVideoMessages, + this.joinToSendMessages, + this.joinByRequest, this.description, - this.invite_link, - this.pinned_message, + this.inviteLink, + this.pinnedMessage, this.permissions, - this.slow_mode_delay, - this.has_protected_content, - this.sticker_set_name, - this.can_set_sticker_set, - this.linked_chat_id, + this.slowModeDelay, + this.messageAutoDeleteTime, + this.hasAggressiveAntiSpamEnabled, + this.hasHiddenMembers, + this.hasProtectedContent, + this.stickerSetName, + this.canSetStickerSet, + this.linkedChatId, this.location, }); + factory Chat.fromJson(Map json) => _$ChatFromJson(json); Map toJson() => _$ChatToJson(this); } diff --git a/lib/src/telegram/models/chat_administrator_rights.dart b/lib/src/telegram/models/chat_administrator_rights.dart new file mode 100644 index 00000000..b8dda0aa --- /dev/null +++ b/lib/src/telegram/models/chat_administrator_rights.dart @@ -0,0 +1,58 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2022 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// Represents the rights of an administrator in a chat. +/// +/// https://core.telegram.org/bots/api#chatadministratorrights + +@JsonSerializable(fieldRename: FieldRename.snake) +class ChatAdministratorRights { + bool isAnonymous; + bool canManageChat; + bool canDeleteMessages; + bool canManageVideoChats; + bool canRestrictMembers; + bool canPromoteMembers; + bool canChangeInfo; + bool canInviteUsers; + bool? canPostMessages; + bool? canEditMessages; + bool? canPinMessages; + bool? canManageTopics; + + ChatAdministratorRights({ + this.isAnonymous = false, + this.canManageChat = false, + this.canDeleteMessages = false, + this.canManageVideoChats = false, + this.canRestrictMembers = false, + this.canPromoteMembers = false, + this.canChangeInfo = false, + this.canInviteUsers = false, + this.canPostMessages, + this.canEditMessages, + this.canPinMessages, + this.canManageTopics, + }); + + factory ChatAdministratorRights.fromJson(Map json) => + _$ChatAdministratorRightsFromJson(json); + Map toJson() => _$ChatAdministratorRightsToJson(this); +} diff --git a/lib/src/telegram/models/chat_invite_link.dart b/lib/src/telegram/models/chat_invite_link.dart index f4999b17..383fd592 100644 --- a/lib/src/telegram/models/chat_invite_link.dart +++ b/lib/src/telegram/models/chat_invite_link.dart @@ -21,35 +21,35 @@ part of '../model.dart'; /// Represents an invite link for a chat. /// /// https://core.telegram.org/bots/api#chatinvitelink -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ChatInviteLink { - String invite_link; + String inviteLink; User creator; - bool creates_join_request; - bool is_primary; - bool is_revoked; + bool createsJoinRequest; + bool isPrimary; + bool isRevoked; String? name; - int? expire_date; - int? member_limit; - int? pending_join_request_count; + int? expireDate; + int? memberLimit; + int? pendingJoinRequestCount; ChatInviteLink({ - required this.invite_link, + required this.inviteLink, required this.creator, - required this.creates_join_request, - required this.is_primary, - required this.is_revoked, + required this.createsJoinRequest, + required this.isPrimary, + required this.isRevoked, this.name, - this.expire_date, - this.member_limit, - this.pending_join_request_count, + this.expireDate, + this.memberLimit, + this.pendingJoinRequestCount, }); - @JsonKey(ignore: true) - DateTime? get expire_date_ => - expire_date == null ? null : TimeHelper.toDateTime(expire_date!); - set expire_date_(DateTime? dateTime) => - expire_date = dateTime == null ? null : TimeHelper.toUnixTime(dateTime); + @JsonKey(includeFromJson: false, includeToJson: false) + DateTime? get expireDate_ => + expireDate == null ? null : TimeHelper.toDateTime(expireDate!); + set expireDate_(DateTime? dateTime) => + expireDate = dateTime == null ? null : TimeHelper.toUnixTime(dateTime); factory ChatInviteLink.fromJson(Map json) => _$ChatInviteLinkFromJson(json); diff --git a/lib/src/telegram/models/chat_join_request.dart b/lib/src/telegram/models/chat_join_request.dart index 0e5a9d65..9847aa44 100644 --- a/lib/src/telegram/models/chat_join_request.dart +++ b/lib/src/telegram/models/chat_join_request.dart @@ -21,23 +21,25 @@ part of '../model.dart'; /// Represents a join request sent to a chat. /// /// https://core.telegram.org/bots/api#chatjoinrequest -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ChatJoinRequest { Chat chat; User from; + int userChatId; int date; String? bio; - ChatInviteLink? invite_link; + ChatInviteLink? inviteLink; ChatJoinRequest({ required this.chat, required this.from, + required this.userChatId, required this.date, this.bio, - this.invite_link, + this.inviteLink, }); - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) DateTime get date_ => TimeHelper.toDateTime(date); set date_(DateTime dateTime) => date = TimeHelper.toUnixTime(dateTime); diff --git a/lib/src/telegram/models/chat_location.dart b/lib/src/telegram/models/chat_location.dart index 455e535d..bd41cf41 100644 --- a/lib/src/telegram/models/chat_location.dart +++ b/lib/src/telegram/models/chat_location.dart @@ -21,7 +21,7 @@ part of '../model.dart'; /// Represents a location to which a chat is connected. /// /// https://core.telegram.org/bots/api#chatlocation -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ChatLocation { Location location; String address; diff --git a/lib/src/telegram/models/chat_member.dart b/lib/src/telegram/models/chat_member.dart index 070f5a82..5bd37211 100644 --- a/lib/src/telegram/models/chat_member.dart +++ b/lib/src/telegram/models/chat_member.dart @@ -30,7 +30,7 @@ part of '../model.dart'; /// /// https://core.telegram.org/bots/api#chatmember -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ChatMember { String status; User user; diff --git a/lib/src/telegram/models/chat_member_administrator.dart b/lib/src/telegram/models/chat_member_administrator.dart index 290a70de..7e29b38c 100644 --- a/lib/src/telegram/models/chat_member_administrator.dart +++ b/lib/src/telegram/models/chat_member_administrator.dart @@ -23,42 +23,44 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#chatmemberadministrator /// /// [chat member]: https://core.telegram.org/bots/api#chatmember -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ChatMemberAdministrator implements ChatMember { @override String status; @override User user; - bool can_be_edited; - bool is_anonymous; - bool can_manage_chat; - bool can_delete_messages; - bool can_manage_voice_chats; - bool can_restrict_members; - bool can_promote_members; - bool can_change_info; - bool can_invite_users; - bool? can_post_messages; - bool? can_edit_messages; - bool? can_pin_messages; - String? custom_title; + bool canBeEdited; + bool isAnonymous; + bool canManageChat; + bool canDeleteMessages; + bool canManageVideoChats; + bool canRestrictMembers; + bool canPromoteMembers; + bool canChangeInfo; + bool canInviteUsers; + bool? canPostMessages; + bool? canEditMessages; + bool? canPinMessages; + bool? canManageTopics; + String? customTitle; ChatMemberAdministrator({ required this.status, required this.user, - this.can_be_edited = false, - this.is_anonymous = false, - this.can_manage_chat = false, - this.can_delete_messages = false, - this.can_manage_voice_chats = false, - this.can_restrict_members = false, - this.can_promote_members = false, - this.can_change_info = false, - this.can_invite_users = false, - this.can_post_messages, - this.can_edit_messages, - this.can_pin_messages, - this.custom_title, + this.canBeEdited = false, + this.isAnonymous = false, + this.canManageChat = false, + this.canDeleteMessages = false, + this.canManageVideoChats = false, + this.canRestrictMembers = false, + this.canPromoteMembers = false, + this.canChangeInfo = false, + this.canInviteUsers = false, + this.canPostMessages, + this.canEditMessages, + this.canPinMessages, + this.canManageTopics, + this.customTitle, }); factory ChatMemberAdministrator.fromJson(Map json) => diff --git a/lib/src/telegram/models/chat_member_banned.dart b/lib/src/telegram/models/chat_member_banned.dart index b74001cb..09d6700f 100644 --- a/lib/src/telegram/models/chat_member_banned.dart +++ b/lib/src/telegram/models/chat_member_banned.dart @@ -24,24 +24,24 @@ part of '../model.dart'; /// /// [chat member]: https://core.telegram.org/bots/api#chatmember -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ChatMemberBanned implements ChatMember { @override String status; @override User user; - int until_date; + int untilDate; ChatMemberBanned({ required this.status, required this.user, - required this.until_date, + required this.untilDate, }); - @JsonKey(ignore: true) - DateTime get until_date_ => TimeHelper.toDateTime(until_date); - set until_date_(DateTime dateTime) => - until_date = TimeHelper.toUnixTime(dateTime); + @JsonKey(includeFromJson: false, includeToJson: false) + DateTime get untilDate_ => TimeHelper.toDateTime(untilDate); + set untilDate_(DateTime dateTime) => + untilDate = TimeHelper.toUnixTime(dateTime); factory ChatMemberBanned.fromJson(Map json) => _$ChatMemberBannedFromJson(json); diff --git a/lib/src/telegram/models/chat_member_left.dart b/lib/src/telegram/models/chat_member_left.dart index ac5e18b1..3a881c97 100644 --- a/lib/src/telegram/models/chat_member_left.dart +++ b/lib/src/telegram/models/chat_member_left.dart @@ -24,7 +24,7 @@ part of '../model.dart'; /// /// [chat member]: https://core.telegram.org/bots/api#chatmember -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ChatMemberLeft implements ChatMember { @override String status; diff --git a/lib/src/telegram/models/chat_member_member.dart b/lib/src/telegram/models/chat_member_member.dart index de5a8b37..580b9358 100644 --- a/lib/src/telegram/models/chat_member_member.dart +++ b/lib/src/telegram/models/chat_member_member.dart @@ -24,7 +24,7 @@ part of '../model.dart'; /// /// [chat member]: https://core.telegram.org/bots/api#chatmember -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ChatMemberMember implements ChatMember { @override String status; diff --git a/lib/src/telegram/models/chat_member_owner.dart b/lib/src/telegram/models/chat_member_owner.dart index 4fb0b824..b837894e 100644 --- a/lib/src/telegram/models/chat_member_owner.dart +++ b/lib/src/telegram/models/chat_member_owner.dart @@ -23,20 +23,20 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#chatmemberowner /// /// [chat member]: https://core.telegram.org/bots/api#chatmember -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ChatMemberOwner implements ChatMember { @override String status; @override User user; - bool is_anonymous; - String? custom_title; + bool isAnonymous; + String? customTitle; ChatMemberOwner({ required this.user, required this.status, - required this.is_anonymous, - this.custom_title, + required this.isAnonymous, + this.customTitle, }); factory ChatMemberOwner.fromJson(Map json) => diff --git a/lib/src/telegram/models/chat_member_restricted.dart b/lib/src/telegram/models/chat_member_restricted.dart index c89528e9..908e7e24 100644 --- a/lib/src/telegram/models/chat_member_restricted.dart +++ b/lib/src/telegram/models/chat_member_restricted.dart @@ -24,42 +24,54 @@ part of '../model.dart'; /// /// [chat member]: https://core.telegram.org/bots/api#chatmember -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ChatMemberRestricted implements ChatMember { @override String status; @override User user; - bool is_member; - bool can_change_info; - bool can_invite_users; - bool can_pin_messages; - bool can_send_messages; - bool can_send_media_messages; - bool can_send_polls; - bool can_send_other_messages; - bool can_add_web_page_previews; - int until_date; + bool isMember; + bool canChangeInfo; + bool canInviteUsers; + bool canPinMessages; + bool canManageTopics; + bool canSendMessages; + bool? canSendAudios; + bool? canSendDocuments; + bool? canSendPhotos; + bool? canSendVideos; + bool? canSendVideoNotes; + bool? canSendVoiceNotes; + bool canSendPolls; + bool canSendOtherMessages; + bool canAddWebPagePreviews; + int untilDate; ChatMemberRestricted({ required this.status, required this.user, - this.is_member = false, - this.can_change_info = false, - this.can_invite_users = false, - this.can_pin_messages = false, - this.can_send_messages = false, - this.can_send_media_messages = false, - this.can_send_polls = false, - this.can_send_other_messages = false, - this.can_add_web_page_previews = false, - required this.until_date, + this.isMember = false, + this.canChangeInfo = false, + this.canInviteUsers = false, + this.canPinMessages = false, + this.canManageTopics = false, + this.canSendMessages = false, + this.canSendAudios = false, + this.canSendDocuments = false, + this.canSendPhotos = false, + this.canSendVideos = false, + this.canSendVideoNotes = false, + this.canSendVoiceNotes = false, + this.canSendPolls = false, + this.canSendOtherMessages = false, + this.canAddWebPagePreviews = false, + required this.untilDate, }); - @JsonKey(ignore: true) - DateTime get until_date_ => TimeHelper.toDateTime(until_date); - set until_date_(DateTime dateTime) => - until_date = TimeHelper.toUnixTime(dateTime); + @JsonKey(includeFromJson: false, includeToJson: false) + DateTime get untilDate_ => TimeHelper.toDateTime(untilDate); + set untilDate_(DateTime dateTime) => + untilDate = TimeHelper.toUnixTime(dateTime); factory ChatMemberRestricted.fromJson(Map json) => _$ChatMemberRestrictedFromJson(json); diff --git a/lib/src/telegram/models/chat_member_updated.dart b/lib/src/telegram/models/chat_member_updated.dart index fdf9e83a..e6fb931e 100644 --- a/lib/src/telegram/models/chat_member_updated.dart +++ b/lib/src/telegram/models/chat_member_updated.dart @@ -21,24 +21,27 @@ part of '../model.dart'; /// This object represents changes in the status of a chat member. /// /// https://core.telegram.org/bots/api#chatmemberupdated -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ChatMemberUpdated { Chat? chat; User? from; int? date; - ChatMember? old_chat_member; - ChatMember? new_chat_member; - ChatInviteLink? invite_link; + ChatMember? oldChatMember; + ChatMember? newChatMember; + ChatInviteLink? inviteLink; + bool? viaChatFolderInviteLink; ChatMemberUpdated({ this.chat, this.from, - this.old_chat_member, - this.new_chat_member, - this.invite_link, + this.oldChatMember, + this.newChatMember, + this.inviteLink, + this.viaChatFolderInviteLink, + this.date, }); - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) DateTime? get date_ => date == null ? null : TimeHelper.toDateTime(date!); set date_(DateTime? dateTime) => date = dateTime == null ? null : TimeHelper.toUnixTime(dateTime); diff --git a/lib/src/telegram/models/chat_permissions.dart b/lib/src/telegram/models/chat_permissions.dart index b9847606..92f75012 100644 --- a/lib/src/telegram/models/chat_permissions.dart +++ b/lib/src/telegram/models/chat_permissions.dart @@ -16,31 +16,47 @@ * along with this program. If not, see . */ +// can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and can_send_voice_notes + part of '../model.dart'; /// Describes actions that a non-administrator user is allowed to take in a chat. /// /// https://core.telegram.org/bots/api#chatpermissions -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ChatPermissions { - bool? can_send_messages; - bool? can_send_media_messages; - bool? can_send_polls; - bool? can_send_other_messages; - bool? can_add_web_page_previews; - bool? can_change_info; - bool? can_invite_users; - bool? can_pin_messages; + bool? canSendMessages; + bool? canSendAudios; + bool? canSendDocuments; + bool? canSendPhotos; + bool? canSendVideos; + bool? canSendVideoNotes; + bool? canSendVoiceNotes; + bool? canSendPolls; + bool? canSendOtherMessages; + bool? canAddWebPagePreviews; + bool? canChangeInfo; + bool? canInviteUsers; + bool? canPinMessages; + bool? canManageTopics; + ChatPermissions({ - this.can_send_messages, - this.can_send_media_messages, - this.can_send_polls, - this.can_send_other_messages, - this.can_add_web_page_previews, - this.can_change_info, - this.can_invite_users, - this.can_pin_messages, + this.canSendMessages, + this.canSendAudios, + this.canSendDocuments, + this.canSendPhotos, + this.canSendVideos, + this.canSendVideoNotes, + this.canSendVoiceNotes, + this.canSendPolls, + this.canSendOtherMessages, + this.canAddWebPagePreviews, + this.canChangeInfo, + this.canInviteUsers, + this.canPinMessages, + this.canManageTopics, }); + factory ChatPermissions.fromJson(Map json) => _$ChatPermissionsFromJson(json); Map toJson() => _$ChatPermissionsToJson(this); diff --git a/lib/src/telegram/models/chat_photo.dart b/lib/src/telegram/models/chat_photo.dart index a3b94717..80cb90c6 100644 --- a/lib/src/telegram/models/chat_photo.dart +++ b/lib/src/telegram/models/chat_photo.dart @@ -21,17 +21,17 @@ part of '../model.dart'; /// This object represents a chat photo. /// /// https://core.telegram.org/bots/api#chatphoto -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ChatPhoto { - String small_file_id; - String small_file_unique_id; - String big_file_id; - String big_file_unique_id; + String smallFileId; + String smallFileUniqueId; + String bigFileId; + String bigFileUniqueId; ChatPhoto({ - required this.small_file_id, - required this.small_file_unique_id, - required this.big_file_id, - required this.big_file_unique_id, + required this.smallFileId, + required this.smallFileUniqueId, + required this.bigFileId, + required this.bigFileUniqueId, }); factory ChatPhoto.fromJson(Map json) => _$ChatPhotoFromJson(json); diff --git a/lib/src/telegram/models/chat_shared.dart b/lib/src/telegram/models/chat_shared.dart new file mode 100644 index 00000000..324de73b --- /dev/null +++ b/lib/src/telegram/models/chat_shared.dart @@ -0,0 +1,36 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object contains information about the chat whose identifier was +/// shared with the bot using a [KeyboardButtonRequestChat] button. +/// +/// https://core.telegram.org/bots/api#chatshared +@JsonSerializable(fieldRename: FieldRename.snake) +class ChatShared { + int requestId; + int userId; + ChatShared({ + required this.requestId, + required this.userId, + }); + factory ChatShared.fromJson(Map json) => + _$ChatSharedFromJson(json); + Map toJson() => _$ChatSharedToJson(this); +} diff --git a/lib/src/telegram/models/chosen_inline_result.dart b/lib/src/telegram/models/chosen_inline_result.dart index 32142785..90820af2 100644 --- a/lib/src/telegram/models/chosen_inline_result.dart +++ b/lib/src/telegram/models/chosen_inline_result.dart @@ -27,18 +27,18 @@ part of '../model.dart'; /// [result]: https://core.telegram.org/bots/api#inlinequeryresult /// [inline feedback]: https://core.telegram.org/bots/inline#collecting-feedback /// [@Botfather]: https://t.me/botfather -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ChosenInlineResult { - String result_id; + String resultId; User from; Location? location; - String? inline_message_id; + String? inlineMessageId; String query; ChosenInlineResult({ - required this.result_id, + required this.resultId, required this.from, this.location, - this.inline_message_id, + this.inlineMessageId, required this.query, }); factory ChosenInlineResult.fromJson(Map json) => diff --git a/lib/src/telegram/models/contact.dart b/lib/src/telegram/models/contact.dart index da614816..f121f8cd 100644 --- a/lib/src/telegram/models/contact.dart +++ b/lib/src/telegram/models/contact.dart @@ -21,18 +21,18 @@ part of '../model.dart'; /// This object represents a phone contact. /// /// https://core.telegram.org/bots/api#contact -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class Contact { - String phone_number; - String first_name; - String? last_name; - int? user_id; + String phoneNumber; + String firstName; + String? lastName; + int? userId; String? vcard; Contact({ - required this.phone_number, - required this.first_name, - this.last_name, - this.user_id, + required this.phoneNumber, + required this.firstName, + this.lastName, + this.userId, this.vcard, }); factory Contact.fromJson(Map json) => diff --git a/lib/src/telegram/models/dice.dart b/lib/src/telegram/models/dice.dart index 40de5b5e..59272324 100644 --- a/lib/src/telegram/models/dice.dart +++ b/lib/src/telegram/models/dice.dart @@ -21,14 +21,14 @@ part of '../model.dart'; /// This object represents an animated emoji that displays a random value. /// /// https://core.telegram.org/bots/api#dice -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class Dice { - static const String DICE = '🎲'; - static const String DART = '🎯'; - static const String BOWLING = '🎳'; - static const String BASKETBALL = '🏀'; - static const String FOOTBALL = '⚽'; - static const String SLOT_MACHINE = '🎰'; + static const emojiDice = '🎲'; + static const emojiDart = '🎯'; + static const emojiBowling = '🎳'; + static const emojiBasketball = '🏀'; + static const emojiFootball = '⚽'; + static const emojiSlotMachine = '🎰'; int value; String emoji; diff --git a/lib/src/telegram/models/document.dart b/lib/src/telegram/models/document.dart index 9b59eebf..f31d55dc 100644 --- a/lib/src/telegram/models/document.dart +++ b/lib/src/telegram/models/document.dart @@ -25,21 +25,21 @@ part of '../model.dart'; /// [photos]: https://core.telegram.org/bots/api#photosize /// [voice messages]: https://core.telegram.org/bots/api#voice /// [audio files]: https://core.telegram.org/bots/api#audio -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class Document { - String file_id; - String file_unique_id; - PhotoSize? thumb; - String? file_name; - String? mime_type; - int? file_size; + String fileId; + String fileUniqueId; + PhotoSize? thumbnail; + String? fileName; + String? mimeType; + int? fileSize; Document({ - required this.file_id, - required this.file_unique_id, - this.thumb, - this.file_name, - this.mime_type, - this.file_size, + required this.fileId, + required this.fileUniqueId, + this.thumbnail, + this.fileName, + this.mimeType, + this.fileSize, }); factory Document.fromJson(Map json) => _$DocumentFromJson(json); diff --git a/lib/src/telegram/models/encrypted_credentials.dart b/lib/src/telegram/models/encrypted_credentials.dart index 56182b14..73de6c49 100644 --- a/lib/src/telegram/models/encrypted_credentials.dart +++ b/lib/src/telegram/models/encrypted_credentials.dart @@ -26,7 +26,7 @@ part of '../model.dart'; /// /// [EncryptedPassportElement]: https://core.telegram.org/bots/api#encryptedpassportelement /// [Telegram Passport Documentation]: https://core.telegram.org/passport#receiving-information -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class EncryptedCredentials { String data; String hash; diff --git a/lib/src/telegram/models/encrypted_passport_element.dart b/lib/src/telegram/models/encrypted_passport_element.dart index 1d9c3293..1c57d1df 100644 --- a/lib/src/telegram/models/encrypted_passport_element.dart +++ b/lib/src/telegram/models/encrypted_passport_element.dart @@ -21,40 +21,40 @@ part of '../model.dart'; /// Contains information about documents or other Telegram Passport elements shared with the bot by the user. /// /// https://core.telegram.org/bots/api#encryptedpassportelement -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class EncryptedPassportElement { - static const PERSONAL_DETAILS = 'personal_details'; - static const PASSPORT = 'passport'; - static const DRIVER_LICENSE = 'driver_license'; - static const IDENTITY_CARD = 'identity_card'; - static const INTERNAL_PASSPORT = 'internal_passport'; - static const ADDRESS = 'address'; - static const UTILITY_BILL = 'utility_bill'; - static const BANK_STATEMENT = 'bank_statement'; - static const RENTAL_AGREEMENT = 'rental_agreement'; - static const PASSPORT_REGISTRATION = 'passport_registration'; - static const TEMPORARY_REGISTRATION = 'temporary_registration'; - static const PHONE_NUMBER = 'phone_number'; - static const EMAIL = 'email'; + static const typePersonalDetails = 'personal_details'; + static const typePassport = 'passport'; + static const typeDriverLicense = 'driver_license'; + static const typeIdentityCard = 'identity_card'; + static const typeInternalPassport = 'internal_passport'; + static const typeAddress = 'address'; + static const typeUtilityBill = 'utility_bill'; + static const typeBankStatement = 'bank_statement'; + static const typeRentalAgreement = 'rental_agreement'; + static const typePassportRegistration = 'passport_registration'; + static const typeTemporaryRegistration = 'temporary_registration'; + static const typePhoneNumber = 'phone_number'; + static const typeEmail = 'email'; String type; String? data; - String? phone_number; + String? phoneNumber; String? email; List? files; - PassportFile? front_side; - PassportFile? reverse_side; + PassportFile? frontSide; + PassportFile? reverseSide; PassportFile? selfie; List? translation; String hash; EncryptedPassportElement({ required this.type, this.data, - this.phone_number, + this.phoneNumber, this.email, this.files, - this.front_side, - this.reverse_side, + this.frontSide, + this.reverseSide, this.selfie, this.translation, required this.hash, diff --git a/lib/src/telegram/models/file.dart b/lib/src/telegram/models/file.dart index 01aef4d9..3f9fcdd3 100644 --- a/lib/src/telegram/models/file.dart +++ b/lib/src/telegram/models/file.dart @@ -29,22 +29,22 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#file /// /// [getFile]: https://core.telegram.org/bots/api#getfile -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class File { - String file_id; - String file_unique_id; - int? file_size; - String? file_path; + String fileId; + String fileUniqueId; + int? fileSize; + String? filePath; File({ - required this.file_id, - required this.file_unique_id, - this.file_size, - this.file_path, + required this.fileId, + required this.fileUniqueId, + this.fileSize, + this.filePath, }); - String? getDownloadLink(String token) => (file_path?.isEmpty ?? true) + String? getDownloadLink(String token) => (filePath?.isEmpty ?? true) ? null - : 'https://api.telegram.org/file/bot$token/$file_path'; + : 'https://api.telegram.org/file/bot$token/$filePath'; factory File.fromJson(Map json) => _$FileFromJson(json); Map toJson() => _$FileToJson(this); diff --git a/lib/src/telegram/models/force_reply.dart b/lib/src/telegram/models/force_reply.dart index a0be491c..cafd5eaa 100644 --- a/lib/src/telegram/models/force_reply.dart +++ b/lib/src/telegram/models/force_reply.dart @@ -45,14 +45,14 @@ part of '../model.dart'; /// [privacy mode]: https://core.telegram.org/bots#privacy-mode /// [poll bot]: https://t.me/PollBot /// [ForceReply]: https://core.telegram.org/bots/api#forcereply -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ForceReply implements ReplyMarkup { - bool force_reply = true; - String? input_field_placeholder; + bool forceReply = true; + String? inputFieldPlaceholder; bool? selective; ForceReply({ - required this.force_reply, - this.input_field_placeholder, + required this.forceReply, + this.inputFieldPlaceholder, this.selective, }); factory ForceReply.fromJson(Map json) => diff --git a/lib/src/telegram/models/forum_topic.dart b/lib/src/telegram/models/forum_topic.dart new file mode 100644 index 00000000..0e5c5464 --- /dev/null +++ b/lib/src/telegram/models/forum_topic.dart @@ -0,0 +1,41 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2022 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object represents a forum topic. +/// +/// https://core.telegram.org/bots/api#forumtopic +@JsonSerializable(fieldRename: FieldRename.snake) +class ForumTopic { + String messageThreadId; + String name; + int iconColor; + String? iconCustomEmojiId; + + ForumTopic({ + required this.messageThreadId, + required this.name, + required this.iconColor, + this.iconCustomEmojiId, + }); + + factory ForumTopic.fromJson(Map json) => + _$ForumTopicFromJson(json); + Map toJson() => _$ForumTopicToJson(this); +} diff --git a/lib/src/telegram/models/forum_topic_closed.dart b/lib/src/telegram/models/forum_topic_closed.dart new file mode 100644 index 00000000..450d78af --- /dev/null +++ b/lib/src/telegram/models/forum_topic_closed.dart @@ -0,0 +1,30 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2022 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object represents a service message about a forum topic closed in the chat. Currently holds no information. +/// +/// https://core.telegram.org/bots/api#forumtopicclosed +@JsonSerializable(fieldRename: FieldRename.snake) +class ForumTopicClosed { + ForumTopicClosed(); + factory ForumTopicClosed.fromJson(Map json) => + _$ForumTopicClosedFromJson(json); + Map toJson() => _$ForumTopicClosedToJson(this); +} diff --git a/lib/src/telegram/models/forum_topic_created.dart b/lib/src/telegram/models/forum_topic_created.dart new file mode 100644 index 00000000..5a6e801b --- /dev/null +++ b/lib/src/telegram/models/forum_topic_created.dart @@ -0,0 +1,37 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2022 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object represents a service message about a new forum topic created in the chat. +/// +/// https://core.telegram.org/bots/api#forumtopiccreated +@JsonSerializable(fieldRename: FieldRename.snake) +class ForumTopicCreated { + String name; + int iconColor; + String? iconCustomEmojiId; + ForumTopicCreated({ + required this.name, + required this.iconColor, + this.iconCustomEmojiId, + }); + factory ForumTopicCreated.fromJson(Map json) => + _$ForumTopicCreatedFromJson(json); + Map toJson() => _$ForumTopicCreatedToJson(this); +} diff --git a/lib/src/telegram/models/forum_topic_edited.dart b/lib/src/telegram/models/forum_topic_edited.dart new file mode 100644 index 00000000..f9dba13a --- /dev/null +++ b/lib/src/telegram/models/forum_topic_edited.dart @@ -0,0 +1,35 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object represents a service message about an edited forum topic. +/// +/// https://core.telegram.org/bots/api#forumtopicedited +@JsonSerializable(fieldRename: FieldRename.snake) +class ForumTopicEdited { + String? name; + String? iconCustomEmojiId; + ForumTopicEdited({ + this.name, + this.iconCustomEmojiId, + }); + factory ForumTopicEdited.fromJson(Map json) => + _$ForumTopicEditedFromJson(json); + Map toJson() => _$ForumTopicEditedToJson(this); +} diff --git a/lib/src/telegram/models/forum_topic_reopened.dart b/lib/src/telegram/models/forum_topic_reopened.dart new file mode 100644 index 00000000..118db483 --- /dev/null +++ b/lib/src/telegram/models/forum_topic_reopened.dart @@ -0,0 +1,30 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2022 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object represents a service message about a forum topic reopened in the chat. Currently holds no information. +/// +/// https://core.telegram.org/bots/api#forumtopicreopened +@JsonSerializable(fieldRename: FieldRename.snake) +class ForumTopicReopened { + ForumTopicReopened(); + factory ForumTopicReopened.fromJson(Map json) => + _$ForumTopicReopenedFromJson(json); + Map toJson() => _$ForumTopicReopenedToJson(this); +} diff --git a/lib/src/telegram/models/game.dart b/lib/src/telegram/models/game.dart index 7369486e..bb261514 100644 --- a/lib/src/telegram/models/game.dart +++ b/lib/src/telegram/models/game.dart @@ -23,20 +23,20 @@ part of '../model.dart'; /// Use BotFather to create and edit games, their short names will act as unique identifiers. /// /// https://core.telegram.org/bots/api#game -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class Game { String title; String description; List photo; String? text; - List? text_entities; + List? textEntities; Animation? animation; Game({ required this.title, required this.description, required this.photo, this.text, - this.text_entities, + this.textEntities, this.animation, }); factory Game.fromJson(Map json) => _$GameFromJson(json); diff --git a/lib/src/telegram/models/game_high_score.dart b/lib/src/telegram/models/game_high_score.dart index 73937430..582bfe78 100644 --- a/lib/src/telegram/models/game_high_score.dart +++ b/lib/src/telegram/models/game_high_score.dart @@ -21,7 +21,7 @@ part of '../model.dart'; /// This object represents one row of the high scores table for a game. /// /// https://core.telegram.org/bots/api#gamehighscore -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class GameHighScore { int position; User user; diff --git a/lib/src/telegram/models/general_forum_topic_hidden.dart b/lib/src/telegram/models/general_forum_topic_hidden.dart new file mode 100644 index 00000000..809bd944 --- /dev/null +++ b/lib/src/telegram/models/general_forum_topic_hidden.dart @@ -0,0 +1,32 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object represents a service message about General forum topic hidden in the chat. +/// +/// Currently holds no information. +/// +/// https://core.telegram.org/bots/api#generalforumtopichidden +@JsonSerializable(fieldRename: FieldRename.snake) +class GeneralForumTopicHidden { + GeneralForumTopicHidden(); + factory GeneralForumTopicHidden.fromJson(Map json) => + _$GeneralForumTopicHiddenFromJson(json); + Map toJson() => _$GeneralForumTopicHiddenToJson(this); +} diff --git a/lib/src/telegram/models/general_forum_topic_unhidden.dart b/lib/src/telegram/models/general_forum_topic_unhidden.dart new file mode 100644 index 00000000..0572578a --- /dev/null +++ b/lib/src/telegram/models/general_forum_topic_unhidden.dart @@ -0,0 +1,32 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object represents a service message about General forum topic unhidden in the chat. +/// +/// Currently holds no information. +/// +/// https://core.telegram.org/bots/api#generalforumtopicunhidden +@JsonSerializable(fieldRename: FieldRename.snake) +class GeneralForumTopicUnhidden { + GeneralForumTopicUnhidden(); + factory GeneralForumTopicUnhidden.fromJson(Map json) => + _$GeneralForumTopicUnhiddenFromJson(json); + Map toJson() => _$GeneralForumTopicUnhiddenToJson(this); +} diff --git a/lib/src/telegram/models/inline_keyboard_button.dart b/lib/src/telegram/models/inline_keyboard_button.dart index b611fb71..71476982 100644 --- a/lib/src/telegram/models/inline_keyboard_button.dart +++ b/lib/src/telegram/models/inline_keyboard_button.dart @@ -23,25 +23,29 @@ part of '../model.dart'; /// You **must** use exactly one of the optional fields. /// /// https://core.telegram.org/bots/api#inlinekeyboardbutton -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineKeyboardButton { String text; String? url; - LoginUrl? login_url; - String? callback_data; - String? switch_inline_query; - String? switch_inline_query_current_chat; - CallbackGame? callback_game; + String? callbackData; + WebAppInfo? webApp; + LoginUrl? loginUrl; + String? switchInlineQuery; + String? switchInlineQueryCurrentChat; + CallbackGame? callbackGame; bool? pay; + SwitchInlineQueryChosenChat? switchInlineQueryChosenChat; InlineKeyboardButton({ required this.text, this.url, - this.login_url, - this.callback_data, - this.switch_inline_query, - this.switch_inline_query_current_chat, - this.callback_game, + this.callbackData, + this.webApp, + this.loginUrl, + this.switchInlineQuery, + this.switchInlineQueryCurrentChat, + this.callbackGame, this.pay, + this.switchInlineQueryChosenChat, }); factory InlineKeyboardButton.fromJson(Map json) => _$InlineKeyboardButtonFromJson(json); diff --git a/lib/src/telegram/models/inline_keyboard_markup.dart b/lib/src/telegram/models/inline_keyboard_markup.dart index 689b32a3..283a5e74 100644 --- a/lib/src/telegram/models/inline_keyboard_markup.dart +++ b/lib/src/telegram/models/inline_keyboard_markup.dart @@ -26,11 +26,11 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#inlinekeyboardmarkup /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineKeyboardMarkup implements ReplyMarkup { - List> inline_keyboard; + List> inlineKeyboard; InlineKeyboardMarkup({ - required this.inline_keyboard, + required this.inlineKeyboard, }); factory InlineKeyboardMarkup.fromJson(Map json) => _$InlineKeyboardMarkupFromJson(json); diff --git a/lib/src/telegram/models/inline_query.dart b/lib/src/telegram/models/inline_query.dart index e0244d29..ed04ed73 100644 --- a/lib/src/telegram/models/inline_query.dart +++ b/lib/src/telegram/models/inline_query.dart @@ -24,20 +24,20 @@ part of '../model.dart'; /// your bot could return some default or trending results. /// /// https://core.telegram.org/bots/api#inlinequery -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQuery { String id; User from; String query; String offset; - String? chat_type; + String? chatType; Location? location; InlineQuery({ required this.id, required this.from, required this.query, required this.offset, - this.chat_type, + this.chatType, this.location, }); factory InlineQuery.fromJson(Map json) => diff --git a/lib/src/telegram/models/inline_query_result.dart b/lib/src/telegram/models/inline_query_result.dart index b0261975..03a1ef6e 100644 --- a/lib/src/telegram/models/inline_query_result.dart +++ b/lib/src/telegram/models/inline_query_result.dart @@ -43,29 +43,29 @@ part of '../model.dart'; /// * [InlineQueryResultVoice](https://core.telegram.org/bots/api#inlinequeryresultvoice) /// /// https://core.telegram.org/bots/api#inlinequeryresult -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResult { - static const ARTICLE = 'article'; - static const AUDIO = 'audio'; - static const DOCUMENT = 'document'; - static const GIF = 'gif'; - static const MPEG4_GIF = 'mpeg4_gif'; - static const PHOTO = 'photo'; - static const STICKER = 'sticker'; - static const VIDEO = 'video'; - static const VOICE = 'voice'; - static const CONTACT = 'contact'; - static const GAME = 'game'; - static const LOCATION = 'location'; - static const VENUE = 'venue'; + static const typeArticle = 'article'; + static const typeAudio = 'audio'; + static const typeDocument = 'document'; + static const typeGif = 'gif'; + static const typeMpeg4Gif = 'mpeg4_gif'; + static const typePhoto = 'photo'; + static const typeSticker = 'sticker'; + static const typeVideo = 'video'; + static const typeVoice = 'voice'; + static const typeContact = 'contact'; + static const typeGame = 'game'; + static const typeLocation = 'location'; + static const typeVenue = 'venue'; String type; String id; - InlineKeyboardMarkup? reply_markup; + InlineKeyboardMarkup? replyMarkup; InlineQueryResult({ required this.type, required this.id, - this.reply_markup, + this.replyMarkup, }); factory InlineQueryResult.fromJson(Map json) => _$InlineQueryResultFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_article.dart b/lib/src/telegram/models/inline_query_result_article.dart index 0651c46d..daf4776a 100644 --- a/lib/src/telegram/models/inline_query_result_article.dart +++ b/lib/src/telegram/models/inline_query_result_article.dart @@ -21,34 +21,34 @@ part of '../model.dart'; /// Represents a link to an article or web page. /// /// https://core.telegram.org/bots/api#inlinequeryresultarticle -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultArticle implements InlineQueryResult { @override String id; @override String type; String title; - InputMessageContent input_message_content; + InputMessageContent inputMessageContent; @override - InlineKeyboardMarkup? reply_markup; + InlineKeyboardMarkup? replyMarkup; String? url; - bool? hide_url; + bool? hideUrl; String? description; - String? thumb_url; - String? thumb_width; - String? thumb_height; + String? thumbnailUrl; + String? thumbnailWidth; + String? thumbnailHeight; InlineQueryResultArticle({ required this.id, - this.type = InlineQueryResult.ARTICLE, + this.type = InlineQueryResult.typeArticle, required this.title, - required this.input_message_content, - this.reply_markup, + required this.inputMessageContent, + this.replyMarkup, this.url, - this.hide_url, + this.hideUrl, this.description, - this.thumb_url, - this.thumb_width, - this.thumb_height, + this.thumbnailUrl, + this.thumbnailWidth, + this.thumbnailHeight, }); factory InlineQueryResultArticle.fromJson(Map json) => _$InlineQueryResultArticleFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_audio.dart b/lib/src/telegram/models/inline_query_result_audio.dart index 848ccd96..45a0a36b 100644 --- a/lib/src/telegram/models/inline_query_result_audio.dart +++ b/lib/src/telegram/models/inline_query_result_audio.dart @@ -22,48 +22,48 @@ part of '../model.dart'; /// /// By default, this audio file will be sent by the user. /// Alternatively, -/// you can use *input_message_content* to send a message with the specified content instead of the audio. +/// you can use *inputMessageContent* to send a message with the specified content instead of the audio. /// /// **Note:** This will only work in Telegram versions released after 9 April, 2016. /// Older clients will ignore them. /// /// https://core.telegram.org/bots/api#inlinequeryresultaudio -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultAudio implements InlineQueryResult { @override String id; @override String type; - String audio_url; + String audioUrl; String title; String? caption; - String? parse_mode; + String? parseMode; String? performer; - int? audio_duration; - List? caption_entities; + int? audioDuration; + List? captionEntities; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; InlineQueryResultAudio({ required this.id, - this.type = InlineQueryResult.AUDIO, - required this.audio_url, + this.type = InlineQueryResult.typeAudio, + required this.audioUrl, required this.title, this.caption, - this.parse_mode, + this.parseMode, this.performer, - this.audio_duration, - this.caption_entities, - this.reply_markup, - this.input_message_content, + this.audioDuration, + this.captionEntities, + this.replyMarkup, + this.inputMessageContent, }); - @JsonKey(ignore: true) - Duration? get audio_duration_ => - audio_duration == null ? null : TimeHelper.toDuration(audio_duration!); - set audio_duration_(Duration? duration) => - audio_duration = duration == null ? null : TimeHelper.toSeconds(duration); + @JsonKey(includeFromJson: false, includeToJson: false) + Duration? get audioDuration_ => + audioDuration == null ? null : TimeHelper.toDuration(audioDuration!); + set audioDuration_(Duration? duration) => + audioDuration = duration == null ? null : TimeHelper.toSeconds(duration); factory InlineQueryResultAudio.fromJson(Map json) => _$InlineQueryResultAudioFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_cached_audio.dart b/lib/src/telegram/models/inline_query_result_cached_audio.dart index 87ba2f92..1ad909f0 100644 --- a/lib/src/telegram/models/inline_query_result_cached_audio.dart +++ b/lib/src/telegram/models/inline_query_result_cached_audio.dart @@ -21,35 +21,35 @@ part of '../model.dart'; /// Represents a link to an mp3 audio file stored on the Telegram servers. /// /// By default, this audio file will be sent by the user. -/// Alternatively, you can use *input_message_content* to +/// Alternatively, you can use *inputMessageContent* to /// send a message with the specified content instead of the audio. /// /// **Note:** This will only work in Telegram versions released after 9 April, 2016. /// Older clients will ignore them /// /// https://core.telegram.org/bots/api#inlinequeryresultcachedaudio -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultCachedAudio implements InlineQueryResult { @override String id; @override String type; - String audio_file_id; + String audioFileId; String? caption; - String? parse_mode; - List? caption_entities; + String? parseMode; + List? captionEntities; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; InlineQueryResultCachedAudio({ required this.id, - this.type = InlineQueryResult.AUDIO, - required this.audio_file_id, + this.type = InlineQueryResult.typeAudio, + required this.audioFileId, this.caption, - this.parse_mode, - this.caption_entities, - this.reply_markup, - this.input_message_content, + this.parseMode, + this.captionEntities, + this.replyMarkup, + this.inputMessageContent, }); factory InlineQueryResultCachedAudio.fromJson(Map json) => _$InlineQueryResultCachedAudioFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_cached_document.dart b/lib/src/telegram/models/inline_query_result_cached_document.dart index c1e8297a..f25180d6 100644 --- a/lib/src/telegram/models/inline_query_result_cached_document.dart +++ b/lib/src/telegram/models/inline_query_result_cached_document.dart @@ -22,38 +22,38 @@ part of '../model.dart'; /// /// By default, this file will be sent by the user with an optional caption. /// Alternatively, -/// you can use *input_message_content* to send a message with the specified content instead of the file. +/// you can use *inputMessageContent* to send a message with the specified content instead of the file. /// /// **Note:** This will only work in Telegram versions released after 9 April, 2016. /// Older clients will ignore them. /// /// https://core.telegram.org/bots/api#inlinequeryresultcacheddocument -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultCachedDocument implements InlineQueryResult { @override String id; @override String type; String title; - String document_file_id; + String documentFileId; String? description; String? caption; - String? parse_mode; - List? caption_entities; + String? parseMode; + List? captionEntities; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; InlineQueryResultCachedDocument({ required this.id, - this.type = InlineQueryResult.DOCUMENT, + this.type = InlineQueryResult.typeDocument, required this.title, - required this.document_file_id, + required this.documentFileId, this.description, this.caption, - this.parse_mode, - this.caption_entities, - this.reply_markup, - this.input_message_content, + this.parseMode, + this.captionEntities, + this.replyMarkup, + this.inputMessageContent, }); factory InlineQueryResultCachedDocument.fromJson(Map json) => _$InlineQueryResultCachedDocumentFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_cached_gif.dart b/lib/src/telegram/models/inline_query_result_cached_gif.dart index 068f9b2b..5c35d74b 100644 --- a/lib/src/telegram/models/inline_query_result_cached_gif.dart +++ b/lib/src/telegram/models/inline_query_result_cached_gif.dart @@ -22,33 +22,33 @@ part of '../model.dart'; /// /// By default, this animated GIF file will be sent by the user with an optional caption. /// Alternatively, -/// you can use *input_message_content* to send a message with specified content instead of the animation. +/// you can use *inputMessageContent* to send a message with specified content instead of the animation. /// /// https://core.telegram.org/bots/api#inlinequeryresultcachedgif -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultCachedGif implements InlineQueryResult { @override String id; @override String type; - String gif_file_id; + String gifFileId; String? title; String? caption; - String? parse_mode; - List? caption_entities; + String? parseMode; + List? captionEntities; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; InlineQueryResultCachedGif({ required this.id, - this.type = InlineQueryResult.GIF, - required this.gif_file_id, + this.type = InlineQueryResult.typeGif, + required this.gifFileId, this.title, this.caption, - this.parse_mode, - this.caption_entities, - this.reply_markup, - this.input_message_content, + this.parseMode, + this.captionEntities, + this.replyMarkup, + this.inputMessageContent, }); factory InlineQueryResultCachedGif.fromJson(Map json) => _$InlineQueryResultCachedGifFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_cached_mpeg4_gif.dart b/lib/src/telegram/models/inline_query_result_cached_mpeg4_gif.dart index a7f293ca..760b50e3 100644 --- a/lib/src/telegram/models/inline_query_result_cached_mpeg4_gif.dart +++ b/lib/src/telegram/models/inline_query_result_cached_mpeg4_gif.dart @@ -22,33 +22,33 @@ part of '../model.dart'; /// /// By default, this animated MPEG-4 file will be sent by the user with an optional caption. /// Alternatively, -/// you can use *input_message_content* to send a message with the specified content instead of the animation. +/// you can use *inputMessageContent* to send a message with the specified content instead of the animation. /// /// https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultCachedMpeg4Gif implements InlineQueryResult { @override String id; @override String type; - String mpeg4_file_id; + String mpeg4FileId; String? title; String? caption; - String? parse_mode; - List? caption_entities; + String? parseMode; + List? captionEntities; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; InlineQueryResultCachedMpeg4Gif({ required this.id, - this.type = InlineQueryResult.MPEG4_GIF, - required this.mpeg4_file_id, + this.type = InlineQueryResult.typeMpeg4Gif, + required this.mpeg4FileId, this.title, this.caption, - this.parse_mode, - this.caption_entities, - this.reply_markup, - this.input_message_content, + this.parseMode, + this.captionEntities, + this.replyMarkup, + this.inputMessageContent, }); factory InlineQueryResultCachedMpeg4Gif.fromJson(Map json) => _$InlineQueryResultCachedMpeg4GifFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_cached_photo.dart b/lib/src/telegram/models/inline_query_result_cached_photo.dart index 015b170e..9b2e7a12 100644 --- a/lib/src/telegram/models/inline_query_result_cached_photo.dart +++ b/lib/src/telegram/models/inline_query_result_cached_photo.dart @@ -22,35 +22,35 @@ part of '../model.dart'; /// /// By default, this photo will be sent by the user with an optional caption. /// Alternatively, -/// you can use *input_message_content* to send a message with the specified content instead of the photo. +/// you can use *inputMessageContent* to send a message with the specified content instead of the photo. /// /// https://core.telegram.org/bots/api#inlinequeryresultcachedphoto -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultCachedPhoto implements InlineQueryResult { @override String id; @override String type; - String photo_file_id; + String photoFileId; String? title; String? description; String? caption; - String? parse_mode; - List? caption_entities; + String? parseMode; + List? captionEntities; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; InlineQueryResultCachedPhoto({ required this.id, - this.type = InlineQueryResult.PHOTO, - required this.photo_file_id, + this.type = InlineQueryResult.typePhoto, + required this.photoFileId, this.title, this.description, this.caption, - this.parse_mode, - this.caption_entities, - this.reply_markup, - this.input_message_content, + this.parseMode, + this.captionEntities, + this.replyMarkup, + this.inputMessageContent, }); factory InlineQueryResultCachedPhoto.fromJson(Map json) => _$InlineQueryResultCachedPhotoFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_cached_sticker.dart b/lib/src/telegram/models/inline_query_result_cached_sticker.dart index 4ee904b8..72b7fce6 100644 --- a/lib/src/telegram/models/inline_query_result_cached_sticker.dart +++ b/lib/src/telegram/models/inline_query_result_cached_sticker.dart @@ -22,28 +22,28 @@ part of '../model.dart'; /// /// By default, this sticker will be sent by the user. /// Alternatively, -/// you can use *input_message_content* to send a message with the specified content instead of the sticker. +/// you can use *inputMessageContent* to send a message with the specified content instead of the sticker. /// /// **Note:** This will only work in Telegram versions released after 9 April, 2016. /// Older clients will ignore them. /// /// https://core.telegram.org/bots/api#inlinequeryresultcachedsticker -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultCachedSticker implements InlineQueryResult { @override String id; @override String type; - String? sticker_file_id; + String? stickerFileId; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; InlineQueryResultCachedSticker({ required this.id, - this.type = InlineQueryResult.STICKER, - required this.sticker_file_id, - this.reply_markup, - this.input_message_content, + this.type = InlineQueryResult.typeSticker, + required this.stickerFileId, + this.replyMarkup, + this.inputMessageContent, }); factory InlineQueryResultCachedSticker.fromJson(Map json) => _$InlineQueryResultCachedStickerFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_cached_video.dart b/lib/src/telegram/models/inline_query_result_cached_video.dart index b1b80b72..5ae601c5 100644 --- a/lib/src/telegram/models/inline_query_result_cached_video.dart +++ b/lib/src/telegram/models/inline_query_result_cached_video.dart @@ -22,35 +22,35 @@ part of '../model.dart'; /// /// By default, this video file will be sent by the user with an optional caption. /// Alternatively, -/// you can use *input_message_content* to send a message with the specified content instead of the video. +/// you can use *inputMessageContent* to send a message with the specified content instead of the video. /// /// https://core.telegram.org/bots/api#inlinequeryresultcachedvideo -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultCachedVideo implements InlineQueryResult { @override String id; @override String type; - String video_file_id; + String videoFileId; String title; String? description; String? caption; - String? parse_mode; - List? caption_entities; + String? parseMode; + List? captionEntities; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; InlineQueryResultCachedVideo({ required this.id, - this.type = InlineQueryResult.VIDEO, - required this.video_file_id, + this.type = InlineQueryResult.typeVideo, + required this.videoFileId, required this.title, this.description, this.caption, - this.parse_mode, - this.caption_entities, - this.reply_markup, - this.input_message_content, + this.parseMode, + this.captionEntities, + this.replyMarkup, + this.inputMessageContent, }); factory InlineQueryResultCachedVideo.fromJson(Map json) => _$InlineQueryResultCachedVideoFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_cached_voice.dart b/lib/src/telegram/models/inline_query_result_cached_voice.dart index 7819876a..02bca974 100644 --- a/lib/src/telegram/models/inline_query_result_cached_voice.dart +++ b/lib/src/telegram/models/inline_query_result_cached_voice.dart @@ -22,36 +22,36 @@ part of '../model.dart'; /// /// By default, this voice message will be sent by the user. /// Alternatively, -/// you can use *input_message_content* to send a message with the specified content instead of the voice message. +/// you can use *inputMessageContent* to send a message with the specified content instead of the voice message. /// /// **Note:** This will only work in Telegram versions released after 9 April, 2016. /// Older clients will ignore them /// /// https://core.telegram.org/bots/api#inlinequeryresultcachedvoice -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultCachedVoice implements InlineQueryResult { @override String id; @override String type; - String voice_file_id; + String voiceFileId; String title; String? caption; - String? parse_mode; - List? caption_entities; + String? parseMode; + List? captionEntities; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; InlineQueryResultCachedVoice({ required this.id, - this.type = InlineQueryResult.VOICE, - required this.voice_file_id, + this.type = InlineQueryResult.typeVoice, + required this.voiceFileId, required this.title, this.caption, - this.parse_mode, - this.caption_entities, - this.reply_markup, - this.input_message_content, + this.parseMode, + this.captionEntities, + this.replyMarkup, + this.inputMessageContent, }); factory InlineQueryResultCachedVoice.fromJson(Map json) => _$InlineQueryResultCachedVoiceFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_contact.dart b/lib/src/telegram/models/inline_query_result_contact.dart index dff68fa7..5b1154fe 100644 --- a/lib/src/telegram/models/inline_query_result_contact.dart +++ b/lib/src/telegram/models/inline_query_result_contact.dart @@ -22,40 +22,40 @@ part of '../model.dart'; /// /// By default, the contact will be sent by the user. /// Alternatively, -/// you can use *input_message_content* to send a message with the specified content instead of the contact. +/// you can use *inputMessageContent* to send a message with the specified content instead of the contact. /// /// **Note:** This will only work in Telegram versions released after 9 April, 2016. /// Older clients will ignore them. /// /// https://core.telegram.org/bots/api#inlinequeryresultcontact -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultContact implements InlineQueryResult { @override String id; @override String type; - String phone_number; - String first_name; - String? last_name; + String phoneNumber; + String firstName; + String? lastName; String? vcard; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; - String? thumb_url; - int? thumb_width; - int? thumb_height; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; + String? thumbnailUrl; + int? thumbnailWidth; + int? thumbnailHeight; InlineQueryResultContact({ required this.id, - this.type = InlineQueryResult.CONTACT, - required this.phone_number, - required this.first_name, - this.last_name, + this.type = InlineQueryResult.typeContact, + required this.phoneNumber, + required this.firstName, + this.lastName, this.vcard, - this.reply_markup, - this.input_message_content, - this.thumb_url, - this.thumb_width, - this.thumb_height, + this.replyMarkup, + this.inputMessageContent, + this.thumbnailUrl, + this.thumbnailWidth, + this.thumbnailHeight, }); factory InlineQueryResultContact.fromJson(Map json) => _$InlineQueryResultContactFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_document.dart b/lib/src/telegram/models/inline_query_result_document.dart index 1735bf7d..9d933726 100644 --- a/lib/src/telegram/models/inline_query_result_document.dart +++ b/lib/src/telegram/models/inline_query_result_document.dart @@ -21,14 +21,14 @@ part of '../model.dart'; /// Represents a link to a file. By default, this file will be sent by the user with an optional caption. /// /// Alternatively, -/// you can use *input_message_content* to send a message with the specified content instead of the file. +/// you can use *inputMessageContent* to send a message with the specified content instead of the file. /// Currently, only **.PDF** and **.ZIP** files can be sent using this method. /// /// **Note:** This will only work in Telegram versions released after 9 April, 2016. /// Older clients will ignore them. /// /// https://core.telegram.org/bots/api#inlinequeryresultdocument -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultDocument implements InlineQueryResult { @override String id; @@ -36,32 +36,32 @@ class InlineQueryResultDocument implements InlineQueryResult { String type; String title; String? caption; - String? parse_mode; - List? caption_entities; - String document_url; - String mime_type; + String? parseMode; + List? captionEntities; + String documentUrl; + String mimeType; String? description; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; - String? thumb_url; - int? thumb_width; - int? thumb_height; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; + String? thumbnailUrl; + int? thumbnailWidth; + int? thumbnailHeight; InlineQueryResultDocument({ required this.id, - this.type = InlineQueryResult.DOCUMENT, + this.type = InlineQueryResult.typeDocument, required this.title, this.caption, - this.parse_mode, - this.caption_entities, - required this.document_url, - required this.mime_type, + this.parseMode, + this.captionEntities, + required this.documentUrl, + required this.mimeType, this.description, - this.reply_markup, - this.input_message_content, - this.thumb_url, - this.thumb_width, - this.thumb_height, + this.replyMarkup, + this.inputMessageContent, + this.thumbnailUrl, + this.thumbnailWidth, + this.thumbnailHeight, }); factory InlineQueryResultDocument.fromJson(Map json) => _$InlineQueryResultDocumentFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_game.dart b/lib/src/telegram/models/inline_query_result_game.dart index 75606ff9..68a755c2 100644 --- a/lib/src/telegram/models/inline_query_result_game.dart +++ b/lib/src/telegram/models/inline_query_result_game.dart @@ -26,20 +26,20 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#inlinequeryresultgame /// /// [Game]: https://core.telegram.org/bots/api#games -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultGame implements InlineQueryResult { @override String id; @override String type; - String game_short_name; + String gameShortName; @override - InlineKeyboardMarkup? reply_markup; + InlineKeyboardMarkup? replyMarkup; InlineQueryResultGame({ required this.id, - this.type = InlineQueryResult.GAME, - required this.game_short_name, - this.reply_markup, + this.type = InlineQueryResult.typeGame, + required this.gameShortName, + this.replyMarkup, }); factory InlineQueryResultGame.fromJson(Map json) => _$InlineQueryResultGameFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_gif.dart b/lib/src/telegram/models/inline_query_result_gif.dart index e8cd3a63..af679834 100644 --- a/lib/src/telegram/models/inline_query_result_gif.dart +++ b/lib/src/telegram/models/inline_query_result_gif.dart @@ -21,51 +21,51 @@ part of '../model.dart'; /// Represents a link to an animated GIF file. /// By default, this animated GIF file will be sent by the user with optional caption. /// Alternatively, -/// you can use *input_message_content* to send a message with the specified content instead of the animation. +/// you can use *inputMessageContent* to send a message with the specified content instead of the animation. /// /// https://core.telegram.org/bots/api#inlinequeryresultgif -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultGif implements InlineQueryResult { @override String id; @override String type; - String gif_url; - int? gif_width; - int? gif_height; - int? gif_duration; - String thumb_url; - String? thumb_mime_type; + String gifUrl; + int? gifWidth; + int? gifHeight; + int? gifDuration; + String thumbnailUrl; + String? thumbnailMimeType; String? title; String? caption; - String? parse_mode; - List? caption_entities; + String? parseMode; + List? captionEntities; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; InlineQueryResultGif({ required this.id, - this.type = InlineQueryResult.GIF, - required this.gif_url, - this.gif_width, - this.gif_height, - this.gif_duration, - required this.thumb_url, - this.thumb_mime_type, + this.type = InlineQueryResult.typeGif, + required this.gifUrl, + this.gifWidth, + this.gifHeight, + this.gifDuration, + required this.thumbnailUrl, + this.thumbnailMimeType, this.title, this.caption, - this.parse_mode, - this.caption_entities, - this.reply_markup, - this.input_message_content, + this.parseMode, + this.captionEntities, + this.replyMarkup, + this.inputMessageContent, }); - @JsonKey(ignore: true) - Duration? get gif_duration_ => - gif_duration == null ? null : TimeHelper.toDuration(gif_duration!); - set gif_duration_(Duration? duration) => - gif_duration = duration == null ? null : TimeHelper.toSeconds(duration); + @JsonKey(includeFromJson: false, includeToJson: false) + Duration? get gifDuration_ => + gifDuration == null ? null : TimeHelper.toDuration(gifDuration!); + set gifDuration_(Duration? duration) => + gifDuration = duration == null ? null : TimeHelper.toSeconds(duration); factory InlineQueryResultGif.fromJson(Map json) => _$InlineQueryResultGifFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_location.dart b/lib/src/telegram/models/inline_query_result_location.dart index 094a94de..7ba8cf56 100644 --- a/lib/src/telegram/models/inline_query_result_location.dart +++ b/lib/src/telegram/models/inline_query_result_location.dart @@ -21,13 +21,13 @@ part of '../model.dart'; /// Represents a location on a map. /// By default, the location will be sent by the user. /// Alternatively, -/// you can use *input_message_content* to send a message with the specified content instead of the location. +/// you can use *inputMessageContent* to send a message with the specified content instead of the location. /// /// **Note:** This will only work in Telegram versions released after 9 April, 2016. /// Older clients will ignore them. /// /// https://core.telegram.org/bots/api#inlinequeryresultlocation -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultLocation implements InlineQueryResult { @override String id; @@ -36,39 +36,39 @@ class InlineQueryResultLocation implements InlineQueryResult { double latitude; double longitude; String title; - double? horizontal_accuracy; - int? live_period; + double? horizontalAccuracy; + int? livePeriod; int? heading; - int? proximity_alert_radius; + int? proximityAlertRadius; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; - String? thumb_url; - int? thumb_width; - int? thumb_height; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; + String? thumbnailUrl; + int? thumbnailWidth; + int? thumbnailHeight; InlineQueryResultLocation({ required this.id, - this.type = InlineQueryResult.LOCATION, + this.type = InlineQueryResult.typeLocation, required this.latitude, required this.longitude, required this.title, - this.horizontal_accuracy, - this.live_period, + this.horizontalAccuracy, + this.livePeriod, this.heading, - this.proximity_alert_radius, - this.reply_markup, - this.input_message_content, - this.thumb_url, - this.thumb_width, - this.thumb_height, + this.proximityAlertRadius, + this.replyMarkup, + this.inputMessageContent, + this.thumbnailUrl, + this.thumbnailWidth, + this.thumbnailHeight, }); - @JsonKey(ignore: true) - Duration? get live_period_ => - live_period == null ? null : TimeHelper.toDuration(live_period!); - set live_period_(Duration? duration) => - live_period = duration == null ? null : TimeHelper.toSeconds(duration); + @JsonKey(includeFromJson: false, includeToJson: false) + Duration? get livePeriod_ => + livePeriod == null ? null : TimeHelper.toDuration(livePeriod!); + set livePeriod_(Duration? duration) => + livePeriod = duration == null ? null : TimeHelper.toSeconds(duration); factory InlineQueryResultLocation.fromJson(Map json) => _$InlineQueryResultLocationFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_mpeg4_gif.dart b/lib/src/telegram/models/inline_query_result_mpeg4_gif.dart index b0001b90..c1dab90a 100644 --- a/lib/src/telegram/models/inline_query_result_mpeg4_gif.dart +++ b/lib/src/telegram/models/inline_query_result_mpeg4_gif.dart @@ -22,51 +22,51 @@ part of '../model.dart'; /// /// By default, this animated MPEG-4 file will be sent by the user with optional caption. /// Alternatively, -/// you can use *input_message_content* to send a message with the specified content instead of the animation. +/// you can use *inputMessageContent* to send a message with the specified content instead of the animation. /// /// https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultMpeg4Gif implements InlineQueryResult { @override String id; @override String type; - String mpeg4_url; - int? mpeg4_width; - int? mpeg4_height; - int? mpeg4_duration; - String thumb_url; - String? thumb_mime_type; + String mpeg4Url; + int? mpeg4Width; + int? mpeg4Height; + int? mpeg4Duration; + String thumbnailUrl; + String? thumbnailMimeType; String? title; String? caption; - String? parse_mode; - List? caption_entities; + String? parseMode; + List? captionEntities; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; InlineQueryResultMpeg4Gif({ required this.id, - this.type = InlineQueryResult.MPEG4_GIF, - required this.mpeg4_url, - this.mpeg4_width, - this.mpeg4_height, - this.mpeg4_duration, - required this.thumb_url, - this.thumb_mime_type, + this.type = InlineQueryResult.typeMpeg4Gif, + required this.mpeg4Url, + this.mpeg4Width, + this.mpeg4Height, + this.mpeg4Duration, + required this.thumbnailUrl, + this.thumbnailMimeType, this.title, this.caption, - this.parse_mode, - this.caption_entities, - this.reply_markup, - this.input_message_content, + this.parseMode, + this.captionEntities, + this.replyMarkup, + this.inputMessageContent, }); - @JsonKey(ignore: true) - Duration? get mpeg4_duration_ => - mpeg4_duration == null ? null : TimeHelper.toDuration(mpeg4_duration!); - set mpeg4_duration_(Duration? duration) => - mpeg4_duration = duration == null ? null : TimeHelper.toSeconds(duration); + @JsonKey(includeFromJson: false, includeToJson: false) + Duration? get mpeg4Duration_ => + mpeg4Duration == null ? null : TimeHelper.toDuration(mpeg4Duration!); + set mpeg4Duration_(Duration? duration) => + mpeg4Duration = duration == null ? null : TimeHelper.toSeconds(duration); factory InlineQueryResultMpeg4Gif.fromJson(Map json) => _$InlineQueryResultMpeg4GifFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_photo.dart b/lib/src/telegram/models/inline_query_result_photo.dart index 1465513d..36e45c3d 100644 --- a/lib/src/telegram/models/inline_query_result_photo.dart +++ b/lib/src/telegram/models/inline_query_result_photo.dart @@ -22,41 +22,41 @@ part of '../model.dart'; /// /// By default, this photo will be sent by the user with optional caption. /// Alternatively, -/// you can use *input_message_content* to send a message with the specified content instead of the photo. +/// you can use *inputMessageContent* to send a message with the specified content instead of the photo. /// /// https://core.telegram.org/bots/api#inlinequeryresultphoto -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultPhoto implements InlineQueryResult { @override String id; @override String type; - String photo_url; - String thumb_url; - int? photo_width; - int? photo_height; + String photoUrl; + String thumbnailUrl; + int? photoWidth; + int? photoHeight; String? title; String? description; String? caption; - String? parse_mode; - List? caption_entities; + String? parseMode; + List? captionEntities; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; InlineQueryResultPhoto({ required this.id, - this.type = InlineQueryResult.PHOTO, - required this.photo_url, - required this.thumb_url, - this.photo_width, - this.photo_height, + this.type = InlineQueryResult.typePhoto, + required this.photoUrl, + required this.thumbnailUrl, + this.photoWidth, + this.photoHeight, this.title, this.description, this.caption, - this.parse_mode, - this.caption_entities, - this.reply_markup, - this.input_message_content, + this.parseMode, + this.captionEntities, + this.replyMarkup, + this.inputMessageContent, }); factory InlineQueryResultPhoto.fromJson(Map json) => _$InlineQueryResultPhotoFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_venue.dart b/lib/src/telegram/models/inline_query_result_venue.dart index 30db231e..cc402295 100644 --- a/lib/src/telegram/models/inline_query_result_venue.dart +++ b/lib/src/telegram/models/inline_query_result_venue.dart @@ -22,13 +22,13 @@ part of '../model.dart'; /// /// By default, the venue will be sent by the user. /// Alternatively, -/// you can use *input_message_content* to send a message with the specified content instead of the venue. +/// you can use *inputMessageContent* to send a message with the specified content instead of the venue. /// /// **Note:** This will only work in Telegram versions released after 9 April, 2016. /// Older clients will ignore them. /// /// https://core.telegram.org/bots/api#inlinequeryresultvenue -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultVenue implements InlineQueryResult { @override String id; @@ -38,32 +38,32 @@ class InlineQueryResultVenue implements InlineQueryResult { double longitude; String title; String address; - String? foursquare_id; - String? foursquare_type; - String? google_place_id; - String? google_place_type; + String? foursquareId; + String? foursquareType; + String? googlePlaceId; + String? googlePlaceType; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; - String? thumb_url; - int? thumb_width; - int? thumb_height; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; + String? thumbnailUrl; + int? thumbnailWidth; + int? thumbnailHeight; InlineQueryResultVenue({ required this.id, - this.type = InlineQueryResult.VENUE, + this.type = InlineQueryResult.typeVenue, required this.latitude, required this.longitude, required this.title, required this.address, - this.foursquare_id, - this.foursquare_type, - this.google_place_id, - this.google_place_type, - this.reply_markup, - this.input_message_content, - this.thumb_url, - this.thumb_width, - this.thumb_height, + this.foursquareId, + this.foursquareType, + this.googlePlaceId, + this.googlePlaceType, + this.replyMarkup, + this.inputMessageContent, + this.thumbnailUrl, + this.thumbnailWidth, + this.thumbnailHeight, }); factory InlineQueryResultVenue.fromJson(Map json) => _$InlineQueryResultVenueFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_video.dart b/lib/src/telegram/models/inline_query_result_video.dart index 0a3f118d..66d2179d 100644 --- a/lib/src/telegram/models/inline_query_result_video.dart +++ b/lib/src/telegram/models/inline_query_result_video.dart @@ -22,56 +22,56 @@ part of '../model.dart'; /// /// By default, this video file will be sent by the user with an optional caption. /// Alternatively, -/// you can use *input_message_content* to send a message with the specified content instead of the video. +/// you can use *inputMessageContent* to send a message with the specified content instead of the video. /// /// If an InlineQueryResultVideo message contains an embedded video (e.g., YouTube), -/// you **must** replace its content using *input_message_content*. +/// you **must** replace its content using *inputMessageContent*. /// /// https://core.telegram.org/bots/api#inlinequeryresultvideo -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultVideo implements InlineQueryResult { @override String id; @override String type; - String video_url; - String mime_type; - String thumb_url; + String videoUrl; + String mimeType; + String thumbnailUrl; String title; String? caption; - String? parse_mode; - int? video_width; - int? video_height; - int? video_duration; + String? parseMode; + int? videoWidth; + int? videoHeight; + int? videoDuration; String? description; - List? caption_entities; + List? captionEntities; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; InlineQueryResultVideo({ required this.id, - this.type = InlineQueryResult.VIDEO, - required this.video_url, - required this.mime_type, - required this.thumb_url, + this.type = InlineQueryResult.typeVideo, + required this.videoUrl, + required this.mimeType, + required this.thumbnailUrl, required this.title, this.caption, - this.parse_mode, - this.video_width, - this.video_height, - this.video_duration, + this.parseMode, + this.videoWidth, + this.videoHeight, + this.videoDuration, this.description, - this.caption_entities, - this.reply_markup, - this.input_message_content, + this.captionEntities, + this.replyMarkup, + this.inputMessageContent, }); - @JsonKey(ignore: true) - Duration? get video_duration_ => - video_duration == null ? null : TimeHelper.toDuration(video_duration!); - set video_duration_(Duration? duration) => - video_duration = duration == null ? null : TimeHelper.toSeconds(duration); + @JsonKey(includeFromJson: false, includeToJson: false) + Duration? get videoDuration_ => + videoDuration == null ? null : TimeHelper.toDuration(videoDuration!); + set videoDuration_(Duration? duration) => + videoDuration = duration == null ? null : TimeHelper.toSeconds(duration); factory InlineQueryResultVideo.fromJson(Map json) => _$InlineQueryResultVideoFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_voice.dart b/lib/src/telegram/models/inline_query_result_voice.dart index 44aeca62..7d7ecb78 100644 --- a/lib/src/telegram/models/inline_query_result_voice.dart +++ b/lib/src/telegram/models/inline_query_result_voice.dart @@ -22,46 +22,46 @@ part of '../model.dart'; /// /// By default, this voice recording will be sent by the user. /// Alternatively, -/// you can use *input_message_content* to send a message with the specified content instead of the the voice message. +/// you can use *inputMessageContent* to send a message with the specified content instead of the the voice message. /// /// **Note:** This will only work in Telegram versions released after 9 April, 2016. /// Older clients will ignore them. /// /// https://core.telegram.org/bots/api#inlinequeryresultvoice -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InlineQueryResultVoice implements InlineQueryResult { @override String id; @override String type; - String voice_url; + String voiceUrl; String title; String? caption; - String? parse_mode; - int? voice_duration; - List? caption_entities; + String? parseMode; + int? voiceDuration; + List? captionEntities; @override - InlineKeyboardMarkup? reply_markup; - InputMessageContent? input_message_content; + InlineKeyboardMarkup? replyMarkup; + InputMessageContent? inputMessageContent; InlineQueryResultVoice({ required this.id, - this.type = InlineQueryResult.VOICE, - required this.voice_url, + this.type = InlineQueryResult.typeVoice, + required this.voiceUrl, required this.title, this.caption, - this.parse_mode, - this.voice_duration, - this.caption_entities, - this.reply_markup, - this.input_message_content, + this.parseMode, + this.voiceDuration, + this.captionEntities, + this.replyMarkup, + this.inputMessageContent, }); - @JsonKey(ignore: true) - Duration? get voice_duration_ => - voice_duration == null ? null : TimeHelper.toDuration(voice_duration!); - set voice_duration_(Duration? duration) => - voice_duration = duration == null ? null : TimeHelper.toSeconds(duration); + @JsonKey(includeFromJson: false, includeToJson: false) + Duration? get voiceDuration_ => + voiceDuration == null ? null : TimeHelper.toDuration(voiceDuration!); + set voiceDuration_(Duration? duration) => + voiceDuration = duration == null ? null : TimeHelper.toSeconds(duration); factory InlineQueryResultVoice.fromJson(Map json) => _$InlineQueryResultVoiceFromJson(json); diff --git a/lib/src/telegram/models/inline_query_results_button.dart b/lib/src/telegram/models/inline_query_results_button.dart new file mode 100644 index 00000000..261523cc --- /dev/null +++ b/lib/src/telegram/models/inline_query_results_button.dart @@ -0,0 +1,38 @@ +part of '../model.dart'; + +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/// This object represents a button to be shown above inline query results. You must use exactly one of the optional fields. +@JsonSerializable(fieldRename: FieldRename.snake) +class InlineQueryResultsButton { + String text; + WebAppInfo? webApp; + String? startParameter; + + InlineQueryResultsButton({ + required this.text, + this.webApp, + this.startParameter, + }); + + factory InlineQueryResultsButton.fromJson(Map json) => + _$InlineQueryResultsButtonFromJson(json); + + Map toJson() => _$InlineQueryResultsButtonToJson(this); +} diff --git a/lib/src/telegram/models/input_contact_message_content.dart b/lib/src/telegram/models/input_contact_message_content.dart index 3ef70f16..c6eddce7 100644 --- a/lib/src/telegram/models/input_contact_message_content.dart +++ b/lib/src/telegram/models/input_contact_message_content.dart @@ -23,16 +23,16 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#inputcontactmessagecontent /// /// [content]: https://core.telegram.org/bots/api#inputmessagecontent -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InputContactMessageContent implements InputMessageContent { - String phone_number; - String first_name; - String? last_name; + String phoneNumber; + String firstName; + String? lastName; String? vcard; InputContactMessageContent({ - required this.phone_number, - required this.first_name, - this.last_name, + required this.phoneNumber, + required this.firstName, + this.lastName, this.vcard, }); factory InputContactMessageContent.fromJson(Map json) => diff --git a/lib/src/telegram/models/input_invoice_message_content.dart b/lib/src/telegram/models/input_invoice_message_content.dart index 1e77b098..f16e91e9 100644 --- a/lib/src/telegram/models/input_invoice_message_content.dart +++ b/lib/src/telegram/models/input_invoice_message_content.dart @@ -23,49 +23,49 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#inputinvoicemessagecontent /// /// [content]: https://core.telegram.org/bots/api#inputmessagecontent -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InputInvoiceMessageContent implements InputMessageContent { String title; String description; String payload; - String provider_token; + String providerToken; String currency; List prices; - int? max_tip_amount; - List? suggested_tip_amounts; - String? provider_data; - String? photo_url; - int? photo_size; - int? photo_width; - int? photo_height; - bool? need_name; - bool? need_phone_number; - bool? need_email; - bool? need_shipping_address; - bool? send_phone_number_to_provider; - bool? send_email_to_provider; - bool? is_flexible; + int? maxTipAmount; + List? suggestedTipAmounts; + String? providerData; + String? photoUrl; + int? photoSize; + int? photoWidth; + int? photoHeight; + bool? needName; + bool? needPhoneNumber; + bool? needEmail; + bool? needShippingAddress; + bool? sendPhoneNumberToProvider; + bool? sendEmailToProvider; + bool? isFlexible; InputInvoiceMessageContent({ required this.title, required this.description, required this.payload, - required this.provider_token, + required this.providerToken, required this.currency, required this.prices, - this.max_tip_amount, - this.suggested_tip_amounts, - this.provider_data, - this.photo_size, - this.photo_width, - this.photo_height, - this.need_name, - this.need_phone_number, - this.need_email, - this.need_shipping_address, - this.send_phone_number_to_provider, - this.send_email_to_provider, - this.is_flexible, + this.maxTipAmount, + this.suggestedTipAmounts, + this.providerData, + this.photoSize, + this.photoWidth, + this.photoHeight, + this.needName, + this.needPhoneNumber, + this.needEmail, + this.needShippingAddress, + this.sendPhoneNumberToProvider, + this.sendEmailToProvider, + this.isFlexible, }); factory InputInvoiceMessageContent.fromJson(Map json) => diff --git a/lib/src/telegram/models/input_location_message_content.dart b/lib/src/telegram/models/input_location_message_content.dart index 10c1bada..b5735aa8 100644 --- a/lib/src/telegram/models/input_location_message_content.dart +++ b/lib/src/telegram/models/input_location_message_content.dart @@ -23,29 +23,29 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#inputlocationmessagecontent /// /// [content]: https://core.telegram.org/bots/api#inputmessagecontent -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InputLocationMessageContent implements InputMessageContent { double latitude; double longitude; - double? horizontal_accuracy; - int? live_period; + double? horizontalAccuracy; + int? livePeriod; int? heading; - int? proximity_alert_radius; + int? proximityAlertRadius; InputLocationMessageContent({ required this.latitude, required this.longitude, - this.horizontal_accuracy, - this.live_period, + this.horizontalAccuracy, + this.livePeriod, this.heading, - this.proximity_alert_radius, + this.proximityAlertRadius, }); - @JsonKey(ignore: true) - Duration? get live_period_ => - live_period == null ? null : TimeHelper.toDuration(live_period!); - set live_period_(Duration? duration) => - live_period = duration == null ? null : TimeHelper.toSeconds(duration); + @JsonKey(includeFromJson: false, includeToJson: false) + Duration? get livePeriod_ => + livePeriod == null ? null : TimeHelper.toDuration(livePeriod!); + set livePeriod_(Duration? duration) => + livePeriod = duration == null ? null : TimeHelper.toSeconds(duration); factory InputLocationMessageContent.fromJson(Map json) => _$InputLocationMessageContentFromJson(json); diff --git a/lib/src/telegram/models/input_media.dart b/lib/src/telegram/models/input_media.dart index f5589588..a1960fde 100644 --- a/lib/src/telegram/models/input_media.dart +++ b/lib/src/telegram/models/input_media.dart @@ -1,6 +1,6 @@ /* * TeleDart - Telegram Bot API for Dart - * Copyright (C) 2019 Dino PH Leung + * Copyright (C) 2023 Dino PH Leung * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,26 +28,30 @@ part of '../model.dart'; /// * [InputMediaVideo](https://core.telegram.org/bots/api#inputmediavideo) /// /// https://core.telegram.org/bots/api#inputmedia -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InputMedia { - static const ANIMATION = 'animation'; - static const AUDIO = 'audio'; - static const DOCUMENT = 'document'; - static const PHOTO = 'photo'; - static const VIDEO = 'video'; + static const typeAnimation = 'animation'; + static const typeAudio = 'audio'; + static const typeDocument = 'document'; + static const typePhoto = 'photo'; + static const typeVideo = 'video'; String type; String media; String? caption; - String? parse_mode; - List? caption_entities; + String? parseMode; + List? captionEntities; + + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? mediaFile; InputMedia({ required this.type, required this.media, this.caption, - this.parse_mode, - this.caption_entities, + this.parseMode, + this.captionEntities, + this.mediaFile, }); factory InputMedia.fromJson(Map json) => diff --git a/lib/src/telegram/models/input_media_animation.dart b/lib/src/telegram/models/input_media_animation.dart index 3402cdd4..98eff42d 100644 --- a/lib/src/telegram/models/input_media_animation.dart +++ b/lib/src/telegram/models/input_media_animation.dart @@ -1,6 +1,6 @@ /* * TeleDart - Telegram Bot API for Dart - * Copyright (C) 2019 Dino PH Leung + * Copyright (C) 2023 Dino PH Leung * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,8 +21,8 @@ part of '../model.dart'; /// Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent. /// /// https://core.telegram.org/bots/api#inputmediaanimation -@JsonSerializable() -class InputMediaAnimation implements InputMedia { +@JsonSerializable(fieldRename: FieldRename.snake) +class InputMediaAnimation implements InputMediaWithThumbnail { @override String type; @override @@ -30,27 +30,118 @@ class InputMediaAnimation implements InputMedia { @override String? caption; @override - String? parse_mode; + String? parseMode; @override - List? caption_entities; - dynamic thumb; // InputFile or String + List? captionEntities; + @override + String? thumbnail; int? width; int? height; int? duration; + bool? hasSpoiler; + + @override + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? mediaFile; + @override + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? thumbnailFile; InputMediaAnimation({ - this.type = InputMedia.ANIMATION, + this.type = InputMedia.typeAnimation, required this.media, - this.thumb, + this.thumbnail, this.caption, - this.parse_mode, - this.caption_entities, + this.parseMode, + this.captionEntities, this.width, this.height, this.duration, + this.hasSpoiler, }); - @JsonKey(ignore: true) + // Factory to create InputMediaAnimation from file + factory InputMediaAnimation.fromFile( + {required io.File media, + String? thumbnail, + String? caption, + String? parseMode, + List? captionEntities, + int? width, + int? height, + int? duration, + bool? hasSpoiler}) => + InputMediaAnimation( + media: 'attach://${media.path}', + thumbnail: thumbnail, + caption: caption, + parseMode: parseMode, + captionEntities: captionEntities, + width: width, + height: height, + duration: duration, + hasSpoiler: hasSpoiler, + )..mediaFile = MultipartFile( + media.path, media.openRead(), media.lengthSync(), + filename: media.path.split('/').last); + + // Factory to create InputMediaAnimation with thumbnail file + factory InputMediaAnimation.withThumbnailFile({ + required String media, + required io.File thumbnail, + String? caption, + String? parseMode, + List? captionEntities, + int? width, + int? height, + int? duration, + bool? hasSpoiler, + }) => + InputMediaAnimation( + media: media, + thumbnail: 'attach://${thumbnail.path}', + caption: caption, + parseMode: parseMode, + captionEntities: captionEntities, + width: width, + height: height, + duration: duration, + hasSpoiler: hasSpoiler, + )..thumbnailFile = MultipartFile( + thumbnail.path, thumbnail.openRead(), thumbnail.lengthSync(), + filename: thumbnail.path.split('/').last); + + // Factory to create InputMediaAnimation from file and with thumbnail file + factory InputMediaAnimation.fromFileWithThumbnailFile({ + required io.File media, + required io.File thumbnail, + String? caption, + String? parseMode, + List? captionEntities, + int? width, + int? height, + int? duration, + bool? hasSpoiler, + }) => + InputMediaAnimation( + media: 'attach://${media.path}', + thumbnail: 'attach://${thumbnail.path}', + caption: caption, + parseMode: parseMode, + captionEntities: captionEntities, + width: width, + height: height, + duration: duration, + hasSpoiler: hasSpoiler, + ) + ..mediaFile = MultipartFile( + media.path, media.openRead(), media.lengthSync(), + filename: media.path.split('/').last) + ..thumbnailFile = MultipartFile( + thumbnail.path, thumbnail.openRead(), thumbnail.lengthSync(), + filename: thumbnail.path.split('/').last); + + @JsonKey(includeFromJson: false, includeToJson: false) Duration? get duration_ => duration == null ? null : TimeHelper.toDuration(duration!); set duration_(Duration? duration) => diff --git a/lib/src/telegram/models/input_media_audio.dart b/lib/src/telegram/models/input_media_audio.dart index 0e0ffa47..f934110a 100644 --- a/lib/src/telegram/models/input_media_audio.dart +++ b/lib/src/telegram/models/input_media_audio.dart @@ -1,6 +1,6 @@ /* * TeleDart - Telegram Bot API for Dart - * Copyright (C) 2019 Dino PH Leung + * Copyright (C) 2023 Dino PH Leung * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,8 +21,8 @@ part of '../model.dart'; /// Represents an audio file to be treated as music to be sent. /// /// https://core.telegram.org/bots/api#inputmediaaudio -@JsonSerializable() -class InputMediaAudio implements InputMedia { +@JsonSerializable(fieldRename: FieldRename.snake) +class InputMediaAudio implements InputMediaWithThumbnail { @override String type; @override @@ -30,27 +30,110 @@ class InputMediaAudio implements InputMedia { @override String? caption; @override - String? parse_mode; + String? parseMode; @override - List? caption_entities; - dynamic thumb; // InputFile or String + List? captionEntities; + @override + String? thumbnail; int? duration; String? performer; String? title; + @override + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? mediaFile; + @override + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? thumbnailFile; + InputMediaAudio({ - this.type = InputMedia.AUDIO, + this.type = InputMedia.typeAudio, required this.media, - this.thumb, + this.thumbnail, this.caption, - this.parse_mode, - this.caption_entities, + this.parseMode, + this.captionEntities, this.duration, this.performer, this.title, }); - @JsonKey(ignore: true) + // Factory to create InputMediaAudio from file + factory InputMediaAudio.fromFile( + {required io.File media, + String? thumbnail, + String? caption, + String? parseMode, + List? captionEntities, + int? duration, + String? performer, + String? title}) => + InputMediaAudio( + media: 'attach://${media.path}', + thumbnail: thumbnail, + caption: caption, + parseMode: parseMode, + captionEntities: captionEntities, + duration: duration, + performer: performer, + title: title, + )..mediaFile = MultipartFile( + media.path, media.openRead(), media.lengthSync(), + filename: media.path.split('/').last); + + // Factory to create InputMediaAudio with thumbnail file + factory InputMediaAudio.withThumbnailFile({ + required io.File thumbnail, + required String media, + String? caption, + String? parseMode, + List? captionEntities, + int? duration, + String? performer, + String? title, + }) => + InputMediaAudio( + media: media, + thumbnail: 'attach://${thumbnail.path}', + caption: caption, + parseMode: parseMode, + captionEntities: captionEntities, + duration: duration, + performer: performer, + title: title, + )..thumbnailFile = MultipartFile( + thumbnail.path, thumbnail.openRead(), thumbnail.lengthSync(), + filename: thumbnail.path.split('/').last); + + // Factory to create InputMediaAudio from file and with thumbnail file + factory InputMediaAudio.fromFileWithThumbnailFile({ + required io.File media, + required io.File thumbnail, + String? caption, + String? parseMode, + List? captionEntities, + int? duration, + String? performer, + String? title, + }) => + InputMediaAudio( + media: 'attach://${media.path}', + thumbnail: 'attach://${thumbnail.path}', + caption: caption, + parseMode: parseMode, + captionEntities: captionEntities, + duration: duration, + performer: performer, + title: title, + ) + ..mediaFile = MultipartFile( + media.path, media.openRead(), media.lengthSync(), + filename: media.path.split('/').last) + ..thumbnailFile = MultipartFile( + thumbnail.path, thumbnail.openRead(), thumbnail.lengthSync(), + filename: thumbnail.path.split('/').last); + + @JsonKey(includeFromJson: false, includeToJson: false) Duration? get duration_ => duration == null ? null : TimeHelper.toDuration(duration!); set duration_(Duration? duration) => diff --git a/lib/src/telegram/models/input_media_document.dart b/lib/src/telegram/models/input_media_document.dart index 4b2186a5..ac5c5d51 100644 --- a/lib/src/telegram/models/input_media_document.dart +++ b/lib/src/telegram/models/input_media_document.dart @@ -1,6 +1,6 @@ /* * TeleDart - Telegram Bot API for Dart - * Copyright (C) 2019 Dino PH Leung + * Copyright (C) 2023 Dino PH Leung * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,8 +21,8 @@ part of '../model.dart'; /// Represents a general file to be sent. /// /// https://core.telegram.org/bots/api#inputmediadocument -@JsonSerializable() -class InputMediaDocument implements InputMedia { +@JsonSerializable(fieldRename: FieldRename.snake) +class InputMediaDocument implements InputMediaWithThumbnail { @override String type; @override @@ -30,20 +30,94 @@ class InputMediaDocument implements InputMedia { @override String? caption; @override - String? parse_mode; + String? parseMode; @override - List? caption_entities; - dynamic thumb; // InputFile or String - bool? disable_content_type_detection; + List? captionEntities; + @override + String? thumbnail; + bool? disableContentTypeDetection; + + @override + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? mediaFile; + @override + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? thumbnailFile; + InputMediaDocument({ - this.type = InputMedia.DOCUMENT, + this.type = InputMedia.typeDocument, required this.media, - this.thumb, + this.thumbnail, this.caption, - this.parse_mode, - this.caption_entities, - this.disable_content_type_detection, + this.parseMode, + this.captionEntities, + this.disableContentTypeDetection, }); + + // Factory to create InputMediaDocument from file + factory InputMediaDocument.fromFile( + {required io.File media, + String? thumbnail, + String? caption, + String? parseMode, + List? captionEntities, + bool? disableContentTypeDetection}) => + InputMediaDocument( + media: 'attach://${media.path}', + thumbnail: thumbnail, + caption: caption, + parseMode: parseMode, + captionEntities: captionEntities, + disableContentTypeDetection: disableContentTypeDetection, + )..mediaFile = MultipartFile( + media.path, media.openRead(), media.lengthSync(), + filename: media.path.split('/').last); + + // Factory to create InputMediaDocument with thumbnail file + factory InputMediaDocument.withThumbnailFile({ + required String media, + required io.File thumbnail, + String? caption, + String? parseMode, + List? captionEntities, + bool? disableContentTypeDetection, + }) => + InputMediaDocument( + type: InputMedia.typeDocument, + media: media, + thumbnail: 'attach://${thumbnail.path}', + caption: caption, + parseMode: parseMode, + captionEntities: captionEntities, + disableContentTypeDetection: disableContentTypeDetection, + )..thumbnailFile = MultipartFile( + thumbnail.path, thumbnail.openRead(), thumbnail.lengthSync(), + filename: thumbnail.path.split('/').last); + + // Factory to create InputMediaDocument from file and with thumbnail file + factory InputMediaDocument.fromFileWithThumbnailFile({ + required io.File media, + required io.File thumbnail, + String? caption, + String? parseMode, + List? captionEntities, + bool? disableContentTypeDetection, + }) => + InputMediaDocument( + media: 'attach://${media.path}', + thumbnail: 'attach://${thumbnail.path}', + caption: caption, + parseMode: parseMode, + captionEntities: captionEntities, + disableContentTypeDetection: disableContentTypeDetection, + ) + ..mediaFile = MultipartFile( + media.path, media.openRead(), media.lengthSync(), + filename: media.path.split('/').last) + ..thumbnailFile = MultipartFile( + thumbnail.path, thumbnail.openRead(), thumbnail.lengthSync(), + filename: thumbnail.path.split('/').last); + factory InputMediaDocument.fromJson(Map json) => _$InputMediaDocumentFromJson(json); @override diff --git a/lib/src/telegram/models/input_media_photo.dart b/lib/src/telegram/models/input_media_photo.dart index 41a0da4b..c211968c 100644 --- a/lib/src/telegram/models/input_media_photo.dart +++ b/lib/src/telegram/models/input_media_photo.dart @@ -1,6 +1,6 @@ /* * TeleDart - Telegram Bot API for Dart - * Copyright (C) 2019 Dino PH Leung + * Copyright (C) 2023 Dino PH Leung * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,7 +21,7 @@ part of '../model.dart'; /// Represents a photo to be sent. /// /// https://core.telegram.org/bots/api#inputmediaphoto -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InputMediaPhoto implements InputMedia { @override String type; @@ -30,16 +30,41 @@ class InputMediaPhoto implements InputMedia { @override String? caption; @override - String? parse_mode; + String? parseMode; @override - List? caption_entities; + List? captionEntities; + bool? hasSpoiler; + + @override + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? mediaFile; + InputMediaPhoto({ - this.type = InputMedia.PHOTO, + this.type = InputMedia.typePhoto, required this.media, this.caption, - this.parse_mode, - this.caption_entities, + this.parseMode, + this.captionEntities, + this.hasSpoiler, }); + + // Factory to create InputMediaPhoto from file + factory InputMediaPhoto.fromFile( + {required io.File media, + String? caption, + String? parseMode, + List? captionEntities, + bool? hasSpoiler}) => + InputMediaPhoto( + media: 'attach://${media.path}', + caption: caption, + parseMode: parseMode, + captionEntities: captionEntities, + hasSpoiler: hasSpoiler, + )..mediaFile = MultipartFile( + media.path, media.openRead(), media.lengthSync(), + filename: media.path.split('/').last); + factory InputMediaPhoto.fromJson(Map json) => _$InputMediaPhotoFromJson(json); @override diff --git a/lib/src/telegram/models/input_media_video.dart b/lib/src/telegram/models/input_media_video.dart index f469f8fa..2448bc68 100644 --- a/lib/src/telegram/models/input_media_video.dart +++ b/lib/src/telegram/models/input_media_video.dart @@ -1,6 +1,6 @@ /* * TeleDart - Telegram Bot API for Dart - * Copyright (C) 2019 Dino PH Leung + * Copyright (C) 2023 Dino PH Leung * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,8 +21,8 @@ part of '../model.dart'; /// Represents a video to be sent. /// /// https://core.telegram.org/bots/api#inputmediavideo -@JsonSerializable() -class InputMediaVideo implements InputMedia { +@JsonSerializable(fieldRename: FieldRename.snake) +class InputMediaVideo implements InputMediaWithThumbnail { @override String type; @override @@ -30,29 +30,127 @@ class InputMediaVideo implements InputMedia { @override String? caption; @override - String? parse_mode; + String? parseMode; @override - List? caption_entities; - dynamic thumb; // InputFile or String + List? captionEntities; + @override + String? thumbnail; int? width; int? height; int? duration; - bool? supports_streaming; + bool? supportsStreaming; + bool? hasSpoiler; + + @override + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? mediaFile; + @override + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? thumbnailFile; InputMediaVideo({ - this.type = InputMedia.VIDEO, + this.type = InputMedia.typeVideo, required this.media, this.caption, - this.parse_mode, - this.caption_entities, - this.thumb, + this.parseMode, + this.captionEntities, + this.thumbnail, this.width, this.height, this.duration, - this.supports_streaming, + this.supportsStreaming, + this.hasSpoiler, }); - @JsonKey(ignore: true) + // Factory to create InputMediaVideo from file + factory InputMediaVideo.fromFile({ + required io.File media, + String? caption, + String? parseMode, + List? captionEntities, + String? thumbnail, + int? width, + int? height, + int? duration, + bool? supportsStreaming, + bool? hasSpoiler, + }) => + InputMediaVideo( + media: 'attach://${media.path}', + caption: caption, + parseMode: parseMode, + captionEntities: captionEntities, + thumbnail: thumbnail, + width: width, + height: height, + duration: duration, + supportsStreaming: supportsStreaming, + hasSpoiler: hasSpoiler, + )..mediaFile = MultipartFile( + media.path, media.openRead(), media.lengthSync(), + filename: media.path.split('/').last); + + // Factory to create InputMediaVideo with thumbnail file + factory InputMediaVideo.withThumbnailFile({ + required String media, + required io.File thumbnail, + String? caption, + String? parseMode, + List? captionEntities, + int? width, + int? height, + int? duration, + bool? supportsStreaming, + bool? hasSpoiler, + }) => + InputMediaVideo( + media: media, + thumbnail: 'attach://${thumbnail.path}', + caption: caption, + parseMode: parseMode, + captionEntities: captionEntities, + width: width, + height: height, + duration: duration, + supportsStreaming: supportsStreaming, + hasSpoiler: hasSpoiler, + )..thumbnailFile = MultipartFile( + thumbnail.path, thumbnail.openRead(), thumbnail.lengthSync(), + filename: thumbnail.path.split('/').last); + + // Factory to create InputMediaVideo from file and with thumbnail file + factory InputMediaVideo.fromFileWithThumbnailFile({ + required io.File media, + required io.File thumbnail, + String? caption, + String? parseMode, + List? captionEntities, + int? width, + int? height, + int? duration, + bool? supportsStreaming, + bool? hasSpoiler, + }) => + InputMediaVideo( + media: 'attach://${media.path}', + thumbnail: 'attach://${thumbnail.path}', + caption: caption, + parseMode: parseMode, + captionEntities: captionEntities, + width: width, + height: height, + duration: duration, + supportsStreaming: supportsStreaming, + hasSpoiler: hasSpoiler, + ) + ..mediaFile = MultipartFile( + media.path, media.openRead(), media.lengthSync(), + filename: media.path.split('/').last) + ..thumbnailFile = MultipartFile( + thumbnail.path, thumbnail.openRead(), thumbnail.lengthSync(), + filename: thumbnail.path.split('/').last); + + @JsonKey(includeFromJson: false, includeToJson: false) Duration? get duration_ => duration == null ? null : TimeHelper.toDuration(duration!); set duration_(Duration? duration) => diff --git a/lib/src/telegram/models/input_media_with_thumbnail.dart b/lib/src/telegram/models/input_media_with_thumbnail.dart new file mode 100644 index 00000000..806bc6e3 --- /dev/null +++ b/lib/src/telegram/models/input_media_with_thumbnail.dart @@ -0,0 +1,63 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object represents the content of a media message to be sent which contains thumbnail. +/// +/// It should be one of +/// * [InputMediaAnimation](https://core.telegram.org/bots/api#inputmediaanimation) +/// * [InputMediaDocument](https://core.telegram.org/bots/api#inputmediadocument) +/// * [InputMediaAudio](https://core.telegram.org/bots/api#inputmediaaudio) +/// * [InputMediaVideo](https://core.telegram.org/bots/api#inputmediavideo) +/// +/// https://core.telegram.org/bots/api#inputmedia +@JsonSerializable(fieldRename: FieldRename.snake) +class InputMediaWithThumbnail implements InputMedia { + @override + String type; + @override + String media; + @override + String? caption; + @override + String? parseMode; + @override + List? captionEntities; + String? thumbnail; + + @override + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? mediaFile; + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? thumbnailFile; + + InputMediaWithThumbnail({ + required this.type, + required this.media, + this.thumbnail, + this.caption, + this.parseMode, + this.captionEntities, + }); + + factory InputMediaWithThumbnail.fromJson(Map json) => + _$InputMediaWithThumbnailFromJson(json); + @override + Map toJson() => _$InputMediaWithThumbnailToJson(this); +} diff --git a/lib/src/telegram/models/input_message_content.dart b/lib/src/telegram/models/input_message_content.dart index 617dc808..8690d320 100644 --- a/lib/src/telegram/models/input_message_content.dart +++ b/lib/src/telegram/models/input_message_content.dart @@ -28,7 +28,7 @@ part of '../model.dart'; /// * [InputInvoiceMessageContent](https://core.telegram.org/bots/api#inputinvoicemessagecontent) /// /// https://core.telegram.org/bots/api#inputmessagecontent -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) // abstract class InputMessageContent { class InputMessageContent { InputMessageContent(); diff --git a/lib/src/telegram/models/input_sticker.dart b/lib/src/telegram/models/input_sticker.dart new file mode 100644 index 00000000..211db504 --- /dev/null +++ b/lib/src/telegram/models/input_sticker.dart @@ -0,0 +1,62 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object describes a sticker to be added to a sticker set. +/// +/// https://core.telegram.org/bots/api#inputsticker +@JsonSerializable(fieldRename: FieldRename.snake) +class InputSticker { + String sticker; + List emojiList; + MaskPosition? maskPosition; + List? keywords; + + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? stickerFile; + + InputSticker({ + required this.sticker, + required this.emojiList, + this.maskPosition, + this.keywords, + this.stickerFile, + }); + + // Factory to create InputSticker from file + factory InputSticker.file({ + required io.File sticker, + required List emojiList, + MaskPosition? maskPosition, + List? keywords, + }) => + InputSticker( + sticker: 'attach://${sticker.path}', + stickerFile: MultipartFile( + sticker.path, sticker.openRead(), sticker.lengthSync(), + filename: sticker.path.split('/').last), + emojiList: emojiList, + maskPosition: maskPosition, + keywords: keywords, + ); + + factory InputSticker.fromJson(Map json) => + _$InputStickerFromJson(json); + Map toJson() => _$InputStickerToJson(this); +} diff --git a/lib/src/telegram/models/input_text_message_content.dart b/lib/src/telegram/models/input_text_message_content.dart index cef8d75c..608e30f4 100644 --- a/lib/src/telegram/models/input_text_message_content.dart +++ b/lib/src/telegram/models/input_text_message_content.dart @@ -23,16 +23,16 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#inputtextmessagecontent /// /// [content]: https://core.telegram.org/bots/api#inputmessagecontent -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InputTextMessageContent implements InputMessageContent { - String message_text; - String? parse_mode; + String messageText; + String? parseMode; List? entities; - bool? disable_web_page_preview; + bool? disableWebPagePreview; InputTextMessageContent({ - required this.message_text, - this.parse_mode, - this.disable_web_page_preview, + required this.messageText, + this.parseMode, + this.disableWebPagePreview, }); factory InputTextMessageContent.fromJson(Map json) => _$InputTextMessageContentFromJson(json); diff --git a/lib/src/telegram/models/input_venue_message_content.dart b/lib/src/telegram/models/input_venue_message_content.dart index 2a0fa726..f0adf75c 100644 --- a/lib/src/telegram/models/input_venue_message_content.dart +++ b/lib/src/telegram/models/input_venue_message_content.dart @@ -23,25 +23,25 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#inputvenuemessagecontent /// /// [content]: https://core.telegram.org/bots/api#inputmessagecontent -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class InputVenueMessageContent implements InputMessageContent { double latitude; double longitude; String title; String address; - String? foursquare_id; - String? foursquare_type; - String? google_place_id; - String? google_place_type; + String? foursquareId; + String? foursquareType; + String? googlePlaceId; + String? googlePlaceType; InputVenueMessageContent({ required this.latitude, required this.longitude, required this.title, required this.address, - this.foursquare_id, - this.foursquare_type, - this.google_place_id, - this.google_place_type, + this.foursquareId, + this.foursquareType, + this.googlePlaceId, + this.googlePlaceType, }); factory InputVenueMessageContent.fromJson(Map json) => _$InputVenueMessageContentFromJson(json); diff --git a/lib/src/telegram/models/invoice.dart b/lib/src/telegram/models/invoice.dart index 858787c8..d9acef36 100644 --- a/lib/src/telegram/models/invoice.dart +++ b/lib/src/telegram/models/invoice.dart @@ -21,19 +21,19 @@ part of '../model.dart'; /// This object contains basic information about an invoice. /// /// https://core.telegram.org/bots/api#invoice -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class Invoice { String title; String description; - String start_parameter; + String startParameter; String currency; - int total_amount; + int totalAmount; Invoice({ required this.title, required this.description, - required this.start_parameter, + required this.startParameter, required this.currency, - required this.total_amount, + required this.totalAmount, }); factory Invoice.fromJson(Map json) => _$InvoiceFromJson(json); diff --git a/lib/src/telegram/models/keyboard_button.dart b/lib/src/telegram/models/keyboard_button.dart index 86cba157..b825df7b 100644 --- a/lib/src/telegram/models/keyboard_button.dart +++ b/lib/src/telegram/models/keyboard_button.dart @@ -23,22 +23,27 @@ part of '../model.dart'; /// For simple text buttons [String] can be used instead of this object to specify text of the button. /// Optional fields are mutually exclusive. /// -/// **Note:** request_contact and request_location options will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. +/// **Note:** requestContact and requestLocation options will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them. /// -/// **Note:** request_poll option will only work in Telegram versions released after 23 January, 2020. Older clients will display unsupported message. +/// **Note:** requestPoll option will only work in Telegram versions released after 23 January, 2020. Older clients will display unsupported message. /// /// https://core.telegram.org/bots/api#keyboardbutton -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class KeyboardButton { String text; - bool? request_contact; - bool? request_location; - KeyboardButtonPollType? request_poll; + KeyboardButtonRequestUser? requestUser; + KeyboardButtonRequestChat? requestChat; + bool? requestContact; + bool? requestLocation; + KeyboardButtonPollType? requestPoll; + WebAppInfo? webApp; KeyboardButton({ required this.text, - this.request_contact, - this.request_location, - this.request_poll, + this.requestUser, + this.requestContact, + this.requestLocation, + this.requestPoll, + this.webApp, }); factory KeyboardButton.fromJson(Map json) => _$KeyboardButtonFromJson(json); diff --git a/lib/src/telegram/models/keyboard_button_poll_type.dart b/lib/src/telegram/models/keyboard_button_poll_type.dart index bf5a64c1..5fe25f04 100644 --- a/lib/src/telegram/models/keyboard_button_poll_type.dart +++ b/lib/src/telegram/models/keyboard_button_poll_type.dart @@ -21,7 +21,7 @@ part of '../model.dart'; /// This object represents type of a poll, which is allowed to be created and sent when the corresponding button is pressed. /// /// https://core.telegram.org/bots/api#keyboardbuttonpolltype -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class KeyboardButtonPollType { String? type; KeyboardButtonPollType({ diff --git a/lib/src/telegram/models/keyboard_button_request_chat.dart b/lib/src/telegram/models/keyboard_button_request_chat.dart new file mode 100644 index 00000000..0af563f0 --- /dev/null +++ b/lib/src/telegram/models/keyboard_button_request_chat.dart @@ -0,0 +1,49 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object defines the criteria used to request a suitable chat. +/// The identifier of the selected chat will be shared with the bot when +/// the corresponding button is pressed. +/// +/// https://core.telegram.org/bots/api#keyboardbuttonrequestchat +@JsonSerializable(fieldRename: FieldRename.snake) +class KeyboardButtonRequestChat { + int requestId; + bool chatIsChannel; + bool? charIsForum; + bool? chatHasUsername; + bool? chatIsCreated; + ChatAdministratorRights? userAdministratorRights; + ChatAdministratorRights? botAdministratorRights; + bool? botIsMember; + KeyboardButtonRequestChat({ + required this.requestId, + required this.chatIsChannel, + this.charIsForum, + this.chatHasUsername, + this.chatIsCreated, + this.userAdministratorRights, + this.botAdministratorRights, + this.botIsMember, + }); + factory KeyboardButtonRequestChat.fromJson(Map json) => + _$KeyboardButtonRequestChatFromJson(json); + Map toJson() => _$KeyboardButtonRequestChatToJson(this); +} diff --git a/lib/src/telegram/models/keyboard_button_request_user.dart b/lib/src/telegram/models/keyboard_button_request_user.dart new file mode 100644 index 00000000..ba9b15d6 --- /dev/null +++ b/lib/src/telegram/models/keyboard_button_request_user.dart @@ -0,0 +1,39 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object defines the criteria used to request a suitable user. +/// The identifier of the selected user will be shared with the bot when +/// the corresponding button is pressed. +/// +/// https://core.telegram.org/bots/api#keyboardbuttonrequestuser +@JsonSerializable(fieldRename: FieldRename.snake) +class KeyboardButtonRequestUser { + int requestId; + bool? userIsBot; + bool? userIsPremium; + KeyboardButtonRequestUser({ + required this.requestId, + this.userIsBot, + this.userIsPremium, + }); + factory KeyboardButtonRequestUser.fromJson(Map json) => + _$KeyboardButtonRequestUserFromJson(json); + Map toJson() => _$KeyboardButtonRequestUserToJson(this); +} diff --git a/lib/src/telegram/models/labeled_price.dart b/lib/src/telegram/models/labeled_price.dart index 6ee670d8..3de01c22 100644 --- a/lib/src/telegram/models/labeled_price.dart +++ b/lib/src/telegram/models/labeled_price.dart @@ -21,7 +21,7 @@ part of '../model.dart'; /// This object represents a portion of the price for goods or services. /// /// https://core.telegram.org/bots/api#labeledprice -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class LabeledPrice { String label; int amount; diff --git a/lib/src/telegram/models/location.dart b/lib/src/telegram/models/location.dart index 8295d404..babe3ed6 100644 --- a/lib/src/telegram/models/location.dart +++ b/lib/src/telegram/models/location.dart @@ -21,21 +21,21 @@ part of '../model.dart'; /// This object represents a point on the map. /// /// https://core.telegram.org/bots/api#location -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class Location { double longitude; double latitude; - double? horizontal_accuracy; - int? live_period; + double? horizontalAccuracy; + int? livePeriod; int? heading; - int? proximity_alert_radius; + int? proximityAlertRadius; Location({ required this.longitude, required this.latitude, - this.horizontal_accuracy, - this.live_period, + this.horizontalAccuracy, + this.livePeriod, this.heading, - this.proximity_alert_radius, + this.proximityAlertRadius, }); factory Location.fromJson(Map json) => _$LocationFromJson(json); diff --git a/lib/src/telegram/models/login_url.dart b/lib/src/telegram/models/login_url.dart index c50bc2e0..646ac256 100644 --- a/lib/src/telegram/models/login_url.dart +++ b/lib/src/telegram/models/login_url.dart @@ -29,17 +29,17 @@ part of '../model.dart'; /// /// [Telegram Login Widget]: https://core.telegram.org/widgets/login /// [version 5.7]: https://telegram.org/blog/privacy-discussions-web-bots#meet-seamless-web-bots -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class LoginUrl { String url; - String? forward_text; - String? bot_username; - bool? request_write_access; + String? forwardText; + String? botUsername; + bool? requestWriteAccess; LoginUrl({ required this.url, - this.forward_text, - this.bot_username, - this.request_write_access, + this.forwardText, + this.botUsername, + this.requestWriteAccess, }); factory LoginUrl.fromJson(Map json) => _$LoginUrlFromJson(json); diff --git a/lib/src/telegram/models/mask_position.dart b/lib/src/telegram/models/mask_position.dart index 94ad07aa..11d207c7 100644 --- a/lib/src/telegram/models/mask_position.dart +++ b/lib/src/telegram/models/mask_position.dart @@ -21,16 +21,16 @@ part of '../model.dart'; /// This object describes the position on faces where a mask should be placed by default. /// /// https://core.telegram.org/bots/api#maskposition -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class MaskPosition { String point; - double x_shift; - double y_shift; + double xShift; + double yShift; double scale; MaskPosition({ required this.point, - required this.x_shift, - required this.y_shift, + required this.xShift, + required this.yShift, required this.scale, }); factory MaskPosition.fromJson(Map json) => diff --git a/lib/src/telegram/models/menu_button.dart b/lib/src/telegram/models/menu_button.dart new file mode 100644 index 00000000..4164ba3b --- /dev/null +++ b/lib/src/telegram/models/menu_button.dart @@ -0,0 +1,42 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2022 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object describes the bot's menu button in a private chat. It should be one of +/// - [MenuButtonCommands] +/// - [MenuButtonWebApp] +/// - [MenuButtonDefault] +/// +/// If a menu button other than [MenuButtonDefault] is set for a private chat, then it is applied in the chat. Otherwise the default menu button is applied. +/// By default, the menu button opens the list of bot commands +/// +/// https://core.telegram.org/bots/api#menubutton + +@JsonSerializable(fieldRename: FieldRename.snake) +class MenuButton { + static const typeCommands = 'commands'; + static const typeWebApp = 'web_app'; + static const typeDefault = 'default'; + + String type; + MenuButton({required this.type}); + factory MenuButton.fromJson(Map json) => + _$MenuButtonFromJson(json); + Map toJson() => _$MenuButtonToJson(this); +} diff --git a/lib/src/telegram/models/menu_button_commands.dart b/lib/src/telegram/models/menu_button_commands.dart new file mode 100644 index 00000000..8ba1adb6 --- /dev/null +++ b/lib/src/telegram/models/menu_button_commands.dart @@ -0,0 +1,34 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2022 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// Represents a menu button, which opens the bot's list of commands. +/// +/// https://core.telegram.org/bots/api#menubuttoncommands + +@JsonSerializable(fieldRename: FieldRename.snake) +class MenuButtonCommands implements MenuButton { + @override + String type; + MenuButtonCommands({this.type = MenuButton.typeCommands}); + factory MenuButtonCommands.fromJson(Map json) => + _$MenuButtonCommandsFromJson(json); + @override + Map toJson() => _$MenuButtonCommandsToJson(this); +} diff --git a/lib/src/telegram/models/menu_button_default.dart b/lib/src/telegram/models/menu_button_default.dart new file mode 100644 index 00000000..3bf943a2 --- /dev/null +++ b/lib/src/telegram/models/menu_button_default.dart @@ -0,0 +1,34 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2022 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// Describes that no specific value for the menu button was set. +/// +/// https://core.telegram.org/bots/api#menubuttondefault + +@JsonSerializable(fieldRename: FieldRename.snake) +class MenuButtonDefault implements MenuButton { + @override + String type; + MenuButtonDefault({this.type = MenuButton.typeDefault}); + factory MenuButtonDefault.fromJson(Map json) => + _$MenuButtonDefaultFromJson(json); + @override + Map toJson() => _$MenuButtonDefaultToJson(this); +} diff --git a/lib/src/telegram/models/menu_button_web_app.dart b/lib/src/telegram/models/menu_button_web_app.dart new file mode 100644 index 00000000..95e71457 --- /dev/null +++ b/lib/src/telegram/models/menu_button_web_app.dart @@ -0,0 +1,41 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2022 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// Represents a menu button, which launches a [Web App]. +/// +/// https://core.telegram.org/bots/api#menubuttoncommands +/// +/// [Web App]: https://core.telegram.org/bots/webapps + +@JsonSerializable(fieldRename: FieldRename.snake) +class MenuButtonWebApp implements MenuButton { + @override + String type; + String text; + WebAppInfo webApp; + MenuButtonWebApp( + {this.type = MenuButton.typeWebApp, + required this.text, + required this.webApp}); + factory MenuButtonWebApp.fromJson(Map json) => + _$MenuButtonWebAppFromJson(json); + @override + Map toJson() => _$MenuButtonWebAppToJson(this); +} diff --git a/lib/src/telegram/models/message.dart b/lib/src/telegram/models/message.dart index fafcb7ef..16c15063 100644 --- a/lib/src/telegram/models/message.dart +++ b/lib/src/telegram/models/message.dart @@ -21,26 +21,28 @@ part of '../model.dart'; /// This object represents a message. /// /// https://core.telegram.org/bots/api#message -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class Message { - int message_id; + int messageId; + int? messageThreadId; User? from; - Chat? sender_chat; + Chat? senderChat; int date; Chat chat; - User? forward_from; - Chat? forward_from_chat; - int? forward_from_message_id; - String? forward_signature; - String? forward_sender_name; - int? forward_date; - bool? is_automatic_forward; - Message? reply_to_message; - User? via_bot; - int? edit_date; - bool? has_protected_content; - String? media_group_id; - String? author_signature; + User? forwardFrom; + Chat? forwardFromChat; + int? forwardFromMessageId; + String? forwardSignature; + String? forwardSenderName; + int? forwardDate; + bool? isTopicMessage; + bool? isAutomaticForward; + Message? replyToMessage; + User? viaBot; + int? editDate; + bool? hasProtectedContent; + String? mediaGroupId; + String? authorSignature; String? text; List? entities; Animation? animation; @@ -48,59 +50,73 @@ class Message { Document? document; List? photo; Sticker? sticker; + Story? story; Video? video; - VideoNote? video_note; + VideoNote? videoNote; Voice? voice; String? caption; - List? caption_entities; + List? captionEntities; + bool? hasMediaSpoiler; Contact? contact; Dice? dice; Game? game; Poll? poll; Venue? venue; Location? location; - List? new_chat_members; - User? left_chat_member; - String? new_chat_title; - List? new_chat_photo; - bool? delete_chat_photo; - bool? group_chat_created; - bool? supergroup_chat_created; - bool? channel_chat_created; - MessageAutoDeleteTimerChanged? message_auto_delete_timer_changed; - int? migrate_to_chat_id; - int? migrate_from_chat_id; - Message? pinned_message; + List? newChatMembers; + User? leftChatMember; + String? newChatTitle; + List? newChatPhoto; + bool? deleteChatPhoto; + bool? groupChatCreated; + bool? supergroupChatCreated; + bool? channelChatCreated; + MessageAutoDeleteTimerChanged? messageAutoDeleteTimerChanged; + int? migrateToChatId; + int? migrateFromChatId; + Message? pinnedMessage; Invoice? invoice; - SuccessfulPayment? successful_payment; - String? connected_website; - PassportData? passport_data; - ProximityAlertTriggered? proximity_alert_triggered; - VoiceChatScheduled? voice_chat_scheduled; - VoiceChatStarted? voice_chat_started; - VoiceChatEnded? voice_chat_ended; - VoiceChatParticipantsInvited? voice_chat_participants_invited; - InlineKeyboardMarkup? reply_markup; + SuccessfulPayment? successfulPayment; + UserShared? userShared; + ChatShared? chatShared; + String? connectedWebsite; + WriteAccessAllowed? writeAccessAllowed; + PassportData? passportData; + ProximityAlertTriggered? proximityAlertTriggered; + ForumTopicCreated? forumTopicCreated; + ForumTopicEdited? forumTopicEdited; + ForumTopicClosed? forumTopicClosed; + ForumTopicReopened? forumTopicReopened; + GeneralForumTopicHidden? generalForumTopicHidden; + GeneralForumTopicUnhidden? generalForumTopicUnhidden; + VoiceChatScheduled? videoChatScheduled; + VoiceChatStarted? videoChatStarted; + VoiceChatEnded? videoChatEnded; + VoiceChatParticipantsInvited? videoChatParticipantsInvited; + WebAppData? webAppData; + InlineKeyboardMarkup? replyMarkup; Message({ - required this.message_id, + required this.messageId, + this.messageThreadId, this.from, - this.sender_chat, + this.senderChat, required this.date, required this.chat, - this.forward_from, - this.forward_from_chat, - this.forward_from_message_id, - this.forward_signature, - this.forward_sender_name, - this.forward_date, - this.is_automatic_forward, - this.reply_to_message, - this.via_bot, - this.edit_date, - this.has_protected_content, - this.media_group_id, - this.author_signature, + this.forwardFrom, + this.forwardFromChat, + this.forwardFromMessageId, + this.forwardSignature, + this.forwardSenderName, + this.forwardDate, + this.isTopicMessage, + this.isAutomaticForward, + this.replyToMessage, + this.viaBot, + this.editDate, + this.hasProtectedContent, + this.mediaGroupId, + this.authorSignature, this.text, this.entities, this.animation, @@ -108,63 +124,75 @@ class Message { this.document, this.photo, this.sticker, + this.story, this.video, - this.video_note, + this.videoNote, this.voice, this.caption, - this.caption_entities, + this.captionEntities, + this.hasMediaSpoiler, this.contact, this.dice, this.game, this.poll, this.venue, this.location, - this.new_chat_members, - this.left_chat_member, - this.new_chat_title, - this.new_chat_photo, - this.delete_chat_photo, - this.group_chat_created, - this.supergroup_chat_created, - this.channel_chat_created, - this.message_auto_delete_timer_changed, - this.migrate_to_chat_id, - this.migrate_from_chat_id, - this.pinned_message, + this.newChatMembers, + this.leftChatMember, + this.newChatTitle, + this.newChatPhoto, + this.deleteChatPhoto, + this.groupChatCreated, + this.supergroupChatCreated, + this.channelChatCreated, + this.messageAutoDeleteTimerChanged, + this.migrateToChatId, + this.migrateFromChatId, + this.pinnedMessage, this.invoice, - this.successful_payment, - this.connected_website, - this.passport_data, - this.proximity_alert_triggered, - this.voice_chat_scheduled, - this.voice_chat_started, - this.voice_chat_ended, - this.voice_chat_participants_invited, - this.reply_markup, + this.successfulPayment, + this.userShared, + this.chatShared, + this.connectedWebsite, + this.writeAccessAllowed, + this.passportData, + this.proximityAlertTriggered, + this.forumTopicCreated, + this.forumTopicEdited, + this.forumTopicClosed, + this.forumTopicReopened, + this.generalForumTopicHidden, + this.generalForumTopicUnhidden, + this.videoChatScheduled, + this.videoChatStarted, + this.videoChatEnded, + this.videoChatParticipantsInvited, + this.webAppData, + this.replyMarkup, }); - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) DateTime get date_ => TimeHelper.toDateTime(date); set date_(DateTime dateTime) => date = TimeHelper.toUnixTime(dateTime); - @JsonKey(ignore: true) - DateTime? get forward_date_ => - forward_date == null ? null : TimeHelper.toDateTime(forward_date!); - set forward_date_(DateTime? dateTime) => - forward_date = dateTime == null ? null : TimeHelper.toUnixTime(dateTime); + @JsonKey(includeFromJson: false, includeToJson: false) + DateTime? get forwardDate_ => + forwardDate == null ? null : TimeHelper.toDateTime(forwardDate!); + set forwardDate_(DateTime? dateTime) => + forwardDate = dateTime == null ? null : TimeHelper.toUnixTime(dateTime); - @JsonKey(ignore: true) - DateTime? get edit_date_ => - edit_date == null ? null : TimeHelper.toDateTime(edit_date!); - set edit_date_(DateTime? dateTime) => - edit_date = dateTime == null ? null : TimeHelper.toUnixTime(dateTime); + @JsonKey(includeFromJson: false, includeToJson: false) + DateTime? get editDate_ => + editDate == null ? null : TimeHelper.toDateTime(editDate!); + set editDate_(DateTime? dateTime) => + editDate = dateTime == null ? null : TimeHelper.toUnixTime(dateTime); factory Message.fromJson(Map json) => _$MessageFromJson(json); Map toJson() => _$MessageToJson(this); int indexOfEntity(String? type) { - var etts = entities ?? caption_entities; + var etts = entities ?? captionEntities; if (etts != null) { for (var ett in etts) { if (ett.type == type) return etts.indexOf(ett); @@ -176,7 +204,7 @@ class Message { MessageEntity? entityOf(String? type) { var i = indexOfEntity(type); if (i >= 0) { - return (entities ?? caption_entities)![i]; + return (entities ?? captionEntities)![i]; } else { return null; } diff --git a/lib/src/telegram/models/message_auto_delete_timer_changed.dart b/lib/src/telegram/models/message_auto_delete_timer_changed.dart index fea47cba..a4c9ea99 100644 --- a/lib/src/telegram/models/message_auto_delete_timer_changed.dart +++ b/lib/src/telegram/models/message_auto_delete_timer_changed.dart @@ -21,17 +21,17 @@ part of '../model.dart'; /// This object represents a service message about a change in auto-delete timer settings. /// /// https://core.telegram.org/bots/api#messageautodeletetimerchanged -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class MessageAutoDeleteTimerChanged { - int message_auto_delete_time; + int messageAutoDeleteTime; - MessageAutoDeleteTimerChanged({required this.message_auto_delete_time}); + MessageAutoDeleteTimerChanged({required this.messageAutoDeleteTime}); - @JsonKey(ignore: true) - Duration get message_auto_delete_time_ => - TimeHelper.toDuration(message_auto_delete_time); - set message_auto_delete_time_(Duration duration) => - message_auto_delete_time = TimeHelper.toSeconds(duration); + @JsonKey(includeFromJson: false, includeToJson: false) + Duration get messageAutoDeleteTime_ => + TimeHelper.toDuration(messageAutoDeleteTime); + set messageAutoDeleteTime_(Duration duration) => + messageAutoDeleteTime = TimeHelper.toSeconds(duration); factory MessageAutoDeleteTimerChanged.fromJson(Map json) => _$MessageAutoDeleteTimerChangedFromJson(json); diff --git a/lib/src/telegram/models/message_entity.dart b/lib/src/telegram/models/message_entity.dart index caeb08c2..8438171a 100644 --- a/lib/src/telegram/models/message_entity.dart +++ b/lib/src/telegram/models/message_entity.dart @@ -21,24 +21,25 @@ part of '../model.dart'; /// This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc. /// /// https://core.telegram.org/bots/api#messageentity -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class MessageEntity { - static const String MENTION = 'mention'; - static const String HASHTAG = 'hashtag'; - static const String CASHTAG = 'cashtag'; - static const String BOT_COMMAND = 'bot_command'; - static const String URL = 'url'; - static const String EMAIL = 'email'; - static const String PHONE_NUMBER = 'phone_number'; - static const String BOLD = 'bold'; - static const String ITALIC = 'italic'; - static const String UNDERLINE = 'underline'; - static const String STRIKETHROUGH = 'strikethrough'; - static const String SPOILER = 'spoiler'; - static const String CODE = 'code'; - static const String PRE = 'pre'; - static const String TEXT_LINK = 'text_link'; - static const String TEXT_MENTION = 'text_mention'; + static const typeMention = 'mention'; + static const typeHashtag = 'hashtag'; + static const typeCashtag = 'cashtag'; + static const typeBotCommand = 'bot_command'; + static const typeUrl = 'url'; + static const typeEmail = 'email'; + static const typePhoneNmber = 'phone_number'; + static const typeBold = 'bold'; + static const typeItalic = 'italic'; + static const typeUnderline = 'underline'; + static const typeStrikethrough = 'strikethrough'; + static const typeSpolier = 'spoiler'; + static const typeCode = 'code'; + static const typePre = 'pre'; + static const typeTextLink = 'text_link'; + static const typeTextMention = 'text_mention'; + static const typeCustomEmoji = 'custom_emoji'; String type; int offset; @@ -46,6 +47,7 @@ class MessageEntity { String? url; User? user; String? language; + String? customEmojiId; MessageEntity({ required this.type, required this.offset, @@ -53,6 +55,7 @@ class MessageEntity { this.url, this.user, this.language, + this.customEmojiId, }); factory MessageEntity.fromJson(Map json) => _$MessageEntityFromJson(json); diff --git a/lib/src/telegram/models/message_id.dart b/lib/src/telegram/models/message_id.dart index c7436850..a5c3e189 100644 --- a/lib/src/telegram/models/message_id.dart +++ b/lib/src/telegram/models/message_id.dart @@ -21,11 +21,11 @@ part of '../model.dart'; /// This object represents an animated emoji that displays a random value. /// /// https://core.telegram.org/bots/api#messageid -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class MessageId { - int message_id; + int messageId; MessageId({ - required this.message_id, + required this.messageId, }); factory MessageId.fromJson(Map json) => _$MessageIdFromJson(json); diff --git a/lib/src/telegram/models/order_info.dart b/lib/src/telegram/models/order_info.dart index 79ff41ac..7af55d17 100644 --- a/lib/src/telegram/models/order_info.dart +++ b/lib/src/telegram/models/order_info.dart @@ -21,15 +21,15 @@ part of '../model.dart'; /// This object represents information about an order. /// /// https://core.telegram.org/bots/api#orderinfo -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class OrderInfo { String? name; - String? phone_number; + String? phoneNumber; String? email; ShippingAddress? shippingAddress; OrderInfo({ this.name, - this.phone_number, + this.phoneNumber, this.email, this.shippingAddress, }); diff --git a/lib/src/telegram/models/passport_data.dart b/lib/src/telegram/models/passport_data.dart index aaaa9f36..82d0032d 100644 --- a/lib/src/telegram/models/passport_data.dart +++ b/lib/src/telegram/models/passport_data.dart @@ -21,7 +21,7 @@ part of '../model.dart'; /// Contains information about Telegram Passport data shared with the bot by the user. /// /// https://core.telegram.org/bots/api#passportdata -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class PassportData { List data; EncryptedCredentials credentials; diff --git a/lib/src/telegram/models/passport_element_error.dart b/lib/src/telegram/models/passport_element_error.dart index 8ff4f265..5e3befba 100644 --- a/lib/src/telegram/models/passport_element_error.dart +++ b/lib/src/telegram/models/passport_element_error.dart @@ -32,14 +32,14 @@ part of '../model.dart'; /// * [PassportElementErrorUnspecified](https://core.telegram.org/bots/api#passportelementerrorunspecified) /// /// https://core.telegram.org/bots/api#passportelementerror -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class PassportElementError { - static const String PERSONAL_DETAILS = 'personal_details'; - static const String PASSPORT = 'passport'; - static const String DRIVER_LICENSE = 'driver_license'; - static const String IDENTITY_CARD = 'identity_card'; - static const String INTERNAL_PASSPORT = 'internal_passport'; - static const String ADDRESS = 'address'; + static const typePersonalDetails = 'personal_details'; + static const typePassport = 'passport'; + static const typeDriverLicense = 'driver_license'; + static const typeIdentityCard = 'identity_card'; + static const typeInternalPassport = 'internal_passport'; + static const typeAddress = 'address'; String source; String type; diff --git a/lib/src/telegram/models/passport_element_error_data_field.dart b/lib/src/telegram/models/passport_element_error_data_field.dart index e6c50bda..bf1f3dd6 100644 --- a/lib/src/telegram/models/passport_element_error_data_field.dart +++ b/lib/src/telegram/models/passport_element_error_data_field.dart @@ -23,7 +23,7 @@ part of '../model.dart'; /// The error is considered resolved when the field's value changes. /// /// https://core.telegram.org/bots/api#passportelementerrordatafield -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class PassportElementErrorDataField implements PassportElementError { @override String source; @@ -31,14 +31,14 @@ class PassportElementErrorDataField implements PassportElementError { String type; @override String message; - String field_name; - String data_hash; + String fieldName; + String dataHash; PassportElementErrorDataField({ required this.source, required this.type, required this.message, - required this.field_name, - required this.data_hash, + required this.fieldName, + required this.dataHash, }); factory PassportElementErrorDataField.fromJson(Map json) => _$PassportElementErrorDataFieldFromJson(json); diff --git a/lib/src/telegram/models/passport_element_error_file.dart b/lib/src/telegram/models/passport_element_error_file.dart index b11abb28..e223ca58 100644 --- a/lib/src/telegram/models/passport_element_error_file.dart +++ b/lib/src/telegram/models/passport_element_error_file.dart @@ -23,7 +23,7 @@ part of '../model.dart'; /// The error is considered resolved when the file with the document scan changes. /// /// https://core.telegram.org/bots/api#passportelementerrorfile -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class PassportElementErrorFile implements PassportElementError { @override String source; @@ -31,12 +31,12 @@ class PassportElementErrorFile implements PassportElementError { String type; @override String message; - String file_hash; + String fileHash; PassportElementErrorFile({ required this.source, required this.type, required this.message, - required this.file_hash, + required this.fileHash, }); factory PassportElementErrorFile.fromJson(Map json) => _$PassportElementErrorFileFromJson(json); diff --git a/lib/src/telegram/models/passport_element_error_files.dart b/lib/src/telegram/models/passport_element_error_files.dart index d46ea885..8bb8ffa2 100644 --- a/lib/src/telegram/models/passport_element_error_files.dart +++ b/lib/src/telegram/models/passport_element_error_files.dart @@ -23,7 +23,7 @@ part of '../model.dart'; /// The error is considered resolved when the list of files containing the scans changes. /// /// https://core.telegram.org/bots/api#passportelementerrorfiles -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class PassportElementErrorFiles implements PassportElementError { @override String source; @@ -31,12 +31,12 @@ class PassportElementErrorFiles implements PassportElementError { String type; @override String message; - List file_hashes; + List fileHashes; PassportElementErrorFiles({ required this.source, required this.type, required this.message, - required this.file_hashes, + required this.fileHashes, }); factory PassportElementErrorFiles.fromJson(Map json) => _$PassportElementErrorFilesFromJson(json); diff --git a/lib/src/telegram/models/passport_element_error_front_side.dart b/lib/src/telegram/models/passport_element_error_front_side.dart index 9b56f473..81a69ce1 100644 --- a/lib/src/telegram/models/passport_element_error_front_side.dart +++ b/lib/src/telegram/models/passport_element_error_front_side.dart @@ -23,7 +23,7 @@ part of '../model.dart'; /// The error is considered resolved when the file with the front side of the document changes. /// /// https://core.telegram.org/bots/api#passportelementerrorfrontside -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class PassportElementErrorFrontSide implements PassportElementError { @override String source; @@ -31,12 +31,12 @@ class PassportElementErrorFrontSide implements PassportElementError { String type; @override String message; - String file_hash; + String fileHash; PassportElementErrorFrontSide({ required this.source, required this.type, required this.message, - required this.file_hash, + required this.fileHash, }); factory PassportElementErrorFrontSide.fromJson(Map json) => _$PassportElementErrorFrontSideFromJson(json); diff --git a/lib/src/telegram/models/passport_element_error_reverse_side.dart b/lib/src/telegram/models/passport_element_error_reverse_side.dart index feb3e4b9..f5eeceda 100644 --- a/lib/src/telegram/models/passport_element_error_reverse_side.dart +++ b/lib/src/telegram/models/passport_element_error_reverse_side.dart @@ -23,7 +23,7 @@ part of '../model.dart'; /// The error is considered resolved when the file with reverse side of the document changes. /// /// https://core.telegram.org/bots/api#passportelementerrorreverseside -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class PassportElementErrorReverseSide implements PassportElementError { @override String source; @@ -31,12 +31,12 @@ class PassportElementErrorReverseSide implements PassportElementError { String type; @override String message; - String file_hash; + String fileHash; PassportElementErrorReverseSide({ required this.source, required this.type, required this.message, - required this.file_hash, + required this.fileHash, }); factory PassportElementErrorReverseSide.fromJson(Map json) => _$PassportElementErrorReverseSideFromJson(json); diff --git a/lib/src/telegram/models/passport_element_error_selfie.dart b/lib/src/telegram/models/passport_element_error_selfie.dart index 231cbfbe..1e2ec033 100644 --- a/lib/src/telegram/models/passport_element_error_selfie.dart +++ b/lib/src/telegram/models/passport_element_error_selfie.dart @@ -23,7 +23,7 @@ part of '../model.dart'; /// The error is considered resolved when the file with the selfie changes. /// /// https://core.telegram.org/bots/api#passportelementerrorselfie -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class PassportElementErrorSelfie implements PassportElementError { @override String source; @@ -31,12 +31,12 @@ class PassportElementErrorSelfie implements PassportElementError { String type; @override String message; - String file_hash; + String fileHash; PassportElementErrorSelfie({ required this.source, required this.type, required this.message, - required this.file_hash, + required this.fileHash, }); factory PassportElementErrorSelfie.fromJson(Map json) => _$PassportElementErrorSelfieFromJson(json); diff --git a/lib/src/telegram/models/passport_element_error_translation_file.dart b/lib/src/telegram/models/passport_element_error_translation_file.dart index fbfa74be..5ece1b97 100644 --- a/lib/src/telegram/models/passport_element_error_translation_file.dart +++ b/lib/src/telegram/models/passport_element_error_translation_file.dart @@ -23,7 +23,7 @@ part of '../model.dart'; /// The error is considered resolved when the file changes. /// /// https://core.telegram.org/bots/api#passportelementerrortranslationfile -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class PassportElementErrorTranslationFile implements PassportElementError { @override String source; @@ -31,12 +31,12 @@ class PassportElementErrorTranslationFile implements PassportElementError { String type; @override String message; - String file_hash; + String fileHash; PassportElementErrorTranslationFile({ required this.source, required this.type, required this.message, - required this.file_hash, + required this.fileHash, }); factory PassportElementErrorTranslationFile.fromJson( Map json) => diff --git a/lib/src/telegram/models/passport_element_error_translation_files.dart b/lib/src/telegram/models/passport_element_error_translation_files.dart index 55a635cc..98386e18 100644 --- a/lib/src/telegram/models/passport_element_error_translation_files.dart +++ b/lib/src/telegram/models/passport_element_error_translation_files.dart @@ -23,7 +23,7 @@ part of '../model.dart'; /// The error is considered resolved when a file with the document translation change. /// /// https://core.telegram.org/bots/api#passportelementerrortranslationfiles -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class PassportElementErrorTranslationFiles implements PassportElementError { @override String source; @@ -31,12 +31,12 @@ class PassportElementErrorTranslationFiles implements PassportElementError { String type; @override String message; - List file_hashes; + List fileHashes; PassportElementErrorTranslationFiles({ required this.source, required this.type, required this.message, - required this.file_hashes, + required this.fileHashes, }); factory PassportElementErrorTranslationFiles.fromJson( Map json) => diff --git a/lib/src/telegram/models/passport_element_error_unspecified.dart b/lib/src/telegram/models/passport_element_error_unspecified.dart index 9d49dbbe..6b6b71f3 100644 --- a/lib/src/telegram/models/passport_element_error_unspecified.dart +++ b/lib/src/telegram/models/passport_element_error_unspecified.dart @@ -23,7 +23,7 @@ part of '../model.dart'; /// The error is considered resolved when new data is added. /// /// https://core.telegram.org/bots/api#passportelementerrorunspecified -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class PassportElementErrorUnspecified implements PassportElementError { @override String source; @@ -31,12 +31,12 @@ class PassportElementErrorUnspecified implements PassportElementError { String type; @override String message; - String element_hash; + String elementHash; PassportElementErrorUnspecified({ required this.source, required this.type, required this.message, - required this.element_hash, + required this.elementHash, }); factory PassportElementErrorUnspecified.fromJson(Map json) => _$PassportElementErrorUnspecifiedFromJson(json); diff --git a/lib/src/telegram/models/passport_file.dart b/lib/src/telegram/models/passport_file.dart index d8ddb517..aab621a8 100644 --- a/lib/src/telegram/models/passport_file.dart +++ b/lib/src/telegram/models/passport_file.dart @@ -23,24 +23,24 @@ part of '../model.dart'; /// Currently all Telegram Passport files are in JPEG format when decrypted and don't exceed 10MB. /// /// https://core.telegram.org/bots/api#passportfile -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class PassportFile { - String file_id; - String file_unique_id; - int file_size; - int file_date; + String fileId; + String fileUniqueId; + int fileSize; + int fileDate; PassportFile({ - required this.file_id, - required this.file_unique_id, - required this.file_size, - required this.file_date, + required this.fileId, + required this.fileUniqueId, + required this.fileSize, + required this.fileDate, }); - @JsonKey(ignore: true) - DateTime get file_date_ => TimeHelper.toDateTime(file_date); - set file_date_(DateTime dateTime) => - file_date = TimeHelper.toUnixTime(dateTime); + @JsonKey(includeFromJson: false, includeToJson: false) + DateTime get fileDate_ => TimeHelper.toDateTime(fileDate); + set fileDate_(DateTime dateTime) => + fileDate = TimeHelper.toUnixTime(dateTime); factory PassportFile.fromJson(Map json) => _$PassportFileFromJson(json); diff --git a/lib/src/telegram/models/photo_size.dart b/lib/src/telegram/models/photo_size.dart index 7647316a..54f190d2 100644 --- a/lib/src/telegram/models/photo_size.dart +++ b/lib/src/telegram/models/photo_size.dart @@ -24,19 +24,19 @@ part of '../model.dart'; /// /// [file]: https://core.telegram.org/bots/api#document /// [sticker]: https://core.telegram.org/bots/api#sticker -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class PhotoSize { - String file_id; - String file_unique_id; + String fileId; + String fileUniqueId; int width; int height; - int? file_size; + int? fileSize; PhotoSize({ - required this.file_id, - required this.file_unique_id, + required this.fileId, + required this.fileUniqueId, required this.width, required this.height, - this.file_size, + this.fileSize, }); factory PhotoSize.fromJson(Map json) => _$PhotoSizeFromJson(json); diff --git a/lib/src/telegram/models/poll.dart b/lib/src/telegram/models/poll.dart index 5b33d1b3..af67ac3e 100644 --- a/lib/src/telegram/models/poll.dart +++ b/lib/src/telegram/models/poll.dart @@ -24,51 +24,51 @@ part of '../model.dart'; /// /// [file]: https://core.telegram.org/bots/api#document /// [sticker]: https://core.telegram.org/bots/api#sticker -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class Poll { - static const String REGULAR = 'regular'; - static const String QUIZ = 'quiz'; + static const typeRegular = 'regular'; + static const typeQuiz = 'quiz'; String id; String question; List options; - int total_voter_count; - bool is_closed; - bool is_anonymous; + int totalVoterCount; + bool isClosed; + bool isAnonymous; String type; - bool allows_multiple_answers; - int? correct_option_id; + bool allowsMultipleAnswers; + int? correctOptionId; String? explanation; - List? explanation_entities; - int? open_period; - int? close_date; + List? explanationEntities; + int? openPeriod; + int? closeDate; Poll({ required this.id, required this.question, required this.options, - required this.total_voter_count, - required this.is_closed, - required this.is_anonymous, + required this.totalVoterCount, + required this.isClosed, + required this.isAnonymous, required this.type, - required this.allows_multiple_answers, - this.correct_option_id, + required this.allowsMultipleAnswers, + this.correctOptionId, this.explanation, - this.explanation_entities, - this.open_period, - this.close_date, + this.explanationEntities, + this.openPeriod, + this.closeDate, }); factory Poll.fromJson(Map json) => _$PollFromJson(json); Map toJson() => _$PollToJson(this); - @JsonKey(ignore: true) - Duration? get open_period_ => - open_period == null ? null : TimeHelper.toDuration(open_period!); - set open_period_(Duration? duration) => - open_period = duration == null ? null : TimeHelper.toSeconds(duration); + @JsonKey(includeFromJson: false, includeToJson: false) + Duration? get openPeriod_ => + openPeriod == null ? null : TimeHelper.toDuration(openPeriod!); + set openPeriod_(Duration? duration) => + openPeriod = duration == null ? null : TimeHelper.toSeconds(duration); - @JsonKey(ignore: true) - DateTime? get close_date_ => - close_date == null ? null : TimeHelper.toDateTime(close_date!); - set close_date_(DateTime? dateTime) => - close_date = dateTime == null ? null : TimeHelper.toUnixTime(dateTime); + @JsonKey(includeFromJson: false, includeToJson: false) + DateTime? get closeDate_ => + closeDate == null ? null : TimeHelper.toDateTime(closeDate!); + set closeDate_(DateTime? dateTime) => + closeDate = dateTime == null ? null : TimeHelper.toUnixTime(dateTime); } diff --git a/lib/src/telegram/models/poll_answer.dart b/lib/src/telegram/models/poll_answer.dart index 5fd59d3d..f2e68cd2 100644 --- a/lib/src/telegram/models/poll_answer.dart +++ b/lib/src/telegram/models/poll_answer.dart @@ -21,15 +21,17 @@ part of '../model.dart'; /// This object represents type of a poll, which is allowed to be created and sent when the corresponding button is pressed. /// /// https://core.telegram.org/bots/api#pollanswer -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class PollAnswer { - String poll_id; - User user; - List option_ids; + String pollId; + Chat? voterChat; + User? user; + List optionIds; PollAnswer({ - required this.poll_id, - required this.user, - required this.option_ids, + required this.pollId, + this.voterChat, + this.user, + required this.optionIds, }); factory PollAnswer.fromJson(Map json) => _$PollAnswerFromJson(json); diff --git a/lib/src/telegram/models/poll_option.dart b/lib/src/telegram/models/poll_option.dart index cd5df5f2..32ac04f6 100644 --- a/lib/src/telegram/models/poll_option.dart +++ b/lib/src/telegram/models/poll_option.dart @@ -24,13 +24,13 @@ part of '../model.dart'; /// /// [file]: https://core.telegram.org/bots/api#document /// [sticker]: https://core.telegram.org/bots/api#sticker -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class PollOption { String text; - int voter_count; + int voterCount; PollOption({ required this.text, - required this.voter_count, + required this.voterCount, }); factory PollOption.fromJson(Map json) => _$PollOptionFromJson(json); diff --git a/lib/src/telegram/models/pre_checkout_query.dart b/lib/src/telegram/models/pre_checkout_query.dart index 148396d1..a054c294 100644 --- a/lib/src/telegram/models/pre_checkout_query.dart +++ b/lib/src/telegram/models/pre_checkout_query.dart @@ -21,23 +21,23 @@ part of '../model.dart'; /// This object contains information about an incoming pre-checkout query. /// /// https://core.telegram.org/bots/api#precheckoutquery -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class PreCheckoutQuery { String id; User from; String currency; - int total_amount; - String invoice_payload; - String? shipping_option_id; - OrderInfo? order_info; + int totalAmount; + String invoicePayload; + String? shippingOptionId; + OrderInfo? orderInfo; PreCheckoutQuery({ required this.id, required this.from, required this.currency, - required this.total_amount, - required this.invoice_payload, - this.shipping_option_id, - this.order_info, + required this.totalAmount, + required this.invoicePayload, + this.shippingOptionId, + this.orderInfo, }); factory PreCheckoutQuery.fromJson(Map json) => _$PreCheckoutQueryFromJson(json); diff --git a/lib/src/telegram/models/proximity_alert_triggered.dart b/lib/src/telegram/models/proximity_alert_triggered.dart index b1d70821..d4432e06 100644 --- a/lib/src/telegram/models/proximity_alert_triggered.dart +++ b/lib/src/telegram/models/proximity_alert_triggered.dart @@ -23,7 +23,7 @@ part of '../model.dart'; /// sent whenever a user in the chat triggers a proximity alert set by another user. /// /// https://core.telegram.org/bots/api#proximityalerttriggered -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ProximityAlertTriggered { User traveler; User watcher; diff --git a/lib/src/telegram/models/reply_keyboard_markup.dart b/lib/src/telegram/models/reply_keyboard_markup.dart index 7d986c7d..7e7cacc8 100644 --- a/lib/src/telegram/models/reply_keyboard_markup.dart +++ b/lib/src/telegram/models/reply_keyboard_markup.dart @@ -26,18 +26,20 @@ part of '../model.dart'; /// /// [custom keyboard]: https://core.telegram.org/bots#keyboards /// [Introduction to bots]: https://core.telegram.org/bots#keyboards -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ReplyKeyboardMarkup implements ReplyMarkup { List> keyboard; - bool? resize_keyboard; - bool? one_time_keyboard; - String? input_field_placeholder; + bool? isPersistent; + bool? resizeKeyboard; + bool? oneTimeKeyboard; + String? inputFieldPlaceholder; bool? selective; ReplyKeyboardMarkup({ required this.keyboard, - this.resize_keyboard, - this.one_time_keyboard, - this.input_field_placeholder, + this.isPersistent, + this.resizeKeyboard, + this.oneTimeKeyboard, + this.inputFieldPlaceholder, this.selective, }); factory ReplyKeyboardMarkup.fromJson(Map json) => diff --git a/lib/src/telegram/models/reply_keyboard_remove.dart b/lib/src/telegram/models/reply_keyboard_remove.dart index 934f57b8..0a8c2b5b 100644 --- a/lib/src/telegram/models/reply_keyboard_remove.dart +++ b/lib/src/telegram/models/reply_keyboard_remove.dart @@ -29,12 +29,12 @@ part of '../model.dart'; /// https://core.telegram.org/bots/api#replykeyboardremove /// /// [ReplyKeyboardMarkup]: https://core.telegram.org/bots/api#replykeyboardmarkup -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ReplyKeyboardRemove implements ReplyMarkup { - bool remove_keyboard; + bool removeKeyboard; bool? selective; ReplyKeyboardRemove({ - required this.remove_keyboard, + required this.removeKeyboard, this.selective, }); factory ReplyKeyboardRemove.fromJson(Map json) => diff --git a/lib/src/telegram/models/reply_markup.dart b/lib/src/telegram/models/reply_markup.dart index 62fd772a..b3331628 100644 --- a/lib/src/telegram/models/reply_markup.dart +++ b/lib/src/telegram/models/reply_markup.dart @@ -27,7 +27,7 @@ part of '../model.dart'; /// /// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [custom reply keyboard]: https://core.telegram.org/bots#keyboards -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ReplyMarkup { ReplyMarkup(); factory ReplyMarkup.fromJson(Map json) => diff --git a/lib/src/telegram/models/response.dart b/lib/src/telegram/models/response.dart new file mode 100644 index 00000000..046222e6 --- /dev/null +++ b/lib/src/telegram/models/response.dart @@ -0,0 +1,80 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object is not explicitly described as an object in the Telegram Bot API. +/// +/// The response contains a JSON object, which always has a Boolean field +/// 'ok' and may have an optional String field 'description' with a +/// human-readable description of the result. If 'ok' equals True, the +/// request was successful and the result of the query can be found in the +/// 'result' field. In case of an unsuccessful request, 'ok' equals false +/// and the error is explained in the 'description'. An Integer +/// 'error_code' field is also returned, but its contents are subject to +/// change in the future. Some errors may also have an optional field +/// 'parameters' of the type ResponseParameters, which can help to +/// automatically handle the error. +/// +/// https://core.telegram.org/bots/api#making-requests +@JsonSerializable(fieldRename: FieldRename.snake) +class Response { + bool ok; + + Response({ + required this.ok, + }); + + factory Response.fromJson(Map json) => + _$ResponseFromJson(json); + Map toJson() => _$ResponseToJson(this); +} + +@JsonSerializable(fieldRename: FieldRename.snake) +class SuccessResponse { + bool ok; + dynamic result; + + SuccessResponse({ + required this.ok, + this.result, + }); + + factory SuccessResponse.fromJson(Map json) => + _$SuccessResponseFromJson(json); + Map toJson() => _$SuccessResponseToJson(this); +} + +@JsonSerializable(fieldRename: FieldRename.snake) +class ErrorResponse { + bool ok; + String description; + int errorCode; + ResponseParameters? parameters; + + ErrorResponse({ + required this.ok, + required this.description, + required this.errorCode, + required this.parameters, + }); + + factory ErrorResponse.fromJson(Map json) => + _$ErrorResponseFromJson(json); + Map toJson() => _$ErrorResponseToJson(this); +} diff --git a/lib/src/telegram/models/response_parameters.dart b/lib/src/telegram/models/response_parameters.dart index e2bf9093..918a8dbb 100644 --- a/lib/src/telegram/models/response_parameters.dart +++ b/lib/src/telegram/models/response_parameters.dart @@ -21,21 +21,21 @@ part of '../model.dart'; /// Contains information about why a request was unsuccessful. /// /// https://core.telegram.org/bots/api#responseparameters -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ResponseParameters { - int? migrate_to_chat_id; - int? retry_after; + int? migrateToChatId; + int? retryAfter; ResponseParameters({ - this.migrate_to_chat_id, - this.retry_after, + this.migrateToChatId, + this.retryAfter, }); - @JsonKey(ignore: true) - Duration? get retry_after_ => - retry_after == null ? null : TimeHelper.toDuration(retry_after!); - set retry_after_(Duration? duration) => - retry_after = duration == null ? null : TimeHelper.toSeconds(duration); + @JsonKey(includeFromJson: false, includeToJson: false) + Duration? get retryAfter_ => + retryAfter == null ? null : TimeHelper.toDuration(retryAfter!); + set retryAfter_(Duration? duration) => + retryAfter = duration == null ? null : TimeHelper.toSeconds(duration); factory ResponseParameters.fromJson(Map json) => _$ResponseParametersFromJson(json); diff --git a/lib/src/telegram/models/sent_web_app_message.dart b/lib/src/telegram/models/sent_web_app_message.dart new file mode 100644 index 00000000..89bed4bf --- /dev/null +++ b/lib/src/telegram/models/sent_web_app_message.dart @@ -0,0 +1,36 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2022 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// Describes an inline message sent by a [Web App] on behalf of a user. +/// +/// https://core.telegram.org/bots/api#sentwebappmessage +/// +/// [Web App]: https://core.telegram.org/bots/webapps + +@JsonSerializable(fieldRename: FieldRename.snake) +class SentWebAppMessage { + String? inlineMessageId; + + SentWebAppMessage({this.inlineMessageId}); + + factory SentWebAppMessage.fromJson(Map json) => + _$SentWebAppMessageFromJson(json); + Map toJson() => _$SentWebAppMessageToJson(this); +} diff --git a/lib/src/telegram/models/shipping_address.dart b/lib/src/telegram/models/shipping_address.dart index 224afcff..8bad7662 100644 --- a/lib/src/telegram/models/shipping_address.dart +++ b/lib/src/telegram/models/shipping_address.dart @@ -21,21 +21,21 @@ part of '../model.dart'; /// This object represents a shipping address. /// /// https://core.telegram.org/bots/api#shippingaddress -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ShippingAddress { - String country_code; + String countryCode; String state; String city; - String street_line1; - String street_line2; - String post_code; + String streetLine1; + String streetLine2; + String postCode; ShippingAddress({ - required this.country_code, + required this.countryCode, required this.state, required this.city, - required this.street_line1, - required this.street_line2, - required this.post_code, + required this.streetLine1, + required this.streetLine2, + required this.postCode, }); factory ShippingAddress.fromJson(Map json) => _$ShippingAddressFromJson(json); diff --git a/lib/src/telegram/models/shipping_option.dart b/lib/src/telegram/models/shipping_option.dart index f7c8e266..d3f93feb 100644 --- a/lib/src/telegram/models/shipping_option.dart +++ b/lib/src/telegram/models/shipping_option.dart @@ -21,7 +21,7 @@ part of '../model.dart'; /// This object represents one shipping option. /// /// https://core.telegram.org/bots/api#shippingoption -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ShippingOption { String id; String title; diff --git a/lib/src/telegram/models/shipping_query.dart b/lib/src/telegram/models/shipping_query.dart index 90831790..d2a554cc 100644 --- a/lib/src/telegram/models/shipping_query.dart +++ b/lib/src/telegram/models/shipping_query.dart @@ -21,17 +21,17 @@ part of '../model.dart'; /// This object contains information about an incoming shipping query. /// /// https://core.telegram.org/bots/api#shippingquery -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class ShippingQuery { String id; User from; - String invoice_payload; - ShippingAddress shipping_address; + String invoicePayload; + ShippingAddress shippingAddress; ShippingQuery({ required this.id, required this.from, - required this.invoice_payload, - required this.shipping_address, + required this.invoicePayload, + required this.shippingAddress, }); factory ShippingQuery.fromJson(Map json) => _$ShippingQueryFromJson(json); diff --git a/lib/src/telegram/models/sticker.dart b/lib/src/telegram/models/sticker.dart index 6a93c86b..30d4a965 100644 --- a/lib/src/telegram/models/sticker.dart +++ b/lib/src/telegram/models/sticker.dart @@ -21,31 +21,37 @@ part of '../model.dart'; /// This object represents a sticker. /// /// https://core.telegram.org/bots/api#sticker -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class Sticker { - String file_id; - String file_unique_id; + String fileId; + String fileUniqueId; int width; int height; - bool is_animated; - bool is_video; - PhotoSize? thumb; + bool isAnimated; + bool isVideo; + PhotoSize? thumbnail; String? emoji; - String? set_name; - MaskPosition? mask_position; - int? file_size; + String? setName; + File? premiumAnimation; + MaskPosition? maskPosition; + String? customEmojiId; + bool? needsRepainting; + int? fileSize; Sticker({ - required this.file_id, - required this.file_unique_id, + required this.fileId, + required this.fileUniqueId, required this.width, required this.height, - required this.is_animated, - required this.is_video, - this.thumb, + required this.isAnimated, + required this.isVideo, + this.thumbnail, this.emoji, - this.set_name, - this.mask_position, - this.file_size, + this.setName, + this.premiumAnimation, + this.maskPosition, + this.customEmojiId, + this.needsRepainting, + this.fileSize, }); factory Sticker.fromJson(Map json) => _$StickerFromJson(json); diff --git a/lib/src/telegram/models/sticker_set.dart b/lib/src/telegram/models/sticker_set.dart index 626f5449..5fcf6ab3 100644 --- a/lib/src/telegram/models/sticker_set.dart +++ b/lib/src/telegram/models/sticker_set.dart @@ -21,23 +21,23 @@ part of '../model.dart'; /// This object represents a sticker set. /// /// https://core.telegram.org/bots/api#stickerset -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class StickerSet { String name; String title; - bool is_animated; - bool is_video; - bool contains_masks; + String stickerType; + bool isAnimated; + bool isVideo; List stickers; - PhotoSize? thumb; + PhotoSize? thumbnail; StickerSet({ required this.name, required this.title, - required this.is_animated, - required this.is_video, - required this.contains_masks, + required this.stickerType, + required this.isAnimated, + required this.isVideo, required this.stickers, - this.thumb, + this.thumbnail, }); factory StickerSet.fromJson(Map json) => _$StickerSetFromJson(json); diff --git a/lib/src/telegram/models/story.dart b/lib/src/telegram/models/story.dart new file mode 100644 index 00000000..83989f08 --- /dev/null +++ b/lib/src/telegram/models/story.dart @@ -0,0 +1,29 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object represents a service message about General forum topic unhidden in the chat. +/// +/// https://core.telegram.org/bots/api#writeaccessallowed +@JsonSerializable(fieldRename: FieldRename.snake) +class Story { + Story(); + factory Story.fromJson(Map json) => _$StoryFromJson(json); + Map toJson() => _$StoryToJson(this); +} diff --git a/lib/src/telegram/models/successful_payment.dart b/lib/src/telegram/models/successful_payment.dart index 71153cbf..3b54ec45 100644 --- a/lib/src/telegram/models/successful_payment.dart +++ b/lib/src/telegram/models/successful_payment.dart @@ -21,23 +21,23 @@ part of '../model.dart'; /// This object contains basic information about a successful payment. /// /// https://core.telegram.org/bots/api#successfulpayment -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class SuccessfulPayment { String currency; - int total_amount; - String invoice_payload; - String? shipping_option_id; - OrderInfo? order_info; - String telegram_payment_charge_id; - String provider_payment_charge_id; + int totalAmount; + String invoicePayload; + String? shippingOptionId; + OrderInfo? orderInfo; + String telegramPaymentChargeId; + String providerPaymentChargeId; SuccessfulPayment({ required this.currency, - required this.total_amount, - required this.invoice_payload, - this.shipping_option_id, - this.order_info, - required this.telegram_payment_charge_id, - required this.provider_payment_charge_id, + required this.totalAmount, + required this.invoicePayload, + this.shippingOptionId, + this.orderInfo, + required this.telegramPaymentChargeId, + required this.providerPaymentChargeId, }); factory SuccessfulPayment.fromJson(Map json) => _$SuccessfulPaymentFromJson(json); diff --git a/lib/src/telegram/models/switch_inline_query_chosen_chat.dart b/lib/src/telegram/models/switch_inline_query_chosen_chat.dart new file mode 100644 index 00000000..1f6d5ce0 --- /dev/null +++ b/lib/src/telegram/models/switch_inline_query_chosen_chat.dart @@ -0,0 +1,44 @@ +part of '../model.dart'; + +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/// This object represents an inline button that switches the current user to inline mode in a chosen chat, with an optional default inline query. +/// +/// https://core.telegram.org/bots/api#inlinequeryresultsbutton +@JsonSerializable(fieldRename: FieldRename.snake) +class SwitchInlineQueryChosenChat { + String? query; + bool? allowUserChats; + bool? allowBotChats; + bool? allowGroupChats; + bool? allowChannelChats; + + SwitchInlineQueryChosenChat({ + this.query, + this.allowUserChats, + this.allowBotChats, + this.allowGroupChats, + this.allowChannelChats, + }); + + factory SwitchInlineQueryChosenChat.fromJson(Map json) => + _$SwitchInlineQueryChosenChatFromJson(json); + + Map toJson() => _$SwitchInlineQueryChosenChatToJson(this); +} diff --git a/lib/src/telegram/models/update.dart b/lib/src/telegram/models/update.dart index ab18ba72..59b4e20a 100644 --- a/lib/src/telegram/models/update.dart +++ b/lib/src/telegram/models/update.dart @@ -23,39 +23,39 @@ part of '../model.dart'; /// At most one of the optional parameters can be present in any given update. /// /// https://core.telegram.org/bots/api#update -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class Update { - int update_id; + int updateId; Message? message; - Message? edited_message; - Message? channel_post; - Message? edited_channel_post; - InlineQuery? inline_query; - ChosenInlineResult? chosen_inline_result; - CallbackQuery? callback_query; - ShippingQuery? shipping_query; - PreCheckoutQuery? pre_checkout_query; + Message? editedMessage; + Message? channelPost; + Message? editedChannelPost; + InlineQuery? inlineQuery; + ChosenInlineResult? chosenInlineResult; + CallbackQuery? callbackQuery; + ShippingQuery? shippingQuery; + PreCheckoutQuery? preCheckoutQuery; Poll? poll; - PollAnswer? poll_answer; - ChatMemberUpdated? my_chat_member; - ChatMemberUpdated? chat_member; - ChatJoinRequest? chat_join_request; + PollAnswer? pollAnswer; + ChatMemberUpdated? myChatMember; + ChatMemberUpdated? chatMember; + ChatJoinRequest? chatJoinRequest; Update({ - required this.update_id, + required this.updateId, this.message, - this.edited_message, - this.channel_post, - this.edited_channel_post, - this.inline_query, - this.chosen_inline_result, - this.callback_query, - this.shipping_query, - this.pre_checkout_query, + this.editedMessage, + this.channelPost, + this.editedChannelPost, + this.inlineQuery, + this.chosenInlineResult, + this.callbackQuery, + this.shippingQuery, + this.preCheckoutQuery, this.poll, - this.poll_answer, - this.my_chat_member, - this.chat_member, - this.chat_join_request, + this.pollAnswer, + this.myChatMember, + this.chatMember, + this.chatJoinRequest, }); factory Update.fromJson(Map json) => _$UpdateFromJson(json); Map toJson() => _$UpdateToJson(this); diff --git a/lib/src/telegram/models/user.dart b/lib/src/telegram/models/user.dart index 2d552209..1628a0d3 100644 --- a/lib/src/telegram/models/user.dart +++ b/lib/src/telegram/models/user.dart @@ -21,27 +21,31 @@ part of '../model.dart'; /// This object represents a Telegram user or bot. /// /// https://core.telegram.org/bots/api#user -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class User { int id; - bool is_bot; - String first_name; - String? last_name; + bool isBot; + String firstName; + String? lastName; String? username; - String? language_code; - bool? can_join_groups; - bool? can_read_all_group_messages; - bool? supports_inline_queries; + String? languageCode; + bool? isPremium; + bool? addedToAttachmentMenu; + bool? canJoinGroups; + bool? canReadAllGroupMessages; + bool? supportsInlineQueries; User({ required this.id, - required this.is_bot, - required this.first_name, - this.last_name, + required this.isBot, + required this.firstName, + this.lastName, this.username, - this.language_code, - this.can_join_groups, - this.can_read_all_group_messages, - this.supports_inline_queries, + this.languageCode, + this.isPremium, + this.addedToAttachmentMenu, + this.canJoinGroups, + this.canReadAllGroupMessages, + this.supportsInlineQueries, }); factory User.fromJson(Map json) => _$UserFromJson(json); Map toJson() => _$UserToJson(this); diff --git a/lib/src/telegram/models/user_profile_photos.dart b/lib/src/telegram/models/user_profile_photos.dart index c9055c8a..6e2adf74 100644 --- a/lib/src/telegram/models/user_profile_photos.dart +++ b/lib/src/telegram/models/user_profile_photos.dart @@ -21,12 +21,12 @@ part of '../model.dart'; /// This object represent a user's profile pictures. /// /// https://core.telegram.org/bots/api#userprofilephotos -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class UserProfilePhotos { - int total_count; + int totalCount; List> photos; UserProfilePhotos({ - required this.total_count, + required this.totalCount, required this.photos, }); factory UserProfilePhotos.fromJson(Map json) => diff --git a/lib/src/telegram/models/user_shared.dart b/lib/src/telegram/models/user_shared.dart new file mode 100644 index 00000000..c59f8cb8 --- /dev/null +++ b/lib/src/telegram/models/user_shared.dart @@ -0,0 +1,36 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object contains information about the user whose identifier was +/// shared with the bot using a [KeyboardButtonRequestUser] button. +/// +/// https://core.telegram.org/bots/api#usershared +@JsonSerializable(fieldRename: FieldRename.snake) +class UserShared { + int requestId; + int userId; + UserShared({ + required this.requestId, + required this.userId, + }); + factory UserShared.fromJson(Map json) => + _$UserSharedFromJson(json); + Map toJson() => _$UserSharedToJson(this); +} diff --git a/lib/src/telegram/models/venue.dart b/lib/src/telegram/models/venue.dart index 554272f8..c24306c3 100644 --- a/lib/src/telegram/models/venue.dart +++ b/lib/src/telegram/models/venue.dart @@ -21,23 +21,23 @@ part of '../model.dart'; /// This object represents a venue. /// /// https://core.telegram.org/bots/api#venue -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class Venue { Location location; String title; String address; - String? foursquare_id; - String? foursquare_type; - String? google_place_id; - String? google_place_type; + String? foursquareId; + String? foursquareType; + String? googlePlaceId; + String? googlePlaceType; Venue({ required this.location, required this.title, required this.address, - this.foursquare_id, - this.foursquare_type, - this.google_place_id, - this.google_place_type, + this.foursquareId, + this.foursquareType, + this.googlePlaceId, + this.googlePlaceType, }); factory Venue.fromJson(Map json) => _$VenueFromJson(json); Map toJson() => _$VenueToJson(this); diff --git a/lib/src/telegram/models/video.dart b/lib/src/telegram/models/video.dart index a3ed2480..25a15d47 100644 --- a/lib/src/telegram/models/video.dart +++ b/lib/src/telegram/models/video.dart @@ -21,31 +21,31 @@ part of '../model.dart'; /// This object represents a video file. /// /// https://core.telegram.org/bots/api#video -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class Video { - String file_id; - String file_unique_id; + String fileId; + String fileUniqueId; int width; int height; int duration; - PhotoSize? thumb; - String? file_name; - String? mime_type; - int? file_size; + PhotoSize? thumbnail; + String? fileName; + String? mimeType; + int? fileSize; Video({ - required this.file_id, - required this.file_unique_id, + required this.fileId, + required this.fileUniqueId, required this.width, required this.height, required this.duration, - this.thumb, - this.file_name, - this.mime_type, - this.file_size, + this.thumbnail, + this.fileName, + this.mimeType, + this.fileSize, }); - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) Duration get duration_ => TimeHelper.toDuration(duration); set duration_(Duration duration) => this.duration = TimeHelper.toSeconds(duration); diff --git a/lib/src/telegram/models/video_note.dart b/lib/src/telegram/models/video_note.dart index 7416e16e..c0310866 100644 --- a/lib/src/telegram/models/video_note.dart +++ b/lib/src/telegram/models/video_note.dart @@ -24,25 +24,25 @@ part of '../model.dart'; /// /// [video message]: https://telegram.org/blog/video-messages-and-telescope /// [v.4.0]: https://telegram.org/blog/video-messages-and-telescope -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class VideoNote { - String file_id; - String file_unique_id; + String fileId; + String fileUniqueId; int length; int duration; - PhotoSize? thumb; - int? file_size; + PhotoSize? thumbnail; + int? fileSize; VideoNote({ - required this.file_id, - required this.file_unique_id, + required this.fileId, + required this.fileUniqueId, required this.length, required this.duration, - this.thumb, - this.file_size, + this.thumbnail, + this.fileSize, }); - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) Duration get duration_ => TimeHelper.toDuration(duration); set duration_(Duration duration) => this.duration = TimeHelper.toSeconds(duration); diff --git a/lib/src/telegram/models/voice.dart b/lib/src/telegram/models/voice.dart index cdae6200..a9dbe5e9 100644 --- a/lib/src/telegram/models/voice.dart +++ b/lib/src/telegram/models/voice.dart @@ -18,26 +18,26 @@ part of '../model.dart'; -///This object represents a voice note. +/// This object represents a voice note. /// /// https://core.telegram.org/bots/api#voice -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class Voice { - String file_id; - String file_unique_id; + String fileId; + String fileUniqueId; int duration; - String? mime_type; - int? file_size; + String? mimeType; + int? fileSize; Voice({ - required this.file_id, - required this.file_unique_id, + required this.fileId, + required this.fileUniqueId, required this.duration, - this.mime_type, - this.file_size, + this.mimeType, + this.fileSize, }); - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) Duration get duration_ => TimeHelper.toDuration(duration); set duration_(Duration duration) => this.duration = TimeHelper.toSeconds(duration); diff --git a/lib/src/telegram/models/voice_chat_ended.dart b/lib/src/telegram/models/voice_chat_ended.dart index 6a58f293..dadccb45 100644 --- a/lib/src/telegram/models/voice_chat_ended.dart +++ b/lib/src/telegram/models/voice_chat_ended.dart @@ -21,13 +21,13 @@ part of '../model.dart'; /// This object represents a service message about a voice chat ended in the chat. /// /// https://core.telegram.org/bots/api#voicechatended -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class VoiceChatEnded { int duration; VoiceChatEnded({required this.duration}); - @JsonKey(ignore: true) + @JsonKey(includeFromJson: false, includeToJson: false) Duration get duration_ => TimeHelper.toDuration(duration); set duration_(Duration duration) => this.duration = TimeHelper.toSeconds(duration); diff --git a/lib/src/telegram/models/voice_chat_participants_invited.dart b/lib/src/telegram/models/voice_chat_participants_invited.dart index ee004916..0cfac22b 100644 --- a/lib/src/telegram/models/voice_chat_participants_invited.dart +++ b/lib/src/telegram/models/voice_chat_participants_invited.dart @@ -21,7 +21,7 @@ part of '../model.dart'; /// This object represents a service message about new members invited to a voice chat. /// /// https://core.telegram.org/bots/api#voicechatparticipantsinvited -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class VoiceChatParticipantsInvited { List? users; diff --git a/lib/src/telegram/models/voice_chat_scheduled.dart b/lib/src/telegram/models/voice_chat_scheduled.dart index a5b497bd..bd48048a 100644 --- a/lib/src/telegram/models/voice_chat_scheduled.dart +++ b/lib/src/telegram/models/voice_chat_scheduled.dart @@ -21,16 +21,16 @@ part of '../model.dart'; /// This object represents a service message about a voice chat scheduled in the chat. /// /// https://core.telegram.org/bots/api#voicechatscheduled -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class VoiceChatScheduled { - int start_date; + int startDate; - VoiceChatScheduled(this.start_date); + VoiceChatScheduled(this.startDate); - @JsonKey(ignore: true) - DateTime get start_date_ => TimeHelper.toDateTime(start_date); - set start_date_(DateTime dateTime) => - start_date = TimeHelper.toUnixTime(dateTime); + @JsonKey(includeFromJson: false, includeToJson: false) + DateTime get startDate_ => TimeHelper.toDateTime(startDate); + set startDate_(DateTime dateTime) => + startDate = TimeHelper.toUnixTime(dateTime); factory VoiceChatScheduled.fromJson(Map json) => _$VoiceChatScheduledFromJson(json); diff --git a/lib/src/telegram/models/voice_chat_started.dart b/lib/src/telegram/models/voice_chat_started.dart index b92baa06..bfade685 100644 --- a/lib/src/telegram/models/voice_chat_started.dart +++ b/lib/src/telegram/models/voice_chat_started.dart @@ -23,7 +23,7 @@ part of '../model.dart'; /// Currently holds no information. /// /// https://core.telegram.org/bots/api#voicechatstarted -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class VoiceChatStarted { VoiceChatStarted(); factory VoiceChatStarted.fromJson(Map json) => diff --git a/lib/src/telegram/models/web_app_data.dart b/lib/src/telegram/models/web_app_data.dart new file mode 100644 index 00000000..2a16d5ea --- /dev/null +++ b/lib/src/telegram/models/web_app_data.dart @@ -0,0 +1,37 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2022 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// Describes data sent from a [Web App] to the bot. +/// +/// https://core.telegram.org/bots/api#webappdata +/// +/// [Web App]: https://core.telegram.org/bots/webapps + +@JsonSerializable(fieldRename: FieldRename.snake) +class WebAppData { + String data; + String buttonText; + + WebAppData({required this.data, required this.buttonText}); + + factory WebAppData.fromJson(Map json) => + _$WebAppDataFromJson(json); + Map toJson() => _$WebAppDataToJson(this); +} diff --git a/lib/src/telegram/models/web_app_info.dart b/lib/src/telegram/models/web_app_info.dart new file mode 100644 index 00000000..8e258408 --- /dev/null +++ b/lib/src/telegram/models/web_app_info.dart @@ -0,0 +1,36 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2022 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// Describes a [Web App]. +/// +/// https://core.telegram.org/bots/api#webappinfo +/// +/// [Web App]: https://core.telegram.org/bots/webapps + +@JsonSerializable(fieldRename: FieldRename.snake) +class WebAppInfo { + String url; + + WebAppInfo({required this.url}); + + factory WebAppInfo.fromJson(Map json) => + _$WebAppInfoFromJson(json); + Map toJson() => _$WebAppInfoToJson(this); +} diff --git a/lib/src/telegram/models/webhook_info.dart b/lib/src/telegram/models/webhook_info.dart index 8b6d7e0c..e8d56f97 100644 --- a/lib/src/telegram/models/webhook_info.dart +++ b/lib/src/telegram/models/webhook_info.dart @@ -21,33 +21,35 @@ part of '../model.dart'; /// Contains information about the current status of a webhook. /// /// https://core.telegram.org/bots/api#webhookinfo -@JsonSerializable() +@JsonSerializable(fieldRename: FieldRename.snake) class WebhookInfo { String url; - bool has_custom_certificate; - int pending_update_count; - String? ip_address; - int? last_error_date; - String? last_error_message; - int? max_connections; - List? allowed_updates; + bool hasCustomCertificate; + int pendingUpdateCount; + String? ipAddress; + int? lastErrorDate; + String? lastErrorMessage; + int? lastSynchronizationErrorDate; + int? maxConnections; + List? allowedUpdates; WebhookInfo({ required this.url, - required this.has_custom_certificate, - required this.pending_update_count, - this.ip_address, - this.last_error_date, - this.last_error_message, - this.max_connections, - this.allowed_updates, + required this.hasCustomCertificate, + required this.pendingUpdateCount, + this.ipAddress, + this.lastErrorDate, + this.lastErrorMessage, + this.lastSynchronizationErrorDate, + this.maxConnections, + this.allowedUpdates, }); - @JsonKey(ignore: true) - DateTime? get last_error_date_ => - last_error_date == null ? null : TimeHelper.toDateTime(last_error_date!); - set last_error_date_(DateTime? dateTime) => last_error_date = - dateTime == null ? null : TimeHelper.toUnixTime(dateTime); + @JsonKey(includeFromJson: false, includeToJson: false) + DateTime? get lastErrorDate_ => + lastErrorDate == null ? null : TimeHelper.toDateTime(lastErrorDate!); + set lastErrorDate_(DateTime? dateTime) => + lastErrorDate = dateTime == null ? null : TimeHelper.toUnixTime(dateTime); factory WebhookInfo.fromJson(Map json) => _$WebhookInfoFromJson(json); diff --git a/lib/src/telegram/models/write_access_allowed.dart b/lib/src/telegram/models/write_access_allowed.dart new file mode 100644 index 00000000..41e16384 --- /dev/null +++ b/lib/src/telegram/models/write_access_allowed.dart @@ -0,0 +1,34 @@ +/* + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2023 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +part of '../model.dart'; + +/// This object represents a service message about General forum topic unhidden in the chat. +/// +/// https://core.telegram.org/bots/api#writeaccessallowed +@JsonSerializable(fieldRename: FieldRename.snake) +class WriteAccessAllowed { + String? webAppName; + + WriteAccessAllowed({ + this.webAppName, + }); + factory WriteAccessAllowed.fromJson(Map json) => + _$WriteAccessAllowedFromJson(json); + Map toJson() => _$WriteAccessAllowedToJson(this); +} diff --git a/lib/src/telegram/telegram.dart b/lib/src/telegram/telegram.dart index ee2d5d19..648be5f4 100644 --- a/lib/src/telegram/telegram.dart +++ b/lib/src/telegram/telegram.dart @@ -54,12 +54,12 @@ class Telegram { {int? offset, int? limit, int? timeout, - List? allowed_updates}) async { + List? allowedUpdates}) async { var requestUrl = _apiUri('getUpdates', { 'offset': ['$offset'], 'limit': ['$limit'], 'timeout': ['$timeout'], - 'allowed_updates': [jsonEncode(allowed_updates)] + 'allowed_updates': [jsonEncode(allowedUpdates)] }); return (await HttpClient.httpGet(requestUrl).timeout( @@ -74,35 +74,37 @@ class Telegram { /// specified url, containing a JSON-serialized [Update]. /// In case of an unsuccessful request, we will give up after a reasonable amount of attempts. /// Returns *True* on success. - /// If you'd like to make sure that the Webhook request comes from Telegram, - /// we recommend using a secret path in the URL, e.g. `https://www.example.com/`. - /// Since nobody else knows your bot‘s token, you can be pretty sure it’s us. + /// If you'd like to make sure that the webhook was set by you, you can specify secret data in the parameter `secretToken`. + /// If specified, the request will contain a header “X-Telegram-Bot-Api-Secret-Token” with the secret token as content. /// /// **Notes** /// 1. You will not be able to receive updates using [getUpdates] for as long as an outgoing webhook is set up. /// 2. To use a self-signed certificate, you need to upload your [public key certificate] using certificate parameter. Please upload as InputFile, sending a String will not work. /// 3. Ports currently supported for Webhooks: **443, 80, 88, 8443**. /// - /// **NEW!** If you're having any trouble setting up webhooks, please check out this amazing guide to Webhooks. + /// If you're having any trouble setting up webhooks, please check out this [amazing guide to Webhooks]. /// /// https://core.telegram.org/bots/api#setwebhook /// /// [public key certificate]: https://core.telegram.org/bots/self-signed + /// [amazing guide to Webhooks]: https://core.telegram.org/bots/webhooks Future setWebhook(String url, - {String? ip_address, + {String? ipAddress, io.File? certificate, - int? max_connections, - List? allowed_updates, - bool? drop_pending_updates}) async { + int? maxConnections, + List? allowedUpdates, + bool? dropPendingUpdates, + String? secretToken}) async { var requestUrl = _apiUri('setWebhook'); var body = { 'url': url, - 'ip_address': ip_address, - 'max_connections': max_connections, + 'ip_address': ipAddress, + 'max_connections': maxConnections, 'allowed_updates': - allowed_updates == null ? null : jsonEncode(allowed_updates), - 'drop_pending_updates': drop_pending_updates, + allowedUpdates == null ? null : jsonEncode(allowedUpdates), + 'drop_pending_updates': dropPendingUpdates, + 'secret_token': secretToken, }; if (certificate != null) { // filename cannot be empty to post to Telegram server @@ -121,9 +123,9 @@ class Telegram { /// Returns *True* on success. Requires no parameters. /// /// https://core.telegram.org/bots/api#deletewebhook - Future deleteWebhook({bool? drop_pending_updates}) async { + Future deleteWebhook({bool? dropPendingUpdates}) async { var requestUrl = _apiUri('deleteWebhook'); - var body = {'drop_pending_updates': drop_pending_updates}; + var body = {'drop_pending_updates': dropPendingUpdates}; return await HttpClient.httpPost(requestUrl, body: body); } @@ -171,31 +173,33 @@ class Telegram { /// [**Formatting options**](https://core.telegram.org/bots/api#formatting-options) /// /// https://core.telegram.org/bots/api#sendmessage - Future sendMessage(dynamic chat_id, String text, - {String? parse_mode, + Future sendMessage(dynamic chatId, String text, + {int? messageThreadId, + String? parseMode, List? entities, - bool? disable_web_page_preview, - bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) async { - if (chat_id is! String && chat_id is! int) { + bool? disableWebPagePreview, + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendMessage'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, 'text': text, - 'parse_mode': parse_mode, + 'parse_mode': parseMode, 'entities': entities == null ? null : jsonEncode(entities), - 'disable_web_page_preview': disable_web_page_preview, - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'disable_web_page_preview': disableWebPagePreview, + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body)); } @@ -203,20 +207,22 @@ class Telegram { /// Use this method to forward messages of any kind. On success, the sent [Message] is returned. /// /// https://core.telegram.org/bots/api#forwardmessage - Future forwardMessage( - dynamic chat_id, int from_chat_id, int message_id, - {bool? disable_notification, bool? protect_content}) async { - if (chat_id is! String && chat_id is! int) { + Future forwardMessage(dynamic chatId, int fromChatId, int messageId, + {int? messageThreadId, + bool? disableNotification, + bool? protectContent}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('forwardMessage'); var body = { - 'chat_id': chat_id, - 'from_chat_id': from_chat_id, - 'message_id': message_id, - 'disable_notification': disable_notification, - 'protect_content': protect_content, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, + 'from_chat_id': fromChatId, + 'message_id': messageId, + 'disable_notification': disableNotification, + 'protect_content': protectContent, }; return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body)); } @@ -228,37 +234,35 @@ class Telegram { /// Returns the [MessageId] of the sent message on success. /// /// https://core.telegram.org/bots/api#copyMessage - Future copyMessage( - dynamic chat_id, - int from_chat_id, - int message_id, { - String? caption, - String? parse_mode, - List? caption_entities, - bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup, - }) async { - if (chat_id is! String && chat_id is! int) { + Future copyMessage(dynamic chatId, int fromChatId, int messageId, + {int? messageThreadId, + String? caption, + String? parseMode, + List? captionEntities, + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('copyMessage'); var body = { - 'chat_id': chat_id, - 'from_chat_id': from_chat_id, - 'message_id': message_id, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, + 'from_chat_id': fromChatId, + 'message_id': messageId, 'caption': caption, - 'parse_mode': parse_mode, + 'parse_mode': parseMode, 'caption_entities': - caption_entities == null ? null : jsonEncode(caption_entities), - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup) + captionEntities == null ? null : jsonEncode(captionEntities), + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup) }; return MessageId.fromJson( await HttpClient.httpPost(requestUrl, body: body)); @@ -269,31 +273,35 @@ class Telegram { /// On success, the sent [Message] is returned. /// /// https://core.telegram.org/bots/api#sendphoto - Future sendPhoto(dynamic chat_id, dynamic photo, - {String? caption, - String? parse_mode, - List? caption_entities, - bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) async { - if (chat_id is! String && chat_id is! int) { - return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + Future sendPhoto(dynamic chatId, dynamic photo, + {int? messageThreadId, + String? caption, + String? parseMode, + List? captionEntities, + bool? hasSpoiler, + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendPhoto'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, 'caption': caption, - 'parse_mode': parse_mode, + 'parse_mode': parseMode, 'caption_entities': - caption_entities == null ? null : jsonEncode(caption_entities), - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + captionEntities == null ? null : jsonEncode(captionEntities), + 'has_spoiler': hasSpoiler, + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; var multiPartFiles = []; @@ -304,7 +312,7 @@ class Telegram { body.addAll({'photo': photo}); } else { return Future.error(TelegramException( - 'Attribute \'photo\' can only be either io.File or String (Telegram file_id or image url)')); + 'Attribute \'photo\' can only be either io.File or String (Telegram fileId or image url)')); } return multiPartFiles.isEmpty @@ -324,38 +332,40 @@ class Telegram { /// For sending voice messages, use the [sendVoice] method instead. /// /// https://core.telegram.org/bots/api#sendaudio - Future sendAudio(dynamic chat_id, dynamic audio, - {String? caption, - String? parse_mode, - List? caption_entities, + Future sendAudio(dynamic chatId, dynamic audio, + {int? messageThreadId, + String? caption, + String? parseMode, + List? captionEntities, int? duration, String? performer, String? title, - dynamic thumb, - bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) async { - if (chat_id is! String && chat_id is! int) { + dynamic thumbnail, + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendAudio'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, 'caption': caption, - 'parse_mode': parse_mode, + 'parse_mode': parseMode, 'caption_entities': - caption_entities == null ? null : jsonEncode(caption_entities), + captionEntities == null ? null : jsonEncode(captionEntities), 'duration': duration, 'performer': performer, 'title': title, - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; var multiPartFiles = []; @@ -366,17 +376,17 @@ class Telegram { body.addAll({'audio': audio}); } else { return Future.error(TelegramException( - 'Attribute \'audio\' can only be either io.File or String (Telegram file_id or image url)')); + 'Attribute \'audio\' can only be either io.File or String (Telegram fileId or image url)')); } - if (thumb != null) { - if (thumb is io.File) { - multiPartFiles.add(HttpClient.toMultiPartFile(thumb, 'thumb')); - } else if (thumb is String) { - body.addAll({'thumb': thumb}); + if (thumbnail != null) { + if (thumbnail is io.File) { + multiPartFiles.add(HttpClient.toMultiPartFile(thumbnail, 'thumbnail')); + } else if (thumbnail is String) { + body.addAll({'thumbnail': thumbnail}); } else { return Future.error(TelegramException( - 'Attribute \'thumb\' can only be either io.File or String (Telegram file_id or image url)')); + 'Attribute \'thumbnail\' can only be either io.File or String (Telegram fileId or image url)')); } } @@ -395,34 +405,36 @@ class Telegram { /// this limit may be changed in the future. /// /// https://core.telegram.org/bots/api#senddocument - Future sendDocument(dynamic chat_id, dynamic document, - {dynamic thumb, + Future sendDocument(dynamic chatId, dynamic document, + {int? messageThreadId, + dynamic thumbnail, String? caption, - String? parse_mode, - List? caption_entities, - bool? disable_content_type_detection, - bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) async { - if (chat_id is! String && chat_id is! int) { - return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + String? parseMode, + List? captionEntities, + bool? disableContentTypeDetection, + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendDocument'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, 'caption': caption, - 'parse_mode': parse_mode, + 'parse_mode': parseMode, 'caption_entities': - caption_entities == null ? null : jsonEncode(caption_entities), - 'disable_content_type_detection': disable_content_type_detection, - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + captionEntities == null ? null : jsonEncode(captionEntities), + 'disable_content_type_detection': disableContentTypeDetection, + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; var multiPartFiles = []; @@ -433,17 +445,17 @@ class Telegram { body.addAll({'document': document}); } else { return Future.error(TelegramException( - 'Attribute \'document\' can only be either io.File or String (Telegram file_id or image url)')); + 'Attribute \'document\' can only be either io.File or String (Telegram fileId or image url)')); } - if (thumb != null) { - if (thumb is io.File) { - multiPartFiles.add(HttpClient.toMultiPartFile(thumb, 'thumb')); - } else if (thumb is String) { - body.addAll({'thumb': thumb}); + if (thumbnail != null) { + if (thumbnail is io.File) { + multiPartFiles.add(HttpClient.toMultiPartFile(thumbnail, 'thumbnail')); + } else if (thumbnail is String) { + body.addAll({'thumbnail': thumbnail}); } else { return Future.error(TelegramException( - 'Attribute \'thumb\' can only be either io.File or String (Telegram file_id or image url)')); + 'Attribute \'thumbnail\' can only be either io.File or String (Telegram fileId or image url)')); } } @@ -464,40 +476,44 @@ class Telegram { /// https://core.telegram.org/bots/api#sendvideo /// /// [Document]: https://core.telegram.org/bots/api#document - Future sendVideo(dynamic chat_id, dynamic video, - {int? duration, + Future sendVideo(dynamic chatId, dynamic video, + {int? messageThreadId, + int? duration, int? width, int? height, - dynamic thumb, + dynamic thumbnail, String? caption, - String? parse_mode, - List? caption_entities, - bool? supports_streaming, - bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) async { - if (chat_id is! String && chat_id is! int) { - return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + String? parseMode, + List? captionEntities, + bool? hasSpoiler, + bool? supportsStreaming, + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendVideo'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, 'duration': duration, 'width': width, 'height': height, 'caption': caption, - 'parse_mode': parse_mode, + 'parse_mode': parseMode, 'caption_entities': - caption_entities == null ? null : jsonEncode(caption_entities), - 'supports_streaming': supports_streaming, - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + captionEntities == null ? null : jsonEncode(captionEntities), + 'has_spoiler': hasSpoiler, + 'supports_streaming': supportsStreaming, + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; var multiPartFiles = []; @@ -508,17 +524,17 @@ class Telegram { body.addAll({'video': video}); } else { return Future.error(TelegramException( - 'Attribute \'video\' can only be either io.File or String (Telegram file_id or image url)')); + 'Attribute \'video\' can only be either io.File or String (Telegram fileId or image url)')); } - if (thumb != null) { - if (thumb is io.File) { - multiPartFiles.add(HttpClient.toMultiPartFile(thumb, 'thumb')); - } else if (thumb is String) { - body.addAll({'thumb': thumb}); + if (thumbnail != null) { + if (thumbnail is io.File) { + multiPartFiles.add(HttpClient.toMultiPartFile(thumbnail, 'thumbnail')); + } else if (thumbnail is String) { + body.addAll({'thumbnail': thumbnail}); } else { return Future.error(TelegramException( - 'Attribute \'thumb\' can only be either io.File or String (Telegram file_id or image url)')); + 'Attribute \'thumbnail\' can only be either io.File or String (Telegram fileId or image url)')); } } @@ -536,38 +552,42 @@ class Telegram { /// this limit may be changed in the future. /// /// https://core.telegram.org/bots/api#sendanimation - Future sendAnimation(dynamic chat_id, dynamic animation, - {int? duration, + Future sendAnimation(dynamic chatId, dynamic animation, + {int? messageThreadId, + int? duration, int? width, int? height, - dynamic thumb, + dynamic thumbnail, String? caption, - String? parse_mode, - List? caption_entities, - bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) async { - if (chat_id is! String && chat_id is! int) { - return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + String? parseMode, + List? captionEntities, + bool? hasSpoiler, + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendAnimation'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, 'duration': duration, 'width': width, 'height': height, 'caption': caption, - 'parse_mode': parse_mode, + 'parse_mode': parseMode, 'caption_entities': - caption_entities == null ? null : jsonEncode(caption_entities), - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + captionEntities == null ? null : jsonEncode(captionEntities), + 'has_spoiler': hasSpoiler, + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; var multiPartFiles = []; @@ -578,17 +598,17 @@ class Telegram { body.addAll({'animation': animation}); } else { return Future.error(TelegramException( - 'Attribute \'animation\' can only be either io.File or String (Telegram file_id or image url)')); + 'Attribute \'animation\' can only be either io.File or String (Telegram fileId or image url)')); } - if (thumb != null) { - if (thumb is io.File) { - multiPartFiles.add(HttpClient.toMultiPartFile(thumb, 'thumb')); - } else if (thumb is String) { - body.addAll({'thumb': thumb}); + if (thumbnail != null) { + if (thumbnail is io.File) { + multiPartFiles.add(HttpClient.toMultiPartFile(thumbnail, 'thumbnail')); + } else if (thumbnail is String) { + body.addAll({'thumbnail': thumbnail}); } else { return Future.error(TelegramException( - 'Attribute \'thumb\' can only be either io.File or String (Telegram file_id or image url)')); + 'Attribute \'thumbnail\' can only be either io.File or String (Telegram fileId or image url)')); } } @@ -612,33 +632,35 @@ class Telegram { /// /// [Audio]: https://core.telegram.org/bots/api#audio /// [Document]: https://core.telegram.org/bots/api#document - Future sendVoice(dynamic chat_id, dynamic voice, - {String? caption, - String? parse_mode, - List? caption_entities, + Future sendVoice(dynamic chatId, dynamic voice, + {int? messageThreadId, + String? caption, + String? parseMode, + List? captionEntities, int? duration, - bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) async { - if (chat_id is! String && chat_id is! int) { + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendVoice'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, 'caption': caption, - 'parse_mode': parse_mode, + 'parse_mode': parseMode, 'caption_entities': - caption_entities == null ? null : jsonEncode(caption_entities), + captionEntities == null ? null : jsonEncode(captionEntities), 'duration': duration, - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; var multiPartFiles = []; @@ -649,7 +671,7 @@ class Telegram { body.addAll({'voice': voice}); } else { return Future.error(TelegramException( - 'Attribute \'voice\' can only be either io.File or String (Telegram file_id or image url)')); + 'Attribute \'voice\' can only be either io.File or String (Telegram fileId or image url)')); } return multiPartFiles.isEmpty @@ -668,50 +690,52 @@ class Telegram { /// https://core.telegram.org/bots/api#sendvideonote /// /// [v.4.0]: https://telegram.org/blog/video-messages-and-telescope - Future sendVideoNote(dynamic chat_id, dynamic video_note, - {int? duration, + Future sendVideoNote(dynamic chatId, dynamic videoNote, + {int? messageThreadId, + int? duration, int? length, - dynamic thumb, - bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) async { - if (chat_id is! String && chat_id is! int) { + dynamic thumbnail, + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendVideoNote'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, 'duration': duration, 'length': length, - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; var multiPartFiles = []; - if (video_note is io.File) { - multiPartFiles.add(HttpClient.toMultiPartFile(video_note, 'video_note')); - } else if (video_note is String) { - body.addAll({'video_note': video_note}); + if (videoNote is io.File) { + multiPartFiles.add(HttpClient.toMultiPartFile(videoNote, 'video_note')); + } else if (videoNote is String) { + body.addAll({'video_note': videoNote}); } else { return Future.error(TelegramException( - 'Attribute \'video_note\' can only be either io.File or String (Telegram file_id or image url)')); + 'Attribute \'videoNote\' can only be either io.File or String (Telegram fileId or image url)')); } - if (thumb != null) { - if (thumb is io.File) { - multiPartFiles.add(HttpClient.toMultiPartFile(thumb, 'thumb')); - } else if (thumb is String) { - body.addAll({'thumb': thumb}); + if (thumbnail != null) { + if (thumbnail is io.File) { + multiPartFiles.add(HttpClient.toMultiPartFile(thumbnail, 'thumbnail')); + } else if (thumbnail is String) { + body.addAll({'thumbnail': thumbnail}); } else { return Future.error(TelegramException( - 'Attribute \'thumb\' can only be either io.File or String (Telegram file_id or image url)')); + 'Attribute \'thumbnail\' can only be either io.File or String (Telegram fileId or image url)')); } } @@ -723,7 +747,7 @@ class Telegram { } // TODO: #9 - // ! media can only take file_id or url + // ! media can only take fileId or url // * need to implement POST multipart/form-data uploading files // * or even mixed input /// Use this method to send a group of photos or videos as an album @@ -731,25 +755,40 @@ class Telegram { /// On success, an array of the sent [Message]s is returned. /// /// https://core.telegram.org/bots/api#sendmediagroup - Future> sendMediaGroup(dynamic chat_id, List media, - {bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply}) async { - if (chat_id is! String && chat_id is! int) { + Future> sendMediaGroup(dynamic chatId, List media, + {int? messageThreadId, + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendMediaGroup'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, 'media': jsonEncode(media), - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, }; - return (await HttpClient.httpPost(requestUrl, body: body)) + var multiPartFiles = + media.map((it) => it.mediaFile).whereType().toList(); + if (media is List) { + multiPartFiles.addAll(media + .map((it) => it.thumbnailFile) + .whereType() + .toList()); + } + var response = multiPartFiles.isNotEmpty + ? await HttpClient.httpMultipartPost(requestUrl, multiPartFiles, + body: body) + : await HttpClient.httpPost(requestUrl, body: body); + + return response .map((message) => Message.fromJson(message)) .toList(); } @@ -760,34 +799,36 @@ class Telegram { /// /// https://core.telegram.org/bots/api#sendlocation Future sendLocation( - dynamic chat_id, double latitude, double longitude, - {double? horizontal_accuracy, - int? live_period, + dynamic chatId, double latitude, double longitude, + {int? messageThreadId, + double? horizontalAccuracy, + int? livePeriod, int? heading, - int? proximity_alert_radius, - bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) async { - if (chat_id is! String && chat_id is! int) { + int? proximityAlertRadius, + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendLocation'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, 'latitude': latitude, 'longitude': longitude, - 'horizontal_accuracy': horizontal_accuracy, - 'live_period': live_period, + 'horizontal_accuracy': horizontalAccuracy, + 'live_period': livePeriod, 'heading': heading, - 'proximity_alert_radius': proximity_alert_radius, - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'proximity_alert_radius': proximityAlertRadius, + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body)); } @@ -795,7 +836,7 @@ class Telegram { /// Use this method to edit live location messages sent by the bot or via the bot /// (for [inline bots]). /// - /// A location can be edited until its *live_period* expires or editing is explicitly disabled by a + /// A location can be edited until its *livePeriod* expires or editing is explicitly disabled by a /// call to [stopMessageLiveLocation]. /// On success, if the edited message was sent by the bot, /// the edited [Message] is returned, otherwise *True* is returned. @@ -803,39 +844,42 @@ class Telegram { /// https://core.telegram.org/bots/api#editmessagelivelocation /// /// [inline bots]: https://core.telegram.org/bots/api#inline-mode - Future editMessageLiveLocation(double latitude, double longitude, - {dynamic chat_id, - int? message_id, - String? inline_message_id, - double? horizontal_accuracy, + Future editMessageLiveLocation(double latitude, double longitude, + {dynamic chatId, + int? messageId, + String? inlineMessageId, + double? horizontalAccuracy, int? heading, - int? proximity_alert_radius, - ReplyMarkup? reply_markup}) async { - if (inline_message_id == null && (chat_id == null || message_id == null)) { + int? proximityAlertRadius, + ReplyMarkup? replyMarkup}) async { + if (inlineMessageId == null && (chatId == null || messageId == null)) { return Future.error(TelegramException( - 'Require either \'chat_id\' and \'message_id\', or \'inline_message_id\'')); + 'Require either \'chatId\' and \'messageId\', or \'inlineMessageId\'')); } - if (chat_id != null && (chat_id is! String && chat_id is! int)) { + if (chatId != null && (chatId is! String && chatId is! int)) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('editMessageLiveLocation'); var body = { 'latitude': latitude, 'longitude': longitude, - 'chat_id': chat_id, - 'message_id': message_id, - 'inline_message_id': inline_message_id, - 'horizontal_accuracy': horizontal_accuracy, + 'chat_id': chatId, + 'message_id': messageId, + 'inline_message_id': inlineMessageId, + 'horizontal_accuracy': horizontalAccuracy, 'heading': heading, - 'proximity_alert_radius': proximity_alert_radius, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'proximity_alert_radius': proximityAlertRadius, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; - return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body)); + + final res = await HttpClient.httpPost(requestUrl, body: body); + + return res is bool ? res : Message.fromJson(res); } /// Use this method to stop updating a live location message sent by the bot or via the bot - /// (for [inline bots]) before *live_period* expires. + /// (for [inline bots]) before *livePeriod* expires. /// /// On success, if the message was sent by the bot, the sent [Message] is returned, /// otherwise *True* is returned. @@ -843,27 +887,30 @@ class Telegram { /// https://core.telegram.org/bots/api#stopmessagelivelocation /// /// [inline bots]: https://core.telegram.org/bots/api#inline-mode - Future stopMessageLiveLocation( - {dynamic chat_id, - int? message_id, - String? inline_message_id, - ReplyMarkup? reply_markup}) async { - if (inline_message_id == null && (chat_id == null || message_id == null)) { + Future stopMessageLiveLocation( + {dynamic chatId, + int? messageId, + String? inlineMessageId, + ReplyMarkup? replyMarkup}) async { + if (inlineMessageId == null && (chatId == null || messageId == null)) { return Future.error(TelegramException( - 'Require either \'chat_id\' and \'message_id\', or \'inline_message_id\'')); + 'Require either \'chatId\' and \'messageId\', or \'inlineMessageId\'')); } - if (chat_id != null && (chat_id is! String && chat_id is! int)) { + if (chatId != null && (chatId is! String && chatId is! int)) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('stopMessageLiveLocation'); var body = { - 'chat_id': chat_id, - 'message_id': message_id, - 'inline_message_id': inline_message_id, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'chat_id': chatId, + 'message_id': messageId, + 'inline_message_id': inlineMessageId, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; - return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body)); + + final res = await HttpClient.httpPost(requestUrl, body: body); + + return res is bool ? res : Message.fromJson(res); } /// Use this method to send information about a venue @@ -871,37 +918,39 @@ class Telegram { /// On success, the sent [Message] is returned. /// /// https://core.telegram.org/bots/api#sendvenue - Future sendVenue(dynamic chat_id, double latitude, double longitude, + Future sendVenue(dynamic chatId, double latitude, double longitude, String title, String address, - {String? foursquare_id, - String? foursquare_type, - String? google_place_id, - String? google_place_type, - bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) async { - if (chat_id is! String && chat_id is! int) { - return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + {int? messageThreadId, + String? foursquareId, + String? foursquareType, + String? googlePlaceId, + String? googlePlaceType, + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendVenue'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, 'latitude': latitude, 'longitude': longitude, 'title': title, 'address': address, - 'foursquare_id': foursquare_id, - 'foursquare_type': foursquare_type, - 'google_place_id': google_place_id, - 'google_place_type': google_place_type, - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'foursquare_id': foursquareId, + 'foursquare_type': foursquareType, + 'google_place_id': googlePlaceId, + 'google_place_type': googlePlaceType, + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body)); } @@ -912,30 +961,32 @@ class Telegram { /// /// https://core.telegram.org/bots/api#sendcontact Future sendContact( - dynamic chat_id, String phone_number, String first_name, - {String? last_name, + dynamic chatId, String phoneNumber, String firstName, + {int? messageThreadId, + String? lastName, String? vcard, - bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) async { - if (chat_id is! String && chat_id is! int) { + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendContact'); var body = { - 'chat_id': chat_id, - 'phone_number': phone_number, - 'first_name': first_name, - 'last_name': last_name, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, + 'phone_number': phoneNumber, + 'first_name': firstName, + 'last_name': lastName, 'vcard': vcard, - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body)); } @@ -948,48 +999,49 @@ class Telegram { /// /// https://core.telegram.org/bots/api#sendpoll Future sendPoll( - dynamic chat_id, String question, List options, - {bool? is_anonymous, + dynamic chatId, String question, List options, + {int? messageThreadId, + bool? isAnonymous, String? type, - bool? allows_multiple_answers, - int? correct_option_id, + bool? allowsMultipleAnswers, + int? correctOptionId, String? explanation, - String? explanation_parse_mode, - List? explanation_entities, - int? open_period, - int? close_date, - bool? is_closed, - bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) async { - if (chat_id is! String && chat_id is! int) { - return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + String? explanationParseMode, + List? explanationEntities, + int? openPeriod, + int? closeDate, + bool? isClosed, + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendPoll'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, 'question': question, 'options': jsonEncode(options), - 'is_anonymous': is_anonymous, + 'is_anonymous': isAnonymous, 'type': type, - 'allows_multiple_answers': allows_multiple_answers, - 'correct_option_id': correct_option_id, + 'allows_multiple_answers': allowsMultipleAnswers, + 'correct_option_id': correctOptionId, 'explanation': explanation, - 'explanation_parse_mode': explanation_parse_mode, - 'explanation_entities': explanation_entities == null - ? null - : jsonEncode(explanation_entities), - 'open_period': open_period, - 'close_date': close_date, - 'is_closed': is_closed, - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'explanation_parse_mode': explanationParseMode, + 'explanation_entities': + explanationEntities == null ? null : jsonEncode(explanationEntities), + 'open_period': openPeriod, + 'close_date': closeDate, + 'is_closed': isClosed, + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body)); } @@ -997,26 +1049,28 @@ class Telegram { /// Use this method to send an animated emoji that will display a random value /// /// On success, the sent [Message] is returned. - Future sendDice(dynamic chat_id, - {String emoji = Dice.DICE, - bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) async { - if (chat_id is! String && chat_id is! int) { - return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + Future sendDice(dynamic chatId, + {int? messageThreadId, + String emoji = Dice.emojiDice, + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendDice'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, 'emoji': emoji, - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body)); } @@ -1029,7 +1083,7 @@ class Telegram { /// /// Example: The [ImageBot] needs some time to process a request and upload the image. /// Instead of sending a text message along the lines of “Retrieving image, please wait…”, - /// the bot may use [sendChatAction] with action = upload_photo. + /// the bot may use [sendChatAction] with action = uploadPhoto. /// The user will see a “sending photo” status for the bot. /// /// We only recommend using this method when a response from the bot will take a **noticeable** @@ -1038,13 +1092,18 @@ class Telegram { /// https://core.telegram.org/bots/api#sendchataction /// /// [ImageBot]: https://t.me/imagebot - Future sendChatAction(dynamic chat_id, String action) async { - if (chat_id is! String && chat_id is! int) { + Future sendChatAction(dynamic chatId, String action, + {int? messageThreadId}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendChatAction'); - var body = {'chat_id': chat_id, 'action': action}; + var body = { + 'chat_id': chatId, + 'message_thread_id': messageThreadId, + 'action': action + }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1053,11 +1112,11 @@ class Telegram { /// Returns a [UserProfilePhotos] object. /// /// https://core.telegram.org/bots/api#getuserprofilephotos - Future getUserProfilePhotos(int user_id, + Future getUserProfilePhotos(int userId, {int? offset, int? limit}) async { var requestUrl = _apiUri('getUserProfilePhotos'); var body = { - 'user_id': user_id, + 'user_id': userId, 'offset': offset, 'limit': limit, }; @@ -1078,9 +1137,9 @@ class Telegram { /// You should save the file's MIME type and name (if available) when the File object is received. /// /// https://core.telegram.org/bots/api#getfile - Future getFile(String file_id) async { + Future getFile(String fileId) async { var requestUrl = _apiUri('getFile'); - var body = {'file_id': file_id}; + var body = {'file_id': fileId}; return File.fromJson(await HttpClient.httpPost(requestUrl, body: body)); } @@ -1095,18 +1154,18 @@ class Telegram { /// https://core.telegram.org/bots/api#banchatmember /// /// [unbanned]: https://core.telegram.org/bots/api#unbanchatmember - Future banChatMember(dynamic chat_id, int user_id, - {int? until_date, bool? revoke_messages}) async { - if (chat_id is! String && chat_id is! int) { + Future banChatMember(dynamic chatId, int userId, + {int? untilDate, bool? revokeMessages}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('banChatMember'); var body = { - 'chat_id': chat_id, - 'user_id': user_id, - 'until_date': until_date, - 'revoke_messages': revoke_messages, + 'chat_id': chatId, + 'user_id': userId, + 'until_date': untilDate, + 'revoke_messages': revokeMessages, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1118,17 +1177,17 @@ class Telegram { /// Returns *True* on success. /// /// https://core.telegram.org/bots/api#unbanchatmember - Future unbanChatMember(dynamic chat_id, int user_id, - {bool? only_if_banned}) async { - if (chat_id is! String && chat_id is! int) { + Future unbanChatMember(dynamic chatId, int userId, + {bool? onlyIfBanned}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('unbanChatMember'); var body = { - 'chat_id': chat_id, - 'user_id': user_id, - 'only_if_banned': only_if_banned, + 'chat_id': chatId, + 'user_id': userId, + 'only_if_banned': onlyIfBanned, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1144,18 +1203,20 @@ class Telegram { /// /// This method now takes the new user permissions in a single argument of the type *ChatPermissions*. /// The old way of passing parameters will keep working for a while for backward compatibility. - Future restrictChatMember(dynamic chat_id, int user_id, - {ChatPermissions? permissions, int? until_date}) async { - if (chat_id is! String && chat_id is! int) { + Future restrictChatMember( + dynamic chatId, int userId, ChatPermissions permissions, + {bool? useIndependentChatPermissions, int? untilDate}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('restrictChatMember'); var body = { - 'chat_id': chat_id, - 'user_id': user_id, - 'permissions': permissions == null ? null : jsonEncode(permissions), - 'until_date': until_date, + 'chat_id': chatId, + 'user_id': userId, + 'permissions': jsonEncode(permissions), + 'use_independent_chat_permissions': useIndependentChatPermissions, + 'until_date': untilDate, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1167,37 +1228,39 @@ class Telegram { /// Pass *False* for all boolean parameters to demote a user. Returns *True* on success. /// /// https://core.telegram.org/bots/api#promotechatmember - Future promoteChatMember(dynamic chat_id, int user_id, - {bool? is_anonymous, - bool? can_manage_chat, - bool? can_post_messages, - bool? can_edit_messages, - bool? can_delete_messages, - bool? can_manage_voice_chats, - bool? can_restrict_members, - bool? can_promote_members, - bool? can_change_info, - bool? can_invite_users, - bool? can_pin_messages}) async { - if (chat_id is! String && chat_id is! int) { - return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + Future promoteChatMember(dynamic chatId, int userId, + {bool? isAnonymous, + bool? canManageChat, + bool? canPostMessages, + bool? canEditMessages, + bool? canDeleteMessages, + bool? canManageVideoChats, + bool? canRestrictMembers, + bool? canPromoteMembers, + bool? canChangeInfo, + bool? canInviteUsers, + bool? canPinMessages, + bool? canManageTopics}) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('promoteChatMember'); var body = { - 'chat_id': chat_id, - 'user_id': user_id, - 'is_anonymous': is_anonymous, - 'can_manage_chat': can_manage_chat, - 'can_post_messages': can_post_messages, - 'can_edit_messages': can_edit_messages, - 'can_delete_messages': can_delete_messages, - 'can_manage_voice_chats': can_manage_voice_chats, - 'can_restrict_members': can_restrict_members, - 'can_promote_members': can_promote_members, - 'can_change_info': can_change_info, - 'can_invite_users': can_invite_users, - 'can_pin_messages': can_pin_messages, + 'chat_id': chatId, + 'user_id': userId, + 'is_anonymous': isAnonymous, + 'can_manage_chat': canManageChat, + 'can_post_messages': canPostMessages, + 'can_edit_messages': canEditMessages, + 'can_delete_messages': canDeleteMessages, + 'can_manage_video_chats': canManageVideoChats, + 'can_restrict_members': canRestrictMembers, + 'can_promote_members': canPromoteMembers, + 'can_change_info': canChangeInfo, + 'can_invite_users': canInviteUsers, + 'can_pin_messages': canPinMessages, + 'can_manage_topics': canManageTopics, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1208,16 +1271,16 @@ class Telegram { /// /// https://core.telegram.org/bots/api#setchatadministratorcustomtitle Future setChatAdministratorCustomTitle( - dynamic chat_id, int user_id, String custom_title) async { - if (chat_id is! String && chat_id is! int) { + dynamic chatId, int userId, String customTitle) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('setChatAdministratorCustomTitle'); var body = { - 'chat_id': chat_id, - 'user_id': user_id, - 'custom_title': custom_title, + 'chat_id': chatId, + 'user_id': userId, + 'custom_title': customTitle, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1229,15 +1292,15 @@ class Telegram { /// channel for this to work and must have the appropriate administrator rights. /// /// Returns *True* on success. - Future banChatSenderChat(dynamic chat_id, int sender_chat_id) async { - if (chat_id is! String && chat_id is! int) { + Future banChatSenderChat(dynamic chatId, int senderChatId) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('banChatSenderChat'); var body = { - 'chat_id': chat_id, - 'sender_chat_id': sender_chat_id, + 'chat_id': chatId, + 'sender_chat_id': senderChatId, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1247,15 +1310,15 @@ class Telegram { /// The bot must be an administrator for this to work and must have the appropriate administrator rights. /// /// Returns *True* on success. - Future unbanChatSenderChat(dynamic chat_id, int sender_chat_id) async { - if (chat_id is! String && chat_id is! int) { + Future unbanChatSenderChat(dynamic chatId, int senderChatId) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('unbanChatSenderChat'); var body = { - 'chat_id': chat_id, - 'sender_chat_id': sender_chat_id, + 'chat_id': chatId, + 'sender_chat_id': senderChatId, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1263,21 +1326,22 @@ class Telegram { /// Use this method to set default chat permissions for all members /// /// The bot must be an administrator in the group or a supergroup for this to work - /// and must have the can_restrict_members admin rights. + /// and must have the canRestrictMembers admin rights. /// /// Returns *True* on success. /// /// https://core.telegram.org/bots/api#setchatpermissions - Future setChatPermissions( - dynamic chat_id, ChatPermissions permissions) async { - if (chat_id is! String && chat_id is! int) { + Future setChatPermissions(dynamic chatId, ChatPermissions permissions, + {bool? useIndependentChatPermissions}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('setChatPermissions'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, 'permissions': jsonEncode(permissions), + 'use_independent_chat_permissions': useIndependentChatPermissions, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1291,13 +1355,13 @@ class Telegram { /// Returns the invite link as [String] on success. /// /// https://core.telegram.org/bots/api#exportchatinvitelink - Future exportChatInviteLink(dynamic chat_id) async { - if (chat_id is! String && chat_id is! int) { + Future exportChatInviteLink(dynamic chatId) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('exportChatInviteLink'); - var body = {'chat_id': chat_id}; + var body = {'chat_id': chatId}; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1309,22 +1373,22 @@ class Telegram { /// Returns the new invite link as [ChatInviteLink] object. /// /// https://core.telegram.org/bots/api#createchatinvitelink - Future createChatInviteLink(dynamic chat_id, + Future createChatInviteLink(dynamic chatId, {String? name, - int? expire_date, - int? member_limit, - bool? creates_join_request}) async { - if (chat_id is! String && chat_id is! int) { + int? expireDate, + int? memberLimit, + bool? createsJoinRequest}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('createChatInviteLink'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, 'name': name, - 'expire_date': expire_date, - 'member_limit': member_limit, - 'creates_join_request': creates_join_request, + 'expire_date': expireDate, + 'member_limit': memberLimit, + 'creates_join_request': createsJoinRequest, }; return ChatInviteLink.fromJson( await HttpClient.httpPost(requestUrl, body: body)); @@ -1337,23 +1401,23 @@ class Telegram { /// Returns the edited invite link as a [ChatInviteLink] object. /// /// https://core.telegram.org/bots/api#editchatinvitelink - Future editChatInviteLink(dynamic chat_id, String invite_link, + Future editChatInviteLink(dynamic chatId, String inviteLink, {String? name, - int? expire_date, - int? member_limit, - bool? creates_join_request}) async { - if (chat_id is! String && chat_id is! int) { + int? expireDate, + int? memberLimit, + bool? createsJoinRequest}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('editChatInviteLink'); var body = { - 'chat_id': chat_id, - 'invite_link': invite_link, + 'chat_id': chatId, + 'invite_link': inviteLink, 'name': name, - 'expire_date': expire_date, - 'member_limit': member_limit, - 'creates_join_request': creates_join_request, + 'expire_date': expireDate, + 'member_limit': memberLimit, + 'creates_join_request': createsJoinRequest, }; return ChatInviteLink.fromJson( await HttpClient.httpPost(requestUrl, body: body)); @@ -1368,15 +1432,15 @@ class Telegram { /// /// https://core.telegram.org/bots/api#revokechatinvitelink Future revokeChatInviteLink( - dynamic chat_id, String invite_link) async { - if (chat_id is! String && chat_id is! int) { + dynamic chatId, String inviteLink) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('revokeChatInviteLink'); var body = { - 'chat_id': chat_id, - 'invite_link': invite_link, + 'chat_id': chatId, + 'invite_link': inviteLink, }; return ChatInviteLink.fromJson( await HttpClient.httpPost(requestUrl, body: body)); @@ -1384,38 +1448,38 @@ class Telegram { /// Use this method to approve a chat join request /// - /// The bot must be an administrator in the chat for this to work and must have the *can_invite_users* administrator right. + /// The bot must be an administrator in the chat for this to work and must have the *canInviteUsers* administrator right. /// /// Returns *True* on success. /// /// https://core.telegram.org/bots/api#approvechatjoinrequest - Future approveChatJoinRequest(dynamic chat_id, int user_id) async { - if (chat_id is! String && chat_id is! int) { + Future approveChatJoinRequest(dynamic chatId, int userId) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('approveChatJoinRequest'); var body = { - 'chat_id': chat_id, - 'user_id': user_id, + 'chat_id': chatId, + 'user_id': userId, }; return await HttpClient.httpPost(requestUrl, body: body); } /// Use this method to decline a chat join request /// - /// The bot must be an administrator in the chat for this to work and must have the *can_invite_users* administrator right. + /// The bot must be an administrator in the chat for this to work and must have the *canInviteUsers* administrator right. /// /// Returns *True* on success. - Future declineChatJoinRequest(dynamic chat_id, int user_id) async { - if (chat_id is! String && chat_id is! int) { + Future declineChatJoinRequest(dynamic chatId, int userId) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('declineChatJoinRequest'); var body = { - 'chat_id': chat_id, - 'user_id': user_id, + 'chat_id': chatId, + 'user_id': userId, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1432,13 +1496,13 @@ class Telegram { /// this method will only work if the ‘All Members Are Admins’ setting is off in the target group. /// /// https://core.telegram.org/bots/api#setchatphoto - Future setChatPhoto(dynamic chat_id, io.File photo) async { - if (chat_id is! String && chat_id is! int) { + Future setChatPhoto(dynamic chatId, io.File photo) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('setChatPhoto'); - var body = {'chat_id': chat_id}; + var body = {'chat_id': chatId}; // filename cannot be empty to post to Telegram server var files = List.filled( 1, @@ -1459,13 +1523,13 @@ class Telegram { /// this method will only work if the ‘All Members Are Admins’ setting is off in the target group. /// /// https://core.telegram.org/bots/api#deletechatphoto - Future deleteChatPhoto(dynamic chat_id) async { - if (chat_id is! String && chat_id is! int) { + Future deleteChatPhoto(dynamic chatId) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('deleteChatPhoto'); - var body = {'chat_id': chat_id}; + var body = {'chat_id': chatId}; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1481,14 +1545,14 @@ class Telegram { /// this method will only work if the ‘All Members Are Admins’ setting is off in the target group. /// /// https://core.telegram.org/bots/api#setchattitle - Future setChatTitle(dynamic chat_id, String title) async { - if (chat_id is! String && chat_id is! int) { + Future setChatTitle(dynamic chatId, String title) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('setChatTitle'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, 'title': title, }; return await HttpClient.httpPost(requestUrl, body: body); @@ -1502,15 +1566,14 @@ class Telegram { /// Returns *True* on success. /// /// https://core.telegram.org/bots/api#setchatdescription - Future setChatDescription(dynamic chat_id, - {String? description}) async { - if (chat_id is! String && chat_id is! int) { + Future setChatDescription(dynamic chatId, {String? description}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('setChatDescription'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, 'description': description, }; return await HttpClient.httpPost(requestUrl, body: body); @@ -1519,23 +1582,23 @@ class Telegram { /// Use this method to pin a message in a supergroup or a channel /// /// The bot must be an administrator in the chat for this to work and must have the - /// ‘can_pin_messages’ admin right in the supergroup or ‘can_edit_messages’ admin right + /// ‘canPinMessages’ admin right in the supergroup or ‘canEditMessages’ admin right /// in the channel. /// /// Returns *True* on success. /// /// https://core.telegram.org/bots/api#pinchatmessage - Future pinChatMessage(dynamic chat_id, int message_id, - {bool? disable_notification}) async { - if (chat_id is! String && chat_id is! int) { + Future pinChatMessage(dynamic chatId, int messageId, + {bool? disableNotification}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('pinChatMessage'); var body = { - 'chat_id': chat_id, - 'message_id': message_id, - 'disable_notification': disable_notification, + 'chat_id': chatId, + 'message_id': messageId, + 'disable_notification': disableNotification, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1543,40 +1606,40 @@ class Telegram { /// Use this method to remove a message from the list of pinned messages in a chat /// /// If the chat is not a private chat, the bot must be an administrator in the chat for - /// this to work and must have the 'can_pin_messages' admin right in a supergroup or - /// 'can_edit_messages' admin right in a channel. + /// this to work and must have the 'canPinMessages' admin right in a supergroup or + /// 'canEditMessages' admin right in a channel. /// /// Returns *True* on success. /// - /// If `message_id` not specified, the most recent pinned message (by sending date) will be unpinned. + /// If `messageId` not specified, the most recent pinned message (by sending date) will be unpinned. /// /// https://core.telegram.org/bots/api#unpinchatmessage - Future unpinChatMessage(dynamic chat_id, {int? message_id}) async { - if (chat_id is! String && chat_id is! int) { + Future unpinChatMessage(dynamic chatId, {int? messageId}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('unpinChatMessage'); - var body = {'chat_id': chat_id, 'message_id': message_id}; + var body = {'chat_id': chatId, 'message_id': messageId}; return await HttpClient.httpPost(requestUrl, body: body); } /// Use this method to clear the list of pinned messages in a chat /// /// If the chat is not a private chat, the bot must be an administrator in the chat for - /// this to work and must have the 'can_pin_messages' admin right in a supergroup or - /// 'can_edit_messages' admin right in a channel. + /// this to work and must have the 'canPinMessages' admin right in a supergroup or + /// 'canEditMessages' admin right in a channel. /// /// Returns *True* on success. /// /// https://core.telegram.org/bots/api#unpinallchatmessages - Future unpinAllChatMessages(dynamic chat_id) async { - if (chat_id is! String && chat_id is! int) { + Future unpinAllChatMessages(dynamic chatId) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('unpinAllChatMessages'); - var body = {'chat_id': chat_id}; + var body = {'chat_id': chatId}; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1585,13 +1648,13 @@ class Telegram { /// Returns *True* on success. /// /// https://core.telegram.org/bots/api#leavechat - Future leaveChat(dynamic chat_id) async { - if (chat_id is! String && chat_id is! int) { + Future leaveChat(dynamic chatId) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('leaveChat'); - var body = {'chat_id': chat_id}; + var body = {'chat_id': chatId}; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1602,13 +1665,13 @@ class Telegram { /// Returns a [Chat] object on success. /// /// https://core.telegram.org/bots/api#getchat - Future getChat(dynamic chat_id) async { - if (chat_id is! String && chat_id is! int) { + Future getChat(dynamic chatId) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('getChat'); - var body = {'chat_id': chat_id}; + var body = {'chat_id': chatId}; return Chat.fromJson(await HttpClient.httpPost(requestUrl, body: body)); } @@ -1620,13 +1683,13 @@ class Telegram { /// only the creator will be returned. /// /// https://core.telegram.org/bots/api#getchatadministrators - Future> getChatAdministrators(dynamic chat_id) async { - if (chat_id is! String && chat_id is! int) { + Future> getChatAdministrators(dynamic chatId) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('getChatAdministrators'); - var body = {'chat_id': chat_id}; + var body = {'chat_id': chatId}; return (await HttpClient.httpPost(requestUrl, body: body)) .map((member) => ChatMember.fromJson(member)) .toList(); @@ -1637,13 +1700,13 @@ class Telegram { /// Returns [int] on success. /// /// https://core.telegram.org/bots/api#getchatmembercount - Future getChatMemberCount(dynamic chat_id) async { - if (chat_id is! String && chat_id is! int) { + Future getChatMemberCount(dynamic chatId) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('getChatMemberCount'); - var body = {'chat_id': chat_id}; + var body = {'chat_id': chatId}; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1652,15 +1715,15 @@ class Telegram { /// Returns a [ChatMember] object on success. /// /// https://core.telegram.org/bots/api#getchatmember - Future getChatMember(dynamic chat_id, int user_id) async { - if (chat_id is! String && chat_id is! int) { + Future getChatMember(dynamic chatId, int userId) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('getChatMember'); var body = { - 'chat_id': chat_id, - 'user_id': user_id, + 'chat_id': chatId, + 'user_id': userId, }; return ChatMember.fromJson( await HttpClient.httpPost(requestUrl, body: body)); @@ -1670,22 +1733,21 @@ class Telegram { /// /// The bot must be an administrator in the chat for this to work and must have the appropriate /// admin rights. - /// Use the field *can_set_sticker_set* optionally returned in [getChat] requests to check if the + /// Use the field *canSetStickerSet* optionally returned in [getChat] requests to check if the /// bot can use this method. /// /// Returns *True* on success. /// /// https://core.telegram.org/bots/api#setchatstickerset - Future setChatStickerSet( - dynamic chat_id, String sticker_set_name) async { - if (chat_id is! String && chat_id is! int) { + Future setChatStickerSet(dynamic chatId, String stickerSetName) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('setChatStickerSet'); var body = { - 'chat_id': chat_id, - 'sticker_set_name': sticker_set_name, + 'chat_id': chatId, + 'sticker_set_name': stickerSetName, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1694,19 +1756,277 @@ class Telegram { /// /// The bot must be an administrator in the chat for this to work and must have the appropriate /// admin rights. - /// Use the field *can_set_sticker_set* optionally returned in [getChat] requests to check if the + /// Use the field *canSetStickerSet* optionally returned in [getChat] requests to check if the /// bot can use this method. /// /// Returns *True* on success. /// /// https://core.telegram.org/bots/api#deletechatstickerset - Future deleteChatStickerSet(dynamic chat_id) async { - if (chat_id is! String && chat_id is! int) { + Future deleteChatStickerSet(dynamic chatId) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('deleteChatStickerSet'); - var body = {'chat_id': chat_id}; + var body = {'chat_id': chatId}; + return await HttpClient.httpPost(requestUrl, body: body); + } + + ///Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. + /// + ///Requires no parameters. + /// + ///Returns an Array of [Sticker] objects. + /// + ///https://core.telegram.org/bots/api#getforumtopiciconstickers + Future> getForumTopicIconStickers() async { + var requestUrl = _apiUri('getForumTopicIconStickers'); + return (await HttpClient.httpPost(requestUrl)) + .map((sticker) => Sticker.fromJson(sticker)) + .toList(); + } + + /// Use this method to create a topic in a forum supergroup chat. + /// + /// The bot must be an administrator in the chat for this to work and must have the canManageTopics administrator rights. + /// + /// Returns information about the created topic as a [ForumTopic] object. + /// + /// https://core.telegram.org/bots/api#createforumtopic + Future createForumTopic(dynamic chatId, String name, + {int? iconColor, String? iconCustomEmojiId}) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); + } + var requestUrl = _apiUri('createForumTopic'); + var body = { + 'chat_id': chatId, + 'name': name, + 'icon_color': iconColor, + 'icon_custom_emoji_id': iconCustomEmojiId, + }; + return ForumTopic.fromJson( + await HttpClient.httpPost(requestUrl, body: body)); + } + + ///Use this method to edit name and icon of a topic in a forum supergroup chat. + /// + ///The bot must be an administrator in the chat for this to work and must have `canManageTopics` administrator rights, unless it is the creator of the topic. + /// + ///Returns *True* on success. + /// + ///https://core.telegram.org/bots/api#editforumtopic + Future editForumTopic(dynamic chatId, String messageThreadId, + String name, String iconCustomEmojiId) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); + } + var requestUrl = _apiUri('editForumTopic'); + var body = { + 'chat_id': chatId, + 'message_thread_id': messageThreadId, + 'name': name, + 'icon_custom_emoji_id': iconCustomEmojiId, + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to close an open topic in a forum supergroup chat. + /// + /// The bot must be an administrator in the chat for this to work and must have the `canManageTopics` administrator rights, unless it is the creator of the topic. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#closeforumtopic + Future closeForumTopic(dynamic chatId, String messageThreadId) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); + } + var requestUrl = _apiUri('closeForumTopic'); + var body = { + 'chat_id': chatId, + 'message_thread_id': messageThreadId, + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to reopen a closed topic in a forum supergroup chat. + /// + /// The bot must be an administrator in the chat for this to work and must have the `canManageTopics` administrator rights, unless it is the creator of the topic. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#reopenforumtopic + Future reopenForumTopic(dynamic chatId, String messageThreadId) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); + } + var requestUrl = _apiUri('reopenForumTopic'); + var body = { + 'chat_id': chatId, + 'message_threadId': messageThreadId, + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to delete a forum topic along with all its messages in a forum supergroup chat. + /// + /// The bot must be an administrator in the chat for this to work and must have the `canDeleteMessages` administrator rights. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#deleteforumtopic + Future deleteForumTopic(dynamic chatId, String messageThreadId) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); + } + var requestUrl = _apiUri('deleteForumTopic'); + var body = { + 'chat_id': chatId, + 'message_thread_id': messageThreadId, + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to clear the list of pinned messages in a forum topic. + /// + /// The bot must be an administrator in the chat for this to work and must have the `canPinMessages` administrator right in the supergroup. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#unpinallforumtopicmessages + Future unpinAllForumTopicMessages( + dynamic chatId, String messageThreadId) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); + } + var requestUrl = _apiUri('unpinAllForumTopicMessages'); + var body = { + 'chat_id': chatId, + 'message_thread_id': messageThreadId, + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to edit the name of the 'General' topic in a forum supergroup chat. + /// + /// The bot must be an administrator in the chat for this to work and must have `canManageTopics` administrator rights. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#editgeneralforumtopic + Future editGeneralForumTopic(dynamic chatId, String name) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); + } + var requestUrl = _apiUri('editGeneralForumTopic'); + var body = { + 'chat_id': chatId, + 'name': name, + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to close an open 'General' topic in a forum supergroup chat. + /// + /// The bot must be an administrator in the chat for this to work and must have the `canManageTopics` administrator rights. + /// + /// Returns *True* on success. + /// + ///https://core.telegram.org/bots/api#closegeneralforumtopic + Future closeGeneralForumTopic(dynamic chatId) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); + } + var requestUrl = _apiUri('closeGeneralForumTopic'); + var body = { + 'chat_id': chatId, + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to reopen a closed 'General' topic in a forum supergroup chat. + /// + /// The bot must be an administrator in the chat for this to work and must have the `canManageTopics` administrator rights. + /// The topic will be automatically unhidden if it was hidden. + /// + /// Returns True on success. + /// + /// https://core.telegram.org/bots/api#reopengeneralforumtopic + Future reopenGeneralForumTopic(dynamic chatId) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); + } + var requestUrl = _apiUri('reopenGeneralForumTopic'); + var body = { + 'chat_id': chatId, + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to hide the 'General' topic in a forum supergroup chat. + /// + /// The bot must be an administrator in the chat for this to work and must have the `canManageTopics` administrator rights. + /// The topic will be automatically closed if it was open. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#hidegeneralforumtopic + Future hideGeneralForumTopic(dynamic chatId) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); + } + var requestUrl = _apiUri('hideGeneralForumTopic'); + var body = { + 'chat_id': chatId, + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to unhide the 'General' topic in a forum supergroup chat. + /// + /// The bot must be an administrator in the chat for this to work and must have the `canManageTopics` administrator rights + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#unhidegeneralforumtopic + Future unhideGeneralForumTopic(dynamic chatId) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); + } + var requestUrl = _apiUri('unhideGeneralForumTopic'); + var body = { + 'chat_id': chatId, + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to clear the list of pinned messages in a General forum topic. + /// The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. + /// + /// Returns True on success. + /// + /// https://core.telegram.org/bots/api#unpinallgeneralforumtopicmessages + Future unpinAllGeneralForumTopicMessages(dynamic chatId) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); + } + var requestUrl = _apiUri('unpinAllGeneralForumTopicMessages'); + var body = { + 'chat_id': chatId, + }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1726,15 +2046,15 @@ class Telegram { /// /// [inline keyboards]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating /// [@Botfather]: https://t.me/botfather - Future answerCallbackQuery(String callback_query_id, - {String? text, bool? show_alert, String? url, int? cache_time}) async { + Future answerCallbackQuery(String callbackQueryId, + {String? text, bool? showAlert, String? url, int? cacheTime}) async { var requestUrl = _apiUri('answerCallbackQuery'); var body = { - 'callback_query_id': callback_query_id, + 'callback_query_id': callbackQueryId, 'text': text, - 'show_alert': show_alert, + 'show_alert': showAlert, 'url': url, - 'cache_time': cache_time, + 'cache_time': cacheTime, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1747,12 +2067,12 @@ class Telegram { /// /// https://core.telegram.org/bots/api#setmycommands Future setMyCommands(List commands, - {BotCommandScope? scope, String? language_code}) async { + {BotCommandScope? scope, String? languageCode}) async { var requestUrl = _apiUri('setMyCommands'); var body = { 'commands': jsonEncode(commands), 'scope': scope == null ? null : jsonEncode(scope), - 'language_code': language_code, + 'language_code': languageCode, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1767,11 +2087,11 @@ class Telegram { /// /// [higher level commands]: https://core.telegram.org/bots/api#determining-list-of-commands Future deleteMyCommands( - {BotCommandScope? scope, String? language_code}) async { + {BotCommandScope? scope, String? languageCode}) async { var requestUrl = _apiUri('deleteMyCommands'); var body = { 'scope': scope == null ? null : jsonEncode(scope), - 'language_code': language_code, + 'language_code': languageCode, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1783,17 +2103,160 @@ class Telegram { /// /// https://core.telegram.org/bots/api#getmycommands Future> getMyCommands( - {BotCommandScope? scope, String? language_code}) async { + {BotCommandScope? scope, String? languageCode}) async { var requestUrl = _apiUri('getMyCommands'); var body = { 'scope': scope == null ? null : jsonEncode(scope), - 'language_code': language_code, + 'language_code': languageCode, }; return (await HttpClient.httpPost(requestUrl, body: body)) .map((botCommand) => BotCommand.fromJson(botCommand)) .toList(); } + /// Use this method to change the bot's name. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#setmyname + Future setMyName(String name, String languageCode) async { + var requestUrl = _apiUri('setMyName'); + var body = { + 'name': name, + 'language_code': languageCode, + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to get the current bot name for the given user language. + /// + /// Returns [BotName] on success. + /// + /// https://core.telegram.org/bots/api#getmyname + Future getMyName(String languageCode) async { + var requestUrl = _apiUri('getMyName'); + var body = { + 'language_code': languageCode, + }; + return BotName.fromJson(await HttpClient.httpPost(requestUrl, body: body)); + } + + /// Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#setmydescription + Future setMyDescription(String description, String languageCode) async { + var requestUrl = _apiUri('setMyDescription'); + var body = { + 'description': description, + 'language_code': languageCode, + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to get the current bot description for the given user language. + /// + /// Returns [BotDescription] on success. + /// + /// https://core.telegram.org/bots/api#getmydescription + Future getMyDescription(String languageCode) async { + var requestUrl = _apiUri('getMyDescription'); + var body = { + 'language_code': languageCode, + }; + return BotDescription.fromJson( + await HttpClient.httpPost(requestUrl, body: body)); + } + + /// Use this method to change the bot's short description, which is shown on the bot's profile page and is sent together with the link when users share the bot. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#setmyshortdescription + Future setMyShortDescription( + String shortDescription, String languageCode) async { + var requestUrl = _apiUri('setMyShortDescription'); + var body = { + 'short_description': shortDescription, + 'language_code': languageCode, + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to get the current bot short description for the given user language. + /// + /// Returns [BotShortDescription] on success. + /// + /// https://core.telegram.org/bots/api#getmyshortdescription + Future getMyShortDescription(String languageCode) async { + var requestUrl = _apiUri('getMyShortDescription'); + var body = { + 'language_code': languageCode, + }; + return BotShortDescription.fromJson( + await HttpClient.httpPost(requestUrl, body: body)); + } + + /// Use this method to change the bot's menu button in a private chat, or the default menu button. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#setchatmenubutton + Future setChatMenuButton(int? chatId, MenuButton? menuButton) async { + var requestUrl = _apiUri('setChatMenuButton'); + var body = { + 'chat_id': chatId, + 'menu_button': jsonEncode(menuButton), + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to get the current value of the bot's menu button in a private chat, or the default menu button. + /// + /// Returns [MenuButton] on success. + /// + /// https://core.telegram.org/bots/api#getchatmenubutton + Future getChatMenuButton(int? chatId) async { + var requestUrl = _apiUri('getChatMenuButton'); + var body = { + 'chat_id': chatId, + }; + return MenuButton.fromJson( + await HttpClient.httpPost(requestUrl, body: body)); + } + + /// Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels. + /// These rights will be suggested to users, but they are are free to modify the list before adding the bot. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#setmydefaultadministratorrights + Future setMyDefaultAdministratorRights( + ChatAdministratorRights? rights, bool? forChannels) async { + var requestUrl = _apiUri('setMyDefaultAdministratorRights'); + var body = { + 'rights': rights == null ? null : jsonEncode(rights), + 'for_channels': forChannels, + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to get the current default administrator rights of the bot. + /// + /// Returns [ChatAdministratorRights] on success. + /// + /// https://core.telegram.org/bots/api#getmydefaultadministratorrights + Future getMyDefaultAdministratorRights( + bool? forChannels) async { + var requestUrl = _apiUri('getMyDefaultAdministratorRights'); + var body = { + 'for_channels': forChannels, + }; + return ChatAdministratorRights.fromJson( + await HttpClient.httpPost(requestUrl, body: body)); + } + /// Use this method to edit text and [Game] messages sent by the bot or via the bot /// (for [inline bots]). /// @@ -1803,38 +2266,33 @@ class Telegram { /// https://core.telegram.org/bots/api#editmessagetext /// /// [inline bots]: https://core.telegram.org/bots/api#inline-mode - Future editMessageText(String text, - {dynamic chat_id, - int? message_id, - String? inline_message_id, - String? parse_mode, - bool? disable_web_page_preview, - InlineKeyboardMarkup? reply_markup}) async { - if (inline_message_id == null && (chat_id == null || message_id == null)) { + Future editMessageText(String text, + {dynamic chatId, + int? messageId, + String? inlineMessageId, + String? parseMode, + bool? disableWebPagePreview, + InlineKeyboardMarkup? replyMarkup}) async { + if (inlineMessageId == null && (chatId == null || messageId == null)) { return Future.error(TelegramException( - 'Require either \'chat_id\' and \'message_id\', or \'inline_message_id\'')); + 'Require either \'chatId\' and \'messageId\', or \'inlineMessageId\'')); } - if (chat_id != null && (chat_id is! String && chat_id is! int)) { + if (chatId != null && (chatId is! String && chatId is! int)) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('editMessageText'); var body = { - 'chat_id': chat_id, - 'message_id': message_id, - 'inline_message_id': inline_message_id, + 'chat_id': chatId, + 'message_id': messageId, + 'inline_message_id': inlineMessageId, 'text': text, - 'parse_mode': parse_mode, - 'disable_web_page_preview': disable_web_page_preview, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'parse_mode': parseMode, + 'disable_web_page_preview': disableWebPagePreview, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; var res = await HttpClient.httpPost(requestUrl, body: body); - if (res == true) { - return Future.error( - TelegramException('Edited message is NOT sent by the bot')); - } else { - return Message.fromJson(res); - } + return res == true ? res : Message.fromJson(res); } /// Use this method to edit captions of messages sent by the bot or via the bot @@ -1846,37 +2304,32 @@ class Telegram { /// https://core.telegram.org/bots/api#editmessagecaption /// /// [inline bots]: https://core.telegram.org/bots/api#inline-mode - Future editMessageCaption( - {dynamic chat_id, - int? message_id, - String? inline_message_id, + Future editMessageCaption( + {dynamic chatId, + int? messageId, + String? inlineMessageId, String? caption, - String? parse_mode, - InlineKeyboardMarkup? reply_markup}) async { - if (inline_message_id == null && (chat_id == null || message_id == null)) { + String? parseMode, + InlineKeyboardMarkup? replyMarkup}) async { + if (inlineMessageId == null && (chatId == null || messageId == null)) { return Future.error(TelegramException( - 'Require either \'chat_id\' and \'message_id\', or \'inline_message_id\'')); + 'Require either \'chatId\' and \'messageId\', or \'inlineMessageId\'')); } - if (chat_id != null && (chat_id is! String && chat_id is! int)) { + if (chatId != null && (chatId is! String && chatId is! int)) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('editMessageCaption'); var body = { - 'chat_id': chat_id, - 'message_id': message_id, - 'inline_message_id': inline_message_id, + 'chat_id': chatId, + 'message_id': messageId, + 'inline_message_id': inlineMessageId, 'caption': caption, - 'parse_mode': parse_mode, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'parse_mode': parseMode, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; var res = await HttpClient.httpPost(requestUrl, body: body); - if (res == true) { - return Future.error( - TelegramException('Edited message is NOT sent by the bot')); - } else { - return Message.fromJson(res); - } + return res == true ? res : Message.fromJson(res); } /// Use this method to edit audio, document, photo, or video messages @@ -1884,43 +2337,50 @@ class Telegram { /// If a message is a part of a message album, then it can be edited only to a photo or a video. /// Otherwise, message type can be changed arbitrarily. /// When inline message is edited, file can't be uploaded. - /// Use previously uploaded file via its file_id or specify a URL. + /// Use previously uploaded file via its fileId or specify a URL. /// /// On success, if the edited message was sent by the bot, the edited [Message] is returned, /// otherwise *True* is returned. /// /// https://core.telegram.org/bots/api#editMessageMedia - Future editMessageMedia( - {dynamic chat_id, - int? message_id, - String? inline_message_id, + Future editMessageMedia( + {dynamic chatId, + int? messageId, + String? inlineMessageId, InputMedia? media, - String? parse_mode, - InlineKeyboardMarkup? reply_markup}) async { - if (inline_message_id == null && (chat_id == null || message_id == null)) { + String? parseMode, + InlineKeyboardMarkup? replyMarkup}) async { + if (inlineMessageId == null && (chatId == null || messageId == null)) { return Future.error(TelegramException( - 'Require either \'chat_id\' and \'message_id\', or \'inline_message_id\'')); + 'Require either \'chatId\' and \'messageId\', or \'inlineMessageId\'')); } - if (chat_id != null && (chat_id is! String && chat_id is! int)) { + if (chatId != null && (chatId is! String && chatId is! int)) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('editMessageMedia'); var body = { - 'chat_id': chat_id, - 'message_id': message_id, - 'inline_message_id': inline_message_id, + 'chat_id': chatId, + 'message_id': messageId, + 'inline_message_id': inlineMessageId, 'media': media == null ? null : jsonEncode(media), - 'parse_mode': parse_mode, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'parse_mode': parseMode, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; - var res = await HttpClient.httpPost(requestUrl, body: body); - if (res == true) { - return Future.error( - TelegramException('Edited message is NOT sent by the bot')); - } else { - return Message.fromJson(res); - } + + List multiPartFiles = media == null + ? [] + : [ + media.mediaFile, + media is InputMediaWithThumbnail ? media.thumbnailFile : null + ].whereType().toList(); + + var res = multiPartFiles.isEmpty + ? await HttpClient.httpPost(requestUrl, body: body) + : await HttpClient.httpMultipartPost(requestUrl, multiPartFiles, + body: body); + + return res == true ? res : Message.fromJson(res); } /// Use this method to edit only the reply markup of messages sent by the bot or via the bot @@ -1932,33 +2392,29 @@ class Telegram { /// https://core.telegram.org/bots/api#editmessagereplymarkup /// /// [inline bots]: https://core.telegram.org/bots/api#inline-mode - Future editMessageReplyMarkup( - {dynamic chat_id, - int? message_id, - String? inline_message_id, - InlineKeyboardMarkup? reply_markup}) async { - if (inline_message_id == null && (chat_id == null || message_id == null)) { + Future editMessageReplyMarkup( + {dynamic chatId, + int? messageId, + String? inlineMessageId, + InlineKeyboardMarkup? replyMarkup}) async { + if (inlineMessageId == null && (chatId == null || messageId == null)) { return Future.error(TelegramException( - 'Require either \'chat_id\' and \'message_id\', or \'inline_message_id\'')); + 'Require either \'chatId\' and \'messageId\', or \'inlineMessageId\'')); } - if (chat_id != null && (chat_id is! String && chat_id is! int)) { + if (chatId != null && (chatId is! String && chatId is! int)) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('editMessageReplyMarkup'); var body = { - 'chat_id': chat_id, - 'message_id': message_id, - 'inline_message_id': inline_message_id, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'chat_id': chatId, + 'message_id': messageId, + 'inline_message_id': inlineMessageId, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; var res = await HttpClient.httpPost(requestUrl, body: body); - if (res == true) { - return Future.error( - TelegramException('Edited message is NOT sent by the bot')); - } else { - return Message.fromJson(res); - } + + return res == true ? res : Message.fromJson(res); } /// Use this method to stop a poll which was sent by the bot @@ -1966,17 +2422,20 @@ class Telegram { /// On success, the stopped [Poll] with the final results is returned. /// /// https://core.telegram.org/bots/api#stoppoll - Future stopPoll(dynamic chat_id, int message_id, - InlineKeyboardMarkup reply_markup) async { - if (chat_id is! String && chat_id is! int) { + Future stopPoll( + dynamic chatId, + int messageId, { + InlineKeyboardMarkup? replyMarkup, + }) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('stopPoll'); var body = { - 'chat_id': chat_id, - 'message_id': message_id, - 'reply_markup': reply_markup, + 'chat_id': chatId, + 'message_id': messageId, + 'reply_markup': replyMarkup != null ? jsonEncode(replyMarkup) : null, }; return Poll.fromJson(await HttpClient.httpPost(requestUrl, body: body)); } @@ -1987,22 +2446,22 @@ class Telegram { /// * A message can only be deleted if it was sent less than 48 hours ago. /// * Bots can delete outgoing messages in groups and supergroups. /// * Bots can delete incoming messages in private chats. - /// * Bots granted can_post_messages permissions can delete outgoing messages in channels. + /// * Bots granted canPostMessages permissions can delete outgoing messages in channels. /// * If the bot is an administrator of a group, it can delete any message there. - /// * If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. + /// * If the bot has canDeleteMessages permission in a supergroup or a channel, it can delete any message there. /// /// Returns *True* on success. /// /// https://core.telegram.org/bots/api#deletemessage - Future deleteMessage(dynamic chat_id, int message_id) async { - if (chat_id is! String && chat_id is! int) { + Future deleteMessage(dynamic chatId, int messageId) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('deleteMessage'); var body = { - 'chat_id': chat_id, - 'message_id': message_id, + 'chat_id': chatId, + 'message_id': messageId, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -2012,24 +2471,28 @@ class Telegram { /// On success, the sent [Message] is returned. /// /// https://core.telegram.org/bots/api#sendsticker - Future sendSticker(dynamic chat_id, dynamic sticker, - {bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - ReplyMarkup? reply_markup}) async { - if (chat_id is! String && chat_id is! int) { - return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + Future sendSticker(dynamic chatId, dynamic sticker, + {int? messageThreadId, + String? emoji, + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + ReplyMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendSticker'); var body = { - 'chat_id': chat_id, - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'chat_id': chatId, + 'message_thread_id': messageThreadId, + 'emoji': emoji, + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; if (sticker is io.File) { @@ -2046,7 +2509,7 @@ class Telegram { await HttpClient.httpPost(requestUrl, body: body)); } else { return Future.error(TelegramException( - 'Attribute \'sticker\' can only be either io.File or String (Telegram file_id or image url)')); + 'Attribute \'sticker\' can only be either io.File or String (Telegram fileId or image url)')); } } @@ -2062,21 +2525,41 @@ class Telegram { await HttpClient.httpPost(requestUrl, body: body)); } + /// Use this method to get information about custom emoji stickers by their identifiers. + /// + /// Returns an Array of [Sticker] objects. + /// + /// https://core.telegram.org/bots/api#getcustomemojistickers + Future> getCustomEmojiStickers( + List customEmojiIds) async { + var requestUrl = _apiUri('getCustomEmojiStickers'); + var body = { + 'custom_emoji_ids': jsonEncode(customEmojiIds) + }; + return (await HttpClient.httpPost(requestUrl, body: body)) + .map((sticker) => Sticker.fromJson(sticker)) + .toList(); + } + /// Use this method to upload a .png file with a sticker for later use in /// *createNewStickerSet* and *addStickerToSet* methods (can be used multiple times) /// /// Returns the uploaded [File] on success. /// /// https://core.telegram.org/bots/api#uploadstickerfile - Future uploadStickerFile(int user_id, io.File png_sticker) async { + Future uploadStickerFile( + int userId, io.File sticker, String stickerFormat) async { var requestUrl = _apiUri('uploadStickerFile'); - var body = {'user_id': user_id}; - // filename cannot be empty to post to Telegram server - var files = List.filled( - 1, - MultipartFile( - 'png_sticker', png_sticker.openRead(), png_sticker.lengthSync(), - filename: '${png_sticker.lengthSync()}')); + var body = { + 'user_id': userId, + 'sticker_format': stickerFormat, + }; + + var files = List.from([ + MultipartFile('sticker', sticker.openRead(), sticker.lengthSync(), + filename: '${sticker.lengthSync()}') + ]); + return File.fromJson( await HttpClient.httpMultipartPost(requestUrl, files, body: body)); } @@ -2084,54 +2567,42 @@ class Telegram { /// Use this method to create sticker set owned by a user /// /// The bot will be able to edit the created sticker set. - /// You **must** use exactly one of the *fields png_sticker*, *tgs_sticker*, or *webm_sticker*. + /// You **must** use exactly one of the *fields pngSticker*, *tgsSticker*, or *webmSticker*. /// /// Returns *True* on success. /// /// https://core.telegram.org/bots/api#createnewstickerset - Future createNewStickerSet( - int user_id, String name, String title, String emojis, - {dynamic png_sticker, - io.File? tgs_sticker, - io.File? webm_sticker, - bool? contains_masks, - MaskPosition? mask_position}) async { + Future createNewStickerSet(int userId, String name, String title, + List stickers, String stickerFormat, + {String? stickerType, bool? needsRepainting}) async { var requestUrl = _apiUri('createNewStickerSet'); var botInfo = await getMe(); var body = { - 'user_id': user_id, + 'user_id': userId, 'name': '${name}_by_${botInfo.username}', 'title': title, - 'emojis': emojis, - 'contains_masks': contains_masks, - 'mask_position': mask_position == null ? null : jsonEncode(mask_position), + 'stickers': jsonEncode(stickers), + 'sticker_format': stickerFormat, + 'sticker_type': stickerType, + 'needs_repainting': needsRepainting, }; - if (png_sticker == null && tgs_sticker == null && webm_sticker == null) { - return Future.error(TelegramException( - 'You must use exactly one of the fields `png_sticker`, `tgs_sticker` or `webm_sticker`.')); - } else if (png_sticker is String) { - body.addAll({'png_sticker': png_sticker}); - return await HttpClient.httpPost(requestUrl, body: body); - } else if (png_sticker is io.File || tgs_sticker != null || webm_sticker != null ) { - var file = png_sticker ?? tgs_sticker ?? webm_sticker; - var fieldName = png_sticker != null ? 'png_sticker' : tgs_sticker != null ? 'tgs_sticker' : 'webm_sticker'; - // filename cannot be empty to post to Telegram server - var files = List.filled( - 1, - MultipartFile( - fieldName, file.openRead(), file.lengthSync(), - filename: '${file.lengthSync()}')); - return await HttpClient.httpMultipartPost(requestUrl, files, body: body); + List stickerFiles = stickers + .map((it) => it.stickerFile) + .whereType() + .toList(); + + if (stickerFiles.isNotEmpty) { + return await HttpClient.httpMultipartPost(requestUrl, stickerFiles, + body: body); } else { - return Future.error(TelegramException( - 'Attribute \'png_sticker\' can only be either io.File or String (Telegram file_id or image url)')); + return await HttpClient.httpPost(requestUrl, body: body); } } /// Use this method to add a new sticker to a set created by the bot /// - /// You **must** use exactly one of the *fields png_sticker*, *tgs_sticker*, or *webm_sticker*. + /// You **must** use exactly one of the fields *png_sticker*, *tgs_sticker*, or *webm_sticker*. /// Animated stickers can be added to animated sticker sets and only to them. /// Animated sticker sets can have up to 50 stickers. /// Static sticker sets can have up to 120 stickers. @@ -2139,38 +2610,21 @@ class Telegram { /// Returns *True* on success. /// /// https://core.telegram.org/bots/api#addstickertoset - Future addStickerToSet(int user_id, String name, String emojis, - {dynamic png_sticker, - io.File? tgs_sticker, - io.File? webm_sticker, - MaskPosition? mask_position}) async { + Future addStickerToSet( + int userId, String name, InputSticker sticker) async { var requestUrl = _apiUri('addStickerToSet'); var body = { - 'user_id': user_id, + 'user_id': userId, 'name': name, - 'emojis': emojis, - 'mask_position': mask_position == null ? null : jsonEncode(mask_position), + 'stickers': jsonEncode(sticker), }; - if (png_sticker == null && tgs_sticker == null && webm_sticker == null) { - return Future.error(TelegramException( - 'You must use exactly one of the fields `png_sticker`, `tgs_sticker` or `webm_sticker`.')); - } else if (png_sticker is String) { - body.addAll({'png_sticker': png_sticker}); - return await HttpClient.httpPost(requestUrl, body: body); - } else if (png_sticker is io.File || tgs_sticker != null || webm_sticker != null ) { - var file = png_sticker ?? tgs_sticker ?? webm_sticker; - var fieldName = png_sticker != null ? 'png_sticker' : tgs_sticker != null ? 'tgs_sticker' : 'webm_sticker'; - // filename cannot be empty to post to Telegram server - var files = List.filled( - 1, - MultipartFile( - fieldName, file.openRead(), file.lengthSync(), - filename: '${file.lengthSync()}')); - return await HttpClient.httpMultipartPost(requestUrl, files, body: body); + if (sticker.stickerFile != null) { + return await HttpClient.httpMultipartPost( + requestUrl, List.from([sticker.stickerFile]), + body: body); } else { - return Future.error(TelegramException( - 'Attribute \'png_sticker\' can only be either io.File or String (Telegram file_id or image url)')); + return await HttpClient.httpPost(requestUrl, body: body); } } @@ -2199,36 +2653,127 @@ class Telegram { return await HttpClient.httpPost(requestUrl, body: body); } + /// Use this method to change the list of emoji assigned to a regular or custom emoji sticker. + /// The sticker must belong to a sticker set created by the bot. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#setstickeremojilist + Future setStickerEmojiList( + String sticker, List emojiList) async { + var requestUrl = _apiUri('setStickerEmojiList'); + var body = { + 'sticker': sticker, + 'emoji_list': jsonEncode(emojiList), + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to change search keywords assigned to a regular or custom emoji sticker. + /// The sticker must belong to a sticker set created by the bot. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#setstickerkeywords + Future setStickerKeywords( + String sticker, List? keywords) async { + var requestUrl = _apiUri('setStickerKeywords'); + var body = { + 'sticker': sticker, + 'keywords': keywords == null ? null : jsonEncode(keywords), + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to change the [MaskPosition] of a mask sticker. + /// The sticker must belong to a sticker set that was created by the bot. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#setstickermaskposition + Future setStickerMaskPosition( + String sticker, MaskPosition? maskPosition) async { + var requestUrl = _apiUri('setStickerMaskPosition'); + var body = { + 'sticker': sticker, + 'mask_position': maskPosition == null ? null : jsonEncode(maskPosition), + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to set the title of a created sticker set. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#setstickersettitle + Future setStickerSetTitle(String name, String title) async { + var requestUrl = _apiUri('setStickerSetTitle'); + var body = { + 'name': name, + 'title': title, + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + /// Use this method to set the thumbnail of a sticker set /// /// Animated thumbnails can be set for animated sticker sets only. /// /// Returns *True* on success. - Future setStickerSetThumb(String name, int user_id, - {dynamic thumb}) async { - var requestUrl = _apiUri('setStickerSetThumb'); + /// + /// https://core.telegram.org/bots/api#setstickersetthumbnail + Future setStickerSetThumbnail(String name, int userId, + {dynamic thumbnail}) async { + var requestUrl = _apiUri('setStickerSetThumbnail'); var body = { 'name': name, - 'user_id': user_id, + 'user_id': userId, }; - if (thumb == null) { + if (thumbnail == null) { return await HttpClient.httpPost(requestUrl, body: body); - } else if (thumb is io.File) { + } else if (thumbnail is io.File) { // filename cannot be empty to post to Telegram server var files = List.filled( 1, - MultipartFile('thumb', thumb.openRead(), thumb.lengthSync(), - filename: '${thumb.lengthSync()}')); + MultipartFile( + 'thumbnail', thumbnail.openRead(), thumbnail.lengthSync(), + filename: '${thumbnail.lengthSync()}')); return await HttpClient.httpMultipartPost(requestUrl, files, body: body); - } else if (thumb is String) { - body.addAll({'thumb': thumb}); + } else if (thumbnail is String) { + body.addAll({'thumbnail': thumbnail}); return await HttpClient.httpPost(requestUrl, body: body); } else { return Future.error(TelegramException( - 'Attribute \'thumb\' can only be either io.File or String (Telegram file_id or image url)')); + 'Attribute \'thumbnail\' can only be either io.File or String (Telegram fileId or image url)')); } } + /// Use this method to set the thumbnail of a custom emoji sticker set. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail + Future setCustomEmojiStickerSetThumbnail(String name, + {String? customEmojiId}) async { + var requestUrl = _apiUri('setCustomEmojiStickerSetThumbnail'); + var body = { + 'name': name, + 'custom_emoji_id': customEmojiId, + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to delete a sticker set that was created by the bot. + /// + /// Returns *True* on success. + /// + /// https://core.telegram.org/bots/api#deletestickerset + Future deleteStickerSet(String name) async { + var requestUrl = _apiUri('deleteStickerSet'); + var body = {'name': name}; + return await HttpClient.httpPost(requestUrl, body: body); + } + /// Use this method to send answers to an inline query /// /// On success, *True* is returned. @@ -2237,21 +2782,39 @@ class Telegram { /// /// https://core.telegram.org/bots/api#answerinlinequery Future answerInlineQuery( - String inline_query_id, List results, - {int? cache_time, - bool? is_personal, - String? next_offset, - String? switch_pm_text, - String? switch_pm_parameter}) async { + String inlineQueryId, + List results, { + int? cacheTime, + bool? isPersonal, + String? nextOffset, + InlineQueryResultsButton? button, + }) async { var requestUrl = _apiUri('answerInlineQuery'); var body = { - 'inline_query_id': inline_query_id, + 'inline_query_id': inlineQueryId, 'results': jsonEncode(results), - 'cache_time': cache_time, - 'is_personal': is_personal, - 'next_offset': next_offset, - 'switch_pm_text': switch_pm_text, - 'switch_pm_parameter': switch_pm_parameter, + 'cache_time': cacheTime, + 'is_personal': isPersonal, + 'next_offset': nextOffset, + 'button': button == null ? null : jsonEncode(button), + }; + return await HttpClient.httpPost(requestUrl, body: body); + } + + /// Use this method to set the result of an interaction with a [Web App] and send a corresponding + /// message on behalf of the user to the chat from which the query originated. + /// + /// On success, a [SentWebAppMessage] object is returned. + /// + /// https://core.telegram.org/bots/api#answerwebappquery + /// + /// [Web App]: (https://core.telegram.org/bots/webapps) + Future answerWebAppQuery( + String webAppQueryId, InlineQueryResult result) async { + var requestUrl = _apiUri('answerWebAppQuery'); + var body = { + 'web_app_query_id': webAppQueryId, + 'result': jsonEncode(result), }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -2262,93 +2825,123 @@ class Telegram { /// /// https://core.telegram.org/bots/api#sendinvoice Future sendInvoice( - dynamic chat_id, + dynamic chatId, String title, String description, String payload, - String provider_token, + String providerToken, String currency, List prices, - {int? max_tip_amount, - List? suggested_tip_amounts, - String? start_parameter, - String? provider_data, - String? photo_url, - int? photo_size, - int? photo_width, - int? photo_height, - bool? need_name, - bool? need_phone_number, - bool? need_email, - bool? need_shipping_address, - bool? send_phone_number_to_provider, - bool? send_email_to_provider, - bool? is_flexible, - bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - InlineKeyboardMarkup? reply_markup}) async { - if (chat_id is! String && chat_id is! int) { - return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + {int? messageThreadId, + int? maxTipAmount, + List? suggestedTipAmounts, + String? startParameter, + String? providerData, + String? photoUrl, + int? photoSize, + int? photoWidth, + int? photoHeight, + bool? needName, + bool? needPhoneNumber, + bool? needEmail, + bool? needShippingAddress, + bool? sendPhoneNumberToProvider, + bool? sendEmailToProvider, + bool? isFlexible, + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + InlineKeyboardMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { + return Future.error(TelegramException( + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendInvoice'); var body = { - 'chat_id': chat_id, + 'chat_id': chatId, + 'message_thread_id': messageThreadId, 'title': title, 'description': description, 'payload': payload, - 'provider_token': provider_token, + 'provider_token': providerToken, 'currency': currency, 'prices': jsonEncode(prices), - 'max_tip_amount': max_tip_amount, - 'suggested_tip_amounts': suggested_tip_amounts == null - ? null - : jsonEncode(suggested_tip_amounts), - 'start_parameter': start_parameter, - 'provider_data': provider_data, - 'photo_url': photo_url, - 'photo_size': photo_size, - 'photo_width': photo_width, - 'photo_height': photo_height, - 'need_name': need_name, - 'need_phone_number': need_phone_number, - 'need_email': need_email, - 'need_shipping_address': need_shipping_address, - 'send_phone_number_to_provider': send_phone_number_to_provider, - 'send_email_to_provider': send_email_to_provider, - 'is_flexible': is_flexible, - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'max_tip_amount': maxTipAmount, + 'suggested_tip_amounts': + suggestedTipAmounts == null ? null : jsonEncode(suggestedTipAmounts), + 'start_parameter': startParameter, + 'provider_data': providerData, + 'photo_url': photoUrl, + 'photo_size': photoSize, + 'photo_width': photoWidth, + 'photo_height': photoHeight, + 'need_name': needName, + 'need_phone_number': needPhoneNumber, + 'need_email': needEmail, + 'need_shipping_address': needShippingAddress, + 'send_phone_number_to_provider': sendPhoneNumberToProvider, + 'send_email_to_provider': sendEmailToProvider, + 'is_flexible': isFlexible, + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body)); } + /// Use this method to create a link for an invoice. + /// + /// Returns the created invoice link as *String* on success + Future createInvoiceLink( + String title, + String description, + String payload, + String providerToken, + String currency, + List prices, + {int? maxTipAmount, + List? suggestedTipAmounts, + String? providerData, + String? photoUrl, + int? photoSize, + int? photoWidth, + int? photoHeight, + bool? needName, + bool? needPhoneNumber, + bool? needEmail, + bool? needShippingAddress, + bool? sendPhoneNumberToProvider, + bool? sendEmailToProvider, + bool? isFlexible}) async { + var requestUrl = _apiUri('createInvoiceLink'); + var body = {}; + return await HttpClient.httpPost(requestUrl, body: body); + } + /// Use this method to reply to shipping queries. /// - /// If you sent an invoice requesting a shipping address and the parameter *is_flexible* was specified, - /// the Bot API will send an [Update] with a *shipping_query* field to the bot. + /// If you sent an invoice requesting a shipping address and the parameter *isFlexible* was specified, + /// the Bot API will send an [Update] with a *shippingQuery* field to the bot. /// /// On success, *True* is returned. /// /// https://core.telegram.org/bots/api#answershippingquery - Future answerShippingQuery(String shipping_query_id, bool ok, - {List? shipping_options, String? error_message}) async { - if (!ok && (shipping_options == null || error_message == null)) { + Future answerShippingQuery(String shippingQueryId, bool ok, + {List? shippingOptions, String? errorMessage}) async { + if (!ok && (shippingOptions == null || errorMessage == null)) { return Future.error(TelegramException( - 'Attribute \'shipping_options\' and \'error_message\' can not be null when \'ok\' = false')); + 'Attribute \'shippingOptions\' and \'errorMessage\' can not be null when \'ok\' = false')); } var requestUrl = _apiUri('answerShippingQuery'); var body = { - 'shipping_query_id': shipping_query_id, + 'shipping_query_id': shippingQueryId, 'ok': ok, 'shipping_options': - shipping_options == null ? null : jsonEncode(shipping_options), - 'error_message': error_message, + shippingOptions == null ? null : jsonEncode(shippingOptions), + 'error_message': errorMessage, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -2356,24 +2949,24 @@ class Telegram { /// Use this method to respond to such pre-checkout queries /// /// Once the user has confirmed their payment and shipping details, - /// the Bot API sends the final confirmation in the form of an [Update] with the field *pre_checkout_query*. + /// the Bot API sends the final confirmation in the form of an [Update] with the field *preCheckoutQuery*. /// /// On success, *True* is returned. /// /// **Note:** The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent. /// /// https://core.telegram.org/bots/api#answerprecheckoutquery - Future answerPreCheckoutQuery(String pre_checkout_query_id, bool ok, - {String? error_message}) async { - if (!ok && error_message == null) { + Future answerPreCheckoutQuery(String preCheckoutQueryId, bool ok, + {String? errorMessage}) async { + if (!ok && errorMessage == null) { return Future.error(TelegramException( - 'Attribute \'error_message\' can not be null when \'ok\' = false')); + 'Attribute \'errorMessage\' can not be null when \'ok\' = false')); } var requestUrl = _apiUri('answerPreCheckoutQuery'); var body = { - 'pre_checkout_query_id': pre_checkout_query_id, + 'pre_checkout_query_id': preCheckoutQueryId, 'ok': ok, - 'error_message': error_message, + 'error_message': errorMessage, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -2392,10 +2985,10 @@ class Telegram { /// /// https://core.telegram.org/bots/api#setpassportdataerrors Future setPassportDataErrors( - int user_id, List errors) async { + int userId, List errors) async { var requestUrl = _apiUri('setPassportDataErrors'); var body = { - 'user_id': user_id, + 'user_id': userId, 'errors': jsonEncode(errors), }; return await HttpClient.httpPost(requestUrl, body: body); @@ -2406,25 +2999,27 @@ class Telegram { /// On success, the sent [Message] is returned. /// /// https://core.telegram.org/bots/api#sendgame - Future sendGame(dynamic chat_id, String game_short_name, - {bool? disable_notification, - bool? protect_content, - int? reply_to_message_id, - bool? allow_sending_without_reply, - InlineKeyboardMarkup? reply_markup}) async { - if (chat_id is! String && chat_id is! int) { + Future sendGame(dynamic chatId, String gameShortName, + {int? messageThreadId, + bool? disableNotification, + bool? protectContent, + int? replyToMessageId, + bool? allowSendingWithoutReply, + InlineKeyboardMarkup? replyMarkup}) async { + if (chatId is! String && chatId is! int) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('sendGame'); var body = { - 'chat_id': chat_id, - 'game_short_name': game_short_name, - 'disable_notification': disable_notification, - 'protect_content': protect_content, - 'reply_to_message_id': reply_to_message_id, - 'allow_sending_without_reply': allow_sending_without_reply, - 'reply_markup': reply_markup == null ? null : jsonEncode(reply_markup), + 'chat_id': chatId, + 'message_thread_id': messageThreadId, + 'game_short_name': gameShortName, + 'disable_notification': disableNotification, + 'protect_content': protectContent, + 'reply_to_message_id': replyToMessageId, + 'allow_sending_without_reply': allowSendingWithoutReply, + 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body)); } @@ -2436,29 +3031,29 @@ class Telegram { /// if the score is not greater than the user's current score in the chat and force is *False*. /// /// https://core.telegram.org/bots/api#setgamescore - Future setGameScore(int user_id, int score, + Future setGameScore(int userId, int score, {bool? force, - bool? disable_edit_message, - dynamic chat_id, - int? message_id, - String? inline_message_id}) async { - if (inline_message_id == null && (chat_id == null || message_id == null)) { + bool? disableEditMessage, + dynamic chatId, + int? messageId, + String? inlineMessageId}) async { + if (inlineMessageId == null && (chatId == null || messageId == null)) { return Future.error(TelegramException( - 'Require either \'chat_id\' and \'message_id\', or \'inline_message_id\'')); + 'Require either \'chatId\' and \'messageId\', or \'inlineMessageId\'')); } - if (chat_id != null && (chat_id is! String && chat_id is! int)) { + if (chatId != null && (chatId is! String && chatId is! int)) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('setGameScore'); var body = { - 'user_id': user_id, + 'user_id': userId, 'score': score, 'force': force, - 'disable_edit_message': disable_edit_message, - 'chat_id': chat_id, - 'message_id': message_id, - 'inline_message_id': inline_message_id, + 'disable_edit_message': disableEditMessage, + 'chat_id': chatId, + 'message_id': messageId, + 'inline_message_id': inlineMessageId, }; return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body)); } @@ -2474,22 +3069,22 @@ class Telegram { /// Please note that this behavior is subject to change. /// /// https://core.telegram.org/bots/api#getgamehighscores - Future> getGameHighScores(int user_id, - {dynamic chat_id, int? message_id, String? inline_message_id}) async { - if (inline_message_id == null && (chat_id == null || message_id == null)) { + Future> getGameHighScores(int userId, + {dynamic chatId, int? messageId, String? inlineMessageId}) async { + if (inlineMessageId == null && (chatId == null || messageId == null)) { return Future.error(TelegramException( - 'Require either \'chat_id\' and \'message_id\', or \'inline_message_id\'')); + 'Require either \'chatId\' and \'messageId\', or \'inlineMessageId\'')); } - if (chat_id != null && (chat_id is! String && chat_id is! int)) { + if (chatId != null && (chatId is! String && chatId is! int)) { return Future.error(TelegramException( - 'Attribute \'chat_id\' can only be either type of String or int')); + 'Attribute \'chatId\' can only be either type of String or int')); } var requestUrl = _apiUri('getGameHighScores'); var body = { - 'user_id': user_id, - 'chat_id': chat_id, - 'message_id': message_id, - 'inline_message_id': inline_message_id, + 'user_id': userId, + 'chat_id': chatId, + 'message_id': messageId, + 'inline_message_id': inlineMessageId, }; return (await HttpClient.httpPost(requestUrl, body: body)) .map( diff --git a/lib/src/util/http_client.dart b/lib/src/util/http_client.dart index eef4007b..9e6f475f 100644 --- a/lib/src/util/http_client.dart +++ b/lib/src/util/http_client.dart @@ -22,26 +22,36 @@ import 'dart:io' as io; import 'package:http/http.dart' as http; +import '../../model.dart'; + /// An internal helper class for easier http request management class HttpClient { static bool _nullFilter(_, value) => value == null; static http.MultipartFile toMultiPartFile(io.File file, String fieldName) => http.MultipartFile(fieldName, file.openRead(), file.lengthSync(), - filename: '${file.path.split(io.Platform.pathSeparator).last}'); + filename: file.path.split(io.Platform.pathSeparator).last); + + /// Parse http response + /// [response] - http response + static Future _parseResponse(http.Response response) { + Map jsonBody = jsonDecode(response.body); + Response responseBody = Response.fromJson(jsonBody); + if (responseBody.ok) { + return Future.value(SuccessResponse.fromJson(jsonBody).result); + } else { + ErrorResponse errorResponse = ErrorResponse.fromJson(jsonBody); + return Future.error(HttpClientException(errorResponse.errorCode, + errorResponse.description, errorResponse.parameters)); + } + } /// HTTP get method /// [url] request url with query string (required) - static Future httpGet(Uri url) async => - http.get(url).then((response) { - Map responseBody = jsonDecode(response.body); - if (responseBody['ok']) { - return responseBody['result']; - } else { - return Future.error(HttpClientException( - responseBody['error_code'], responseBody['description'])); - } - }).catchError((error) => Future.error(error)); + static Future httpGet(Uri url) async => http + .get(url) + .then(_parseResponse) + .catchError((error) => Future.error(error)); /// HTTP post method (x-www-form-urlencoded) /// [url] - request url (required) @@ -50,15 +60,8 @@ class HttpClient { body?.removeWhere(_nullFilter); return http .post(url, body: body?.map((k, v) => MapEntry(k, '$v'))) - .then((response) { - Map responseBody = jsonDecode(response.body); - if (responseBody['ok']) { - return responseBody['result']; - } else { - return Future.error(HttpClientException( - responseBody['error_code'], responseBody['description'])); - } - }).catchError((error) => Future.error(error)); + .then(_parseResponse) + .catchError((error) => Future.error(error)); } /// HTTP post method (multipart/form-data) @@ -76,23 +79,18 @@ class HttpClient { return request .send() .then((response) => http.Response.fromStream(response)) - .then((response) { - Map responseBody = jsonDecode(response.body); - if (responseBody['ok']) { - return responseBody['result']; - } else { - return Future.error(HttpClientException( - responseBody['error_code'], responseBody['description'])); - } - }).catchError((error) => Future.error(error)); + .then(_parseResponse) + .catchError((error) => Future.error(error)); } } class HttpClientException implements Exception { int code; String description; - HttpClientException(this.code, this.description); + ResponseParameters? parameters; + HttpClientException(this.code, this.description, this.parameters); bool isHttpClientError() => code >= 400 && code < 500; + bool isTooManyRequests() => code == 429; @override String toString() => 'HttpClientException: $code $description'; } diff --git a/lib/teledart.dart b/lib/teledart.dart index f8633989..f1aaf3c0 100644 --- a/lib/teledart.dart +++ b/lib/teledart.dart @@ -31,3 +31,4 @@ export 'src/teledart/event/event.dart'; export 'src/teledart/fetch/abstract_update_fetcher.dart'; export 'src/teledart/fetch/long_polling.dart'; export 'src/teledart/fetch/webhook.dart'; +export 'src/util/http_client.dart' show HttpClientException; diff --git a/lib/util.dart b/lib/util.dart new file mode 100644 index 00000000..1f3e232f --- /dev/null +++ b/lib/util.dart @@ -0,0 +1,24 @@ +/** + * TeleDart - Telegram Bot API for Dart + * Copyright (C) 2019 Dino PH Leung + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/// Util classes for TeleDart + +library util; + +export 'src/util/http_client.dart'; +export 'src/util/time_helper.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index 4416f2a5..ad4c8992 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,18 +1,18 @@ name: teledart description: A Dart library interfacing with the latest Telegram Bot API. -version: 0.3.4 +version: 0.6.2 homepage: https://github.com/DinoLeung/TeleDart issue_tracker: https://github.com/DinoLeung/TeleDart/issues environment: - sdk: ">=2.14.0 <3.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: - json_annotation: ^4.4.0 - http: ^0.13.4 + json_annotation: ^4.8.1 + http: ^1.1.0 dev_dependencies: - test: ^1.20.1 - build_runner: ^2.1.7 - json_serializable: ^6.1.3 - lints: ^1.0.1 + test: ^1.24.6 + build_runner: ^2.4.6 + json_serializable: ^6.7.1 + lints: ^2.1.1 diff --git a/test/TeleDart_test.dart b/test/TeleDart_test.dart deleted file mode 100644 index 71a9f599..00000000 --- a/test/TeleDart_test.dart +++ /dev/null @@ -1,12 +0,0 @@ -// import 'package:teledart/teledart.dart'; -import 'package:test/test.dart'; - -void main() { - group('A group of tests', () { - setUp(() {}); - - test('First Test', () { - // TODO: TEST ME PLEASE - }); - }); -} diff --git a/test/teledart_test.dart b/test/teledart_test.dart new file mode 100644 index 00000000..8e1904cf --- /dev/null +++ b/test/teledart_test.dart @@ -0,0 +1,22 @@ +import 'dart:io'; + +import 'package:teledart/teledart.dart'; +import 'package:test/test.dart'; + +void main() { + TeleDart teleDart = TeleDart( + Platform.environment["BOT_TOKEN"]!, + Event(Platform.environment["BOT_USERNAME"] ?? ""), + ); + group('Senders', () { + setUp(() {}); + + test('sendMessage', () async { + final msg = await teleDart.sendMessage( + Platform.environment["CHAT_ID"]!, + "Hello World!", + ); + expect(msg.text, "Hello World!"); + }); + }); +}