diff --git a/CHANGELOG.md b/CHANGELOG.md index 1257e1b..314670c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## 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 diff --git a/README.md b/README.md index f06903a..3a09d55 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-6.4-blue.svg?style=flat-square)](https://core.telegram.org/bots/api) -[![Dart Version](https://img.shields.io/badge/Dart-2.18-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) diff --git a/lib/src/teledart/model/inline_query.dart b/lib/src/teledart/model/inline_query.dart index b06144b..1cc2770 100644 --- a/lib/src/teledart/model/inline_query.dart +++ b/lib/src/teledart/model/inline_query.dart @@ -57,13 +57,14 @@ class TeleDartInlineQuery extends InlineQuery { int? cacheTime, bool? isPersonal, String? nextOffset, - String? switchPmText, - String? switchPmParameter, + InlineQueryResultsButton? button, }) => - _teledart.answerInlineQuery(id, results, - cacheTime: cacheTime, - isPersonal: isPersonal, - nextOffset: nextOffset, - switchPmText: switchPmText, - switchPmParameter: switchPmParameter); + _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 bd9a70e..86c380a 100644 --- a/lib/src/teledart/model/message.dart +++ b/lib/src/teledart/model/message.dart @@ -62,6 +62,7 @@ class TeleDartMessage extends Message { document: message.document, photo: message.photo, sticker: message.sticker, + story: message.story, video: message.video, videoNote: message.videoNote, voice: message.voice, @@ -88,6 +89,8 @@ class TeleDartMessage extends Message { pinnedMessage: message.pinnedMessage, invoice: message.invoice, successfulPayment: message.successfulPayment, + userShared: message.userShared, + chatShared: message.chatShared, connectedWebsite: message.connectedWebsite, writeAccessAllowed: message.writeAccessAllowed, passportData: message.passportData, @@ -190,7 +193,7 @@ class TeleDartMessage extends Message { int? duration, String? performer, String? title, - dynamic thumb, + dynamic thumbnail, bool? disableNotification, bool? allowSendingWithoutReply, ReplyMarkup? replyMarkup, @@ -203,7 +206,7 @@ class TeleDartMessage extends Message { duration: duration, performer: performer, title: title, - thumb: thumb, + thumbnail: thumbnail, disableNotification: disableNotification, replyToMessageId: withQuote ? messageId : null, allowSendingWithoutReply: allowSendingWithoutReply, @@ -223,7 +226,7 @@ class TeleDartMessage extends Message { Future replyDocument( dynamic document, { bool withQuote = false, - dynamic thumb, + dynamic thumbnail, String? caption, String? parseMode, List? captionEntities, @@ -233,7 +236,7 @@ class TeleDartMessage extends Message { }) => _teledart.sendDocument(chat.id, document, messageThreadId: messageThreadId, - thumb: thumb, + thumbnail: thumbnail, caption: caption, parseMode: parseMode, captionEntities: captionEntities, @@ -259,7 +262,7 @@ class TeleDartMessage extends Message { int? duration, int? width, int? height, - dynamic thumb, + dynamic thumbnail, String? caption, String? parseMode, List? captionEntities, @@ -274,7 +277,7 @@ class TeleDartMessage extends Message { duration: duration, width: width, height: height, - thumb: thumb, + thumbnail: thumbnail, caption: caption, parseMode: parseMode, captionEntities: captionEntities, @@ -302,7 +305,7 @@ class TeleDartMessage extends Message { int? duration, int? width, int? height, - dynamic thumb, + dynamic thumbnail, String? caption, String? parseMode, List? captionEntities, @@ -316,7 +319,7 @@ class TeleDartMessage extends Message { duration: duration, width: width, height: height, - thumb: thumb, + thumbnail: thumbnail, caption: caption, parseMode: parseMode, captionEntities: captionEntities, @@ -373,7 +376,7 @@ class TeleDartMessage extends Message { bool withQuote = false, int? duration, int? length, - dynamic thumb, + dynamic thumbnail, bool? disableNotification, bool? allowSendingWithoutReply, ReplyMarkup? replyMarkup, @@ -382,7 +385,7 @@ class TeleDartMessage extends Message { messageThreadId: messageThreadId, duration: duration, length: length, - thumb: thumb, + thumbnail: thumbnail, disableNotification: disableNotification, replyToMessageId: withQuote ? messageId : null, allowSendingWithoutReply: allowSendingWithoutReply, diff --git a/lib/src/telegram/model.dart b/lib/src/telegram/model.dart index 09c5c79..babbd01 100644 --- a/lib/src/telegram/model.dart +++ b/lib/src/telegram/model.dart @@ -16,8 +16,10 @@ * 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'; @@ -32,6 +34,9 @@ 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/chat_administrator_rights.dart'; @@ -48,6 +53,7 @@ part 'models/chat_member_updated.dart'; part 'models/chat_member.dart'; part 'models/chat_permissions.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'; @@ -89,6 +95,7 @@ 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'; @@ -98,12 +105,16 @@ 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_venue_message_content.dart'; part 'models/invoice.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'; @@ -147,9 +158,12 @@ 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'; diff --git a/lib/src/telegram/model.g.dart b/lib/src/telegram/model.g.dart index da656f8..28bd457 100644 --- a/lib/src/telegram/model.g.dart +++ b/lib/src/telegram/model.g.dart @@ -12,9 +12,9 @@ Animation _$AnimationFromJson(Map json) => Animation( width: json['width'] as int, height: json['height'] as int, duration: json['duration'] as int, - thumb: json['thumb'] == null + thumbnail: json['thumbnail'] == null ? null - : PhotoSize.fromJson(json['thumb'] 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?, @@ -35,7 +35,7 @@ Map _$AnimationToJson(Animation instance) { } } - writeNotNull('thumb', instance.thumb?.toJson()); + writeNotNull('thumbnail', instance.thumbnail?.toJson()); writeNotNull('file_name', instance.fileName); writeNotNull('mime_type', instance.mimeType); writeNotNull('file_size', instance.fileSize); @@ -51,9 +51,9 @@ Audio _$AudioFromJson(Map json) => Audio( fileName: json['file_name'] as String?, mimeType: json['mime_type'] as String?, fileSize: json['file_size'] as int?, - thumb: json['thumb'] == null + thumbnail: json['thumbnail'] == null ? null - : PhotoSize.fromJson(json['thumb'] as Map), + : PhotoSize.fromJson(json['thumbnail'] as Map), ); Map _$AudioToJson(Audio instance) { @@ -74,7 +74,7 @@ Map _$AudioToJson(Audio instance) { writeNotNull('file_name', instance.fileName); writeNotNull('mime_type', instance.mimeType); writeNotNull('file_size', instance.fileSize); - writeNotNull('thumb', instance.thumb?.toJson()); + writeNotNull('thumbnail', instance.thumbnail?.toJson()); return val; } @@ -216,6 +216,35 @@ Map _$BotCommandToJson(BotCommand instance) => 'description': instance.description, }; +BotDescription _$BotDescriptionFromJson(Map json) => + BotDescription( + description: json['description'] as String, + ); + +Map _$BotDescriptionToJson(BotDescription instance) => + { + 'description': instance.description, + }; + +BotName _$BotNameFromJson(Map json) => BotName( + name: json['name'] as String, + ); + +Map _$BotNameToJson(BotName instance) => { + 'name': instance.name, + }; + +BotShortDescription _$BotShortDescriptionFromJson(Map json) => + BotShortDescription( + shortDescription: json['short_description'] as String, + ); + +Map _$BotShortDescriptionToJson( + BotShortDescription instance) => + { + 'short_description': instance.shortDescription, + }; + CallbackGame _$CallbackGameFromJson(Map json) => CallbackGame(); @@ -337,6 +366,7 @@ 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 @@ -349,6 +379,7 @@ Map _$ChatJoinRequestToJson(ChatJoinRequest instance) { final val = { 'chat': instance.chat.toJson(), 'from': instance.from.toJson(), + 'user_chat_id': instance.userChatId, 'date': instance.date, }; @@ -499,7 +530,12 @@ ChatMemberRestricted _$ChatMemberRestrictedFromJson( canPinMessages: json['can_pin_messages'] as bool? ?? false, canManageTopics: json['can_manage_topics'] as bool? ?? false, canSendMessages: json['can_send_messages'] as bool? ?? false, - canSendMediaMessages: json['can_send_media_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: @@ -508,22 +544,36 @@ ChatMemberRestricted _$ChatMemberRestrictedFromJson( ); Map _$ChatMemberRestrictedToJson( - ChatMemberRestricted instance) => - { - '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, - 'can_send_media_messages': instance.canSendMediaMessages, - 'can_send_polls': instance.canSendPolls, - 'can_send_other_messages': instance.canSendOtherMessages, - 'can_add_web_page_previews': instance.canAddWebPagePreviews, - 'until_date': instance.untilDate, - }; + ChatMemberRestricted instance) { + final val = { + '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) { + if (value != null) { + val[key] = value; + } + } + + 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; +} ChatMemberUpdated _$ChatMemberUpdatedFromJson(Map json) => ChatMemberUpdated( @@ -545,7 +595,9 @@ ChatMemberUpdated _$ChatMemberUpdatedFromJson(Map json) => ? null : ChatInviteLink.fromJson( json['invite_link'] as Map), - )..date = json['date'] as int?; + viaChatFolderInviteLink: json['via_chat_folder_invite_link'] as bool?, + date: json['date'] as int?, + ); Map _$ChatMemberUpdatedToJson(ChatMemberUpdated instance) { final val = {}; @@ -562,6 +614,7 @@ Map _$ChatMemberUpdatedToJson(ChatMemberUpdated instance) { 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; } @@ -579,7 +632,12 @@ Map _$ChatMemberToJson(ChatMember instance) => ChatPermissions _$ChatPermissionsFromJson(Map json) => ChatPermissions( canSendMessages: json['can_send_messages'] as bool?, - canSendMediaMessages: json['can_send_media_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?, @@ -599,7 +657,12 @@ Map _$ChatPermissionsToJson(ChatPermissions instance) { } writeNotNull('can_send_messages', instance.canSendMessages); - writeNotNull('can_send_media_messages', instance.canSendMediaMessages); + 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); @@ -624,6 +687,17 @@ Map _$ChatPhotoToJson(ChatPhoto instance) => { 'big_file_unique_id': instance.bigFileUniqueId, }; +ChatShared _$ChatSharedFromJson(Map json) => ChatShared( + requestId: json['request_id'] as int, + userId: json['user_id'] as int, + ); + +Map _$ChatSharedToJson(ChatShared instance) => + { + 'request_id': instance.requestId, + 'user_id': instance.userId, + }; + Chat _$ChatFromJson(Map json) => Chat( id: json['id'] as int, type: json['type'] as String, @@ -639,6 +713,8 @@ Chat _$ChatFromJson(Map json) => Chat( ?.map((e) => e as String) .toList(), 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: @@ -689,6 +765,8 @@ Map _$ChatToJson(Chat instance) { 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', @@ -780,9 +858,9 @@ Map _$DiceToJson(Dice instance) => { Document _$DocumentFromJson(Map json) => Document( fileId: json['file_id'] as String, fileUniqueId: json['file_unique_id'] as String, - thumb: json['thumb'] == null + thumbnail: json['thumbnail'] == null ? null - : PhotoSize.fromJson(json['thumb'] 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?, @@ -800,7 +878,7 @@ Map _$DocumentToJson(Document instance) { } } - writeNotNull('thumb', instance.thumb?.toJson()); + writeNotNull('thumbnail', instance.thumbnail?.toJson()); writeNotNull('file_name', instance.fileName); writeNotNull('mime_type', instance.mimeType); writeNotNull('file_size', instance.fileSize); @@ -1083,6 +1161,11 @@ InlineKeyboardButton _$InlineKeyboardButtonFromJson( : 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 _$InlineKeyboardButtonToJson( @@ -1106,6 +1189,8 @@ Map _$InlineKeyboardButtonToJson( instance.switchInlineQueryCurrentChat); writeNotNull('callback_game', instance.callbackGame?.toJson()); writeNotNull('pay', instance.pay); + writeNotNull('switch_inline_query_chosen_chat', + instance.switchInlineQueryChosenChat?.toJson()); return val; } @@ -1143,9 +1228,9 @@ InlineQueryResultArticle _$InlineQueryResultArticleFromJson( url: json['url'] as String?, hideUrl: json['hide_url'] as bool?, description: json['description'] as String?, - thumbUrl: json['thumb_url'] as String?, - thumbWidth: json['thumb_width'] as String?, - thumbHeight: json['thumb_height'] as String?, + thumbnailUrl: json['thumbnail_url'] as String?, + thumbnailWidth: json['thumbnail_width'] as String?, + thumbnailHeight: json['thumbnail_height'] as String?, ); Map _$InlineQueryResultArticleToJson( @@ -1167,9 +1252,9 @@ Map _$InlineQueryResultArticleToJson( writeNotNull('url', instance.url); writeNotNull('hide_url', instance.hideUrl); writeNotNull('description', instance.description); - writeNotNull('thumb_url', instance.thumbUrl); - writeNotNull('thumb_width', instance.thumbWidth); - writeNotNull('thumb_height', instance.thumbHeight); + writeNotNull('thumbnail_url', instance.thumbnailUrl); + writeNotNull('thumbnail_width', instance.thumbnailWidth); + writeNotNull('thumbnail_height', instance.thumbnailHeight); return val; } @@ -1601,9 +1686,9 @@ InlineQueryResultContact _$InlineQueryResultContactFromJson( ? null : InputMessageContent.fromJson( json['input_message_content'] as Map), - thumbUrl: json['thumb_url'] as String?, - thumbWidth: json['thumb_width'] as int?, - thumbHeight: json['thumb_height'] as int?, + thumbnailUrl: json['thumbnail_url'] as String?, + thumbnailWidth: json['thumbnail_width'] as int?, + thumbnailHeight: json['thumbnail_height'] as int?, ); Map _$InlineQueryResultContactToJson( @@ -1625,9 +1710,9 @@ Map _$InlineQueryResultContactToJson( writeNotNull('vcard', instance.vcard); writeNotNull('reply_markup', instance.replyMarkup?.toJson()); writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); - writeNotNull('thumb_url', instance.thumbUrl); - writeNotNull('thumb_width', instance.thumbWidth); - writeNotNull('thumb_height', instance.thumbHeight); + writeNotNull('thumbnail_url', instance.thumbnailUrl); + writeNotNull('thumbnail_width', instance.thumbnailWidth); + writeNotNull('thumbnail_height', instance.thumbnailHeight); return val; } @@ -1653,9 +1738,9 @@ InlineQueryResultDocument _$InlineQueryResultDocumentFromJson( ? null : InputMessageContent.fromJson( json['input_message_content'] as Map), - thumbUrl: json['thumb_url'] as String?, - thumbWidth: json['thumb_width'] as int?, - thumbHeight: json['thumb_height'] as int?, + thumbnailUrl: json['thumbnail_url'] as String?, + thumbnailWidth: json['thumbnail_width'] as int?, + thumbnailHeight: json['thumbnail_height'] as int?, ); Map _$InlineQueryResultDocumentToJson( @@ -1681,9 +1766,9 @@ Map _$InlineQueryResultDocumentToJson( writeNotNull('description', instance.description); writeNotNull('reply_markup', instance.replyMarkup?.toJson()); writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); - writeNotNull('thumb_url', instance.thumbUrl); - writeNotNull('thumb_width', instance.thumbWidth); - writeNotNull('thumb_height', instance.thumbHeight); + writeNotNull('thumbnail_url', instance.thumbnailUrl); + writeNotNull('thumbnail_width', instance.thumbnailWidth); + writeNotNull('thumbnail_height', instance.thumbnailHeight); return val; } @@ -1726,8 +1811,8 @@ InlineQueryResultGif _$InlineQueryResultGifFromJson( gifWidth: json['gif_width'] as int?, gifHeight: json['gif_height'] as int?, gifDuration: json['gif_duration'] as int?, - thumbUrl: json['thumb_url'] as String, - thumbMimeType: json['thumb_mime_type'] as String?, + 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?, @@ -1761,8 +1846,8 @@ Map _$InlineQueryResultGifToJson( writeNotNull('gif_width', instance.gifWidth); writeNotNull('gif_height', instance.gifHeight); writeNotNull('gif_duration', instance.gifDuration); - val['thumb_url'] = instance.thumbUrl; - writeNotNull('thumb_mime_type', instance.thumbMimeType); + val['thumbnail_url'] = instance.thumbnailUrl; + writeNotNull('thumbnail_mime_type', instance.thumbnailMimeType); writeNotNull('title', instance.title); writeNotNull('caption', instance.caption); writeNotNull('parse_mode', instance.parseMode); @@ -1793,9 +1878,9 @@ InlineQueryResultLocation _$InlineQueryResultLocationFromJson( ? null : InputMessageContent.fromJson( json['input_message_content'] as Map), - thumbUrl: json['thumb_url'] as String?, - thumbWidth: json['thumb_width'] as int?, - thumbHeight: json['thumb_height'] as int?, + thumbnailUrl: json['thumbnail_url'] as String?, + thumbnailWidth: json['thumbnail_width'] as int?, + thumbnailHeight: json['thumbnail_height'] as int?, ); Map _$InlineQueryResultLocationToJson( @@ -1820,9 +1905,9 @@ Map _$InlineQueryResultLocationToJson( writeNotNull('proximity_alert_radius', instance.proximityAlertRadius); writeNotNull('reply_markup', instance.replyMarkup?.toJson()); writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); - writeNotNull('thumb_url', instance.thumbUrl); - writeNotNull('thumb_width', instance.thumbWidth); - writeNotNull('thumb_height', instance.thumbHeight); + writeNotNull('thumbnail_url', instance.thumbnailUrl); + writeNotNull('thumbnail_width', instance.thumbnailWidth); + writeNotNull('thumbnail_height', instance.thumbnailHeight); return val; } @@ -1835,8 +1920,8 @@ InlineQueryResultMpeg4Gif _$InlineQueryResultMpeg4GifFromJson( mpeg4Width: json['mpeg4_width'] as int?, mpeg4Height: json['mpeg4_height'] as int?, mpeg4Duration: json['mpeg4_duration'] as int?, - thumbUrl: json['thumb_url'] as String, - thumbMimeType: json['thumb_mime_type'] as String?, + 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?, @@ -1870,8 +1955,8 @@ Map _$InlineQueryResultMpeg4GifToJson( writeNotNull('mpeg4_width', instance.mpeg4Width); writeNotNull('mpeg4_height', instance.mpeg4Height); writeNotNull('mpeg4_duration', instance.mpeg4Duration); - val['thumb_url'] = instance.thumbUrl; - writeNotNull('thumb_mime_type', instance.thumbMimeType); + val['thumbnail_url'] = instance.thumbnailUrl; + writeNotNull('thumbnail_mime_type', instance.thumbnailMimeType); writeNotNull('title', instance.title); writeNotNull('caption', instance.caption); writeNotNull('parse_mode', instance.parseMode); @@ -1888,7 +1973,7 @@ InlineQueryResultPhoto _$InlineQueryResultPhotoFromJson( id: json['id'] as String, type: json['type'] as String? ?? InlineQueryResult.typePhoto, photoUrl: json['photo_url'] as String, - thumbUrl: json['thumb_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?, @@ -1914,7 +1999,7 @@ Map _$InlineQueryResultPhotoToJson( 'id': instance.id, 'type': instance.type, 'photo_url': instance.photoUrl, - 'thumb_url': instance.thumbUrl, + 'thumbnail_url': instance.thumbnailUrl, }; void writeNotNull(String key, dynamic value) { @@ -1957,9 +2042,9 @@ InlineQueryResultVenue _$InlineQueryResultVenueFromJson( ? null : InputMessageContent.fromJson( json['input_message_content'] as Map), - thumbUrl: json['thumb_url'] as String?, - thumbWidth: json['thumb_width'] as int?, - thumbHeight: json['thumb_height'] as int?, + thumbnailUrl: json['thumbnail_url'] as String?, + thumbnailWidth: json['thumbnail_width'] as int?, + thumbnailHeight: json['thumbnail_height'] as int?, ); Map _$InlineQueryResultVenueToJson( @@ -1985,9 +2070,9 @@ Map _$InlineQueryResultVenueToJson( writeNotNull('google_place_type', instance.googlePlaceType); writeNotNull('reply_markup', instance.replyMarkup?.toJson()); writeNotNull('input_message_content', instance.inputMessageContent?.toJson()); - writeNotNull('thumb_url', instance.thumbUrl); - writeNotNull('thumb_width', instance.thumbWidth); - writeNotNull('thumb_height', instance.thumbHeight); + writeNotNull('thumbnail_url', instance.thumbnailUrl); + writeNotNull('thumbnail_width', instance.thumbnailWidth); + writeNotNull('thumbnail_height', instance.thumbnailHeight); return val; } @@ -1998,7 +2083,7 @@ InlineQueryResultVideo _$InlineQueryResultVideoFromJson( type: json['type'] as String? ?? InlineQueryResult.typeVideo, videoUrl: json['video_url'] as String, mimeType: json['mime_type'] as String, - thumbUrl: json['thumb_url'] as String, + thumbnailUrl: json['thumbnail_url'] as String, title: json['title'] as String, caption: json['caption'] as String?, parseMode: json['parse_mode'] as String?, @@ -2026,7 +2111,7 @@ Map _$InlineQueryResultVideoToJson( 'type': instance.type, 'video_url': instance.videoUrl, 'mime_type': instance.mimeType, - 'thumb_url': instance.thumbUrl, + 'thumbnail_url': instance.thumbnailUrl, 'title': instance.title, }; @@ -2123,6 +2208,33 @@ Map _$InlineQueryResultToJson(InlineQueryResult instance) { return val; } +InlineQueryResultsButton _$InlineQueryResultsButtonFromJson( + Map json) => + InlineQueryResultsButton( + text: json['text'] as String, + webApp: json['web_app'] == null + ? null + : WebAppInfo.fromJson(json['web_app'] as Map), + startParameter: json['start_parameter'] as String?, + ); + +Map _$InlineQueryResultsButtonToJson( + InlineQueryResultsButton instance) { + final val = { + 'text': instance.text, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('web_app', instance.webApp?.toJson()); + writeNotNull('start_parameter', instance.startParameter); + return val; +} + InlineQuery _$InlineQueryFromJson(Map json) => InlineQuery( id: json['id'] as String, from: User.fromJson(json['from'] as Map), @@ -2278,7 +2390,7 @@ InputMediaAnimation _$InputMediaAnimationFromJson(Map json) => InputMediaAnimation( type: json['type'] as String? ?? InputMedia.typeAnimation, media: json['media'] as String, - thumb: json['thumb'], + thumbnail: json['thumbnail'] as String?, caption: json['caption'] as String?, parseMode: json['parse_mode'] as String?, captionEntities: (json['caption_entities'] as List?) @@ -2306,7 +2418,7 @@ Map _$InputMediaAnimationToJson(InputMediaAnimation instance) { writeNotNull('parse_mode', instance.parseMode); writeNotNull('caption_entities', instance.captionEntities?.map((e) => e.toJson()).toList()); - writeNotNull('thumb', instance.thumb); + writeNotNull('thumbnail', instance.thumbnail); writeNotNull('width', instance.width); writeNotNull('height', instance.height); writeNotNull('duration', instance.duration); @@ -2318,7 +2430,7 @@ InputMediaAudio _$InputMediaAudioFromJson(Map json) => InputMediaAudio( type: json['type'] as String? ?? InputMedia.typeAudio, media: json['media'] as String, - thumb: json['thumb'], + thumbnail: json['thumbnail'] as String?, caption: json['caption'] as String?, parseMode: json['parse_mode'] as String?, captionEntities: (json['caption_entities'] as List?) @@ -2345,7 +2457,7 @@ Map _$InputMediaAudioToJson(InputMediaAudio instance) { writeNotNull('parse_mode', instance.parseMode); writeNotNull('caption_entities', instance.captionEntities?.map((e) => e.toJson()).toList()); - writeNotNull('thumb', instance.thumb); + writeNotNull('thumbnail', instance.thumbnail); writeNotNull('duration', instance.duration); writeNotNull('performer', instance.performer); writeNotNull('title', instance.title); @@ -2356,7 +2468,7 @@ InputMediaDocument _$InputMediaDocumentFromJson(Map json) => InputMediaDocument( type: json['type'] as String? ?? InputMedia.typeDocument, media: json['media'] as String, - thumb: json['thumb'], + thumbnail: json['thumbnail'] as String?, caption: json['caption'] as String?, parseMode: json['parse_mode'] as String?, captionEntities: (json['caption_entities'] as List?) @@ -2382,7 +2494,7 @@ Map _$InputMediaDocumentToJson(InputMediaDocument instance) { writeNotNull('parse_mode', instance.parseMode); writeNotNull('caption_entities', instance.captionEntities?.map((e) => e.toJson()).toList()); - writeNotNull('thumb', instance.thumb); + writeNotNull('thumbnail', instance.thumbnail); writeNotNull( 'disable_content_type_detection', instance.disableContentTypeDetection); return val; @@ -2429,7 +2541,7 @@ InputMediaVideo _$InputMediaVideoFromJson(Map json) => captionEntities: (json['caption_entities'] as List?) ?.map((e) => MessageEntity.fromJson(e as Map)) .toList(), - thumb: json['thumb'], + thumbnail: json['thumbnail'] as String?, width: json['width'] as int?, height: json['height'] as int?, duration: json['duration'] as int?, @@ -2453,7 +2565,7 @@ Map _$InputMediaVideoToJson(InputMediaVideo instance) { writeNotNull('parse_mode', instance.parseMode); writeNotNull('caption_entities', instance.captionEntities?.map((e) => e.toJson()).toList()); - writeNotNull('thumb', instance.thumb); + writeNotNull('thumbnail', instance.thumbnail); writeNotNull('width', instance.width); writeNotNull('height', instance.height); writeNotNull('duration', instance.duration); @@ -2462,6 +2574,40 @@ Map _$InputMediaVideoToJson(InputMediaVideo instance) { return val; } +InputMediaWithThumbnail _$InputMediaWithThumbnailFromJson( + Map json) => + InputMediaWithThumbnail( + type: json['type'] as String, + 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(), + ); + +Map _$InputMediaWithThumbnailToJson( + InputMediaWithThumbnail instance) { + final val = { + 'type': instance.type, + 'media': instance.media, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('caption', instance.caption); + writeNotNull('parse_mode', instance.parseMode); + writeNotNull('caption_entities', + instance.captionEntities?.map((e) => e.toJson()).toList()); + writeNotNull('thumbnail', instance.thumbnail); + return val; +} + InputMedia _$InputMediaFromJson(Map json) => InputMedia( type: json['type'] as String, media: json['media'] as String, @@ -2498,6 +2644,37 @@ 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(), + maskPosition: json['mask_position'] == null + ? null + : MaskPosition.fromJson( + json['mask_position'] as Map), + keywords: (json['keywords'] as List?) + ?.map((e) => e as String) + .toList(), + ); + +Map _$InputStickerToJson(InputSticker instance) { + final val = { + 'sticker': instance.sticker, + 'emoji_list': instance.emojiList, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('mask_position', instance.maskPosition?.toJson()); + writeNotNull('keywords', instance.keywords); + return val; +} + InputTextMessageContent _$InputTextMessageContentFromJson( Map json) => InputTextMessageContent( @@ -2597,9 +2774,81 @@ Map _$KeyboardButtonPollTypeToJson( return val; } +KeyboardButtonRequestChat _$KeyboardButtonRequestChatFromJson( + Map json) => + 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 _$KeyboardButtonRequestChatToJson( + KeyboardButtonRequestChat instance) { + final val = { + 'request_id': instance.requestId, + 'chat_is_channel': instance.chatIsChannel, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + 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; +} + +KeyboardButtonRequestUser _$KeyboardButtonRequestUserFromJson( + Map json) => + KeyboardButtonRequestUser( + requestId: json['request_id'] as int, + userIsBot: json['user_is_bot'] as bool?, + userIsPremium: json['user_is_premium'] as bool?, + ); + +Map _$KeyboardButtonRequestUserToJson( + KeyboardButtonRequestUser instance) { + final val = { + 'request_id': instance.requestId, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('user_is_bot', instance.userIsBot); + writeNotNull('user_is_premium', instance.userIsPremium); + return val; +} + KeyboardButton _$KeyboardButtonFromJson(Map json) => KeyboardButton( text: json['text'] as String, + requestUser: json['request_user'] == null + ? null + : KeyboardButtonRequestUser.fromJson( + json['request_user'] as Map), requestContact: json['request_contact'] as bool?, requestLocation: json['request_location'] as bool?, requestPoll: json['request_poll'] == null @@ -2609,7 +2858,10 @@ KeyboardButton _$KeyboardButtonFromJson(Map json) => 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 _$KeyboardButtonToJson(KeyboardButton instance) { final val = { @@ -2622,6 +2874,8 @@ Map _$KeyboardButtonToJson(KeyboardButton instance) { } } + 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()); @@ -2855,6 +3109,9 @@ Message _$MessageFromJson(Map json) => Message( 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), @@ -2919,6 +3176,12 @@ Message _$MessageFromJson(Map json) => Message( ? 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 @@ -3019,6 +3282,7 @@ Map _$MessageToJson(Message instance) { 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()); @@ -3049,6 +3313,8 @@ Map _$MessageToJson(Message instance) { 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()); @@ -3340,17 +3606,32 @@ Map _$PhotoSizeToJson(PhotoSize instance) { PollAnswer _$PollAnswerFromJson(Map json) => PollAnswer( pollId: json['poll_id'] as String, - user: User.fromJson(json['user'] as Map), + 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) => - { - 'poll_id': instance.pollId, - 'user': instance.user.toJson(), - 'option_ids': instance.optionIds, - }; +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, @@ -3677,9 +3958,9 @@ StickerSet _$StickerSetFromJson(Map json) => StickerSet( stickers: (json['stickers'] as List) .map((e) => Sticker.fromJson(e as Map)) .toList(), - thumb: json['thumb'] == null + thumbnail: json['thumbnail'] == null ? null - : PhotoSize.fromJson(json['thumb'] as Map), + : PhotoSize.fromJson(json['thumbnail'] as Map), ); Map _$StickerSetToJson(StickerSet instance) { @@ -3698,7 +3979,7 @@ Map _$StickerSetToJson(StickerSet instance) { } } - writeNotNull('thumb', instance.thumb?.toJson()); + writeNotNull('thumbnail', instance.thumbnail?.toJson()); return val; } @@ -3709,9 +3990,9 @@ Sticker _$StickerFromJson(Map json) => Sticker( height: json['height'] as int, isAnimated: json['is_animated'] as bool, isVideo: json['is_video'] as bool, - thumb: json['thumb'] == null + thumbnail: json['thumbnail'] == null ? null - : PhotoSize.fromJson(json['thumb'] as Map), + : PhotoSize.fromJson(json['thumbnail'] as Map), emoji: json['emoji'] as String?, setName: json['set_name'] as String?, premiumAnimation: json['premium_animation'] == null @@ -3722,6 +4003,7 @@ Sticker _$StickerFromJson(Map json) => Sticker( : 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?, ); @@ -3741,16 +4023,21 @@ Map _$StickerToJson(Sticker instance) { } } - writeNotNull('thumb', instance.thumb?.toJson()); + 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, @@ -3784,6 +4071,34 @@ Map _$SuccessfulPaymentToJson(SuccessfulPayment instance) { 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 @@ -3884,6 +4199,17 @@ Map _$UserProfilePhotosToJson(UserProfilePhotos instance) => .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, @@ -3957,9 +4283,9 @@ VideoNote _$VideoNoteFromJson(Map json) => VideoNote( fileUniqueId: json['file_unique_id'] as String, length: json['length'] as int, duration: json['duration'] as int, - thumb: json['thumb'] == null + thumbnail: json['thumbnail'] == null ? null - : PhotoSize.fromJson(json['thumb'] as Map), + : PhotoSize.fromJson(json['thumbnail'] as Map), fileSize: json['file_size'] as int?, ); @@ -3977,7 +4303,7 @@ Map _$VideoNoteToJson(VideoNote instance) { } } - writeNotNull('thumb', instance.thumb?.toJson()); + writeNotNull('thumbnail', instance.thumbnail?.toJson()); writeNotNull('file_size', instance.fileSize); return val; } @@ -3988,9 +4314,9 @@ Video _$VideoFromJson(Map json) => Video( width: json['width'] as int, height: json['height'] as int, duration: json['duration'] as int, - thumb: json['thumb'] == null + thumbnail: json['thumbnail'] == null ? null - : PhotoSize.fromJson(json['thumb'] 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?, @@ -4011,7 +4337,7 @@ Map _$VideoToJson(Video instance) { } } - writeNotNull('thumb', instance.thumb?.toJson()); + writeNotNull('thumbnail', instance.thumbnail?.toJson()); writeNotNull('file_name', instance.fileName); writeNotNull('mime_type', instance.mimeType); writeNotNull('file_size', instance.fileSize); @@ -4151,7 +4477,19 @@ Map _$WebhookInfoToJson(WebhookInfo instance) { } WriteAccessAllowed _$WriteAccessAllowedFromJson(Map json) => - WriteAccessAllowed(); + WriteAccessAllowed( + webAppName: json['web_app_name'] as String?, + ); -Map _$WriteAccessAllowedToJson(WriteAccessAllowed instance) => - {}; +Map _$WriteAccessAllowedToJson(WriteAccessAllowed instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + 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 d8704be..567207a 100644 --- a/lib/src/telegram/models/animation.dart +++ b/lib/src/telegram/models/animation.dart @@ -28,7 +28,7 @@ class Animation { int width; int height; int duration; - PhotoSize? thumb; + PhotoSize? thumbnail; String? fileName; String? mimeType; int? fileSize; @@ -39,7 +39,7 @@ class Animation { required this.width, required this.height, required this.duration, - this.thumb, + this.thumbnail, this.fileName, this.mimeType, this.fileSize, diff --git a/lib/src/telegram/models/audio.dart b/lib/src/telegram/models/audio.dart index cca2058..bc1c3a5 100644 --- a/lib/src/telegram/models/audio.dart +++ b/lib/src/telegram/models/audio.dart @@ -31,7 +31,7 @@ class Audio { String? fileName; String? mimeType; int? fileSize; - PhotoSize? thumb; + PhotoSize? thumbnail; Audio({ required this.fileId, @@ -42,7 +42,7 @@ class Audio { this.fileName, this.mimeType, this.fileSize, - this.thumb, + this.thumbnail, }); @JsonKey(includeFromJson: false, includeToJson: false) diff --git a/lib/src/telegram/models/bot_description.dart b/lib/src/telegram/models/bot_description.dart new file mode 100644 index 0000000..4ac2c27 --- /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 0000000..8352c92 --- /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 0000000..f1eb799 --- /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/chat.dart b/lib/src/telegram/models/chat.dart index f42984a..6defc24 100644 --- a/lib/src/telegram/models/chat.dart +++ b/lib/src/telegram/models/chat.dart @@ -38,6 +38,7 @@ class Chat { ChatPhoto? photo; List? activeUsernames; String? emojiStatusCustomEmojiId; + String? emojiStatusExpirationDate; String? bio; bool? hasPrivateForwards; bool? hasRestrictedVoiceAndVideoMessages; @@ -68,6 +69,7 @@ class Chat { this.photo, this.activeUsernames, this.emojiStatusCustomEmojiId, + this.emojiStatusExpirationDate, this.bio, this.hasPrivateForwards, this.hasRestrictedVoiceAndVideoMessages, diff --git a/lib/src/telegram/models/chat_join_request.dart b/lib/src/telegram/models/chat_join_request.dart index c1c57de..9847aa4 100644 --- a/lib/src/telegram/models/chat_join_request.dart +++ b/lib/src/telegram/models/chat_join_request.dart @@ -25,6 +25,7 @@ part of '../model.dart'; class ChatJoinRequest { Chat chat; User from; + int userChatId; int date; String? bio; ChatInviteLink? inviteLink; @@ -32,6 +33,7 @@ class ChatJoinRequest { ChatJoinRequest({ required this.chat, required this.from, + required this.userChatId, required this.date, this.bio, this.inviteLink, diff --git a/lib/src/telegram/models/chat_member_restricted.dart b/lib/src/telegram/models/chat_member_restricted.dart index 29a32e4..908e7e2 100644 --- a/lib/src/telegram/models/chat_member_restricted.dart +++ b/lib/src/telegram/models/chat_member_restricted.dart @@ -36,7 +36,12 @@ class ChatMemberRestricted implements ChatMember { bool canPinMessages; bool canManageTopics; bool canSendMessages; - bool canSendMediaMessages; + bool? canSendAudios; + bool? canSendDocuments; + bool? canSendPhotos; + bool? canSendVideos; + bool? canSendVideoNotes; + bool? canSendVoiceNotes; bool canSendPolls; bool canSendOtherMessages; bool canAddWebPagePreviews; @@ -51,7 +56,12 @@ class ChatMemberRestricted implements ChatMember { this.canPinMessages = false, this.canManageTopics = false, this.canSendMessages = false, - this.canSendMediaMessages = 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, diff --git a/lib/src/telegram/models/chat_member_updated.dart b/lib/src/telegram/models/chat_member_updated.dart index 94d7809..e6fb931 100644 --- a/lib/src/telegram/models/chat_member_updated.dart +++ b/lib/src/telegram/models/chat_member_updated.dart @@ -29,6 +29,7 @@ class ChatMemberUpdated { ChatMember? oldChatMember; ChatMember? newChatMember; ChatInviteLink? inviteLink; + bool? viaChatFolderInviteLink; ChatMemberUpdated({ this.chat, @@ -36,6 +37,8 @@ class ChatMemberUpdated { this.oldChatMember, this.newChatMember, this.inviteLink, + this.viaChatFolderInviteLink, + this.date, }); @JsonKey(includeFromJson: false, includeToJson: false) diff --git a/lib/src/telegram/models/chat_permissions.dart b/lib/src/telegram/models/chat_permissions.dart index 0e29c35..92f7501 100644 --- a/lib/src/telegram/models/chat_permissions.dart +++ b/lib/src/telegram/models/chat_permissions.dart @@ -16,6 +16,8 @@ * 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. @@ -24,7 +26,12 @@ part of '../model.dart'; @JsonSerializable(fieldRename: FieldRename.snake) class ChatPermissions { bool? canSendMessages; - bool? canSendMediaMessages; + bool? canSendAudios; + bool? canSendDocuments; + bool? canSendPhotos; + bool? canSendVideos; + bool? canSendVideoNotes; + bool? canSendVoiceNotes; bool? canSendPolls; bool? canSendOtherMessages; bool? canAddWebPagePreviews; @@ -35,7 +42,12 @@ class ChatPermissions { ChatPermissions({ this.canSendMessages, - this.canSendMediaMessages, + this.canSendAudios, + this.canSendDocuments, + this.canSendPhotos, + this.canSendVideos, + this.canSendVideoNotes, + this.canSendVoiceNotes, this.canSendPolls, this.canSendOtherMessages, this.canAddWebPagePreviews, diff --git a/lib/src/telegram/models/chat_shared.dart b/lib/src/telegram/models/chat_shared.dart new file mode 100644 index 0000000..324de73 --- /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/document.dart b/lib/src/telegram/models/document.dart index 5992fdc..f31d55d 100644 --- a/lib/src/telegram/models/document.dart +++ b/lib/src/telegram/models/document.dart @@ -29,14 +29,14 @@ part of '../model.dart'; class Document { String fileId; String fileUniqueId; - PhotoSize? thumb; + PhotoSize? thumbnail; String? fileName; String? mimeType; int? fileSize; Document({ required this.fileId, required this.fileUniqueId, - this.thumb, + this.thumbnail, this.fileName, this.mimeType, this.fileSize, diff --git a/lib/src/telegram/models/inline_keyboard_button.dart b/lib/src/telegram/models/inline_keyboard_button.dart index 53c1357..7147698 100644 --- a/lib/src/telegram/models/inline_keyboard_button.dart +++ b/lib/src/telegram/models/inline_keyboard_button.dart @@ -34,6 +34,7 @@ class InlineKeyboardButton { String? switchInlineQueryCurrentChat; CallbackGame? callbackGame; bool? pay; + SwitchInlineQueryChosenChat? switchInlineQueryChosenChat; InlineKeyboardButton({ required this.text, this.url, @@ -44,6 +45,7 @@ class InlineKeyboardButton { this.switchInlineQueryCurrentChat, this.callbackGame, this.pay, + this.switchInlineQueryChosenChat, }); factory InlineKeyboardButton.fromJson(Map json) => _$InlineKeyboardButtonFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_article.dart b/lib/src/telegram/models/inline_query_result_article.dart index 39eb73f..daf4776 100644 --- a/lib/src/telegram/models/inline_query_result_article.dart +++ b/lib/src/telegram/models/inline_query_result_article.dart @@ -34,9 +34,9 @@ class InlineQueryResultArticle implements InlineQueryResult { String? url; bool? hideUrl; String? description; - String? thumbUrl; - String? thumbWidth; - String? thumbHeight; + String? thumbnailUrl; + String? thumbnailWidth; + String? thumbnailHeight; InlineQueryResultArticle({ required this.id, this.type = InlineQueryResult.typeArticle, @@ -46,9 +46,9 @@ class InlineQueryResultArticle implements InlineQueryResult { this.url, this.hideUrl, this.description, - this.thumbUrl, - this.thumbWidth, - this.thumbHeight, + this.thumbnailUrl, + this.thumbnailWidth, + this.thumbnailHeight, }); factory InlineQueryResultArticle.fromJson(Map json) => _$InlineQueryResultArticleFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_contact.dart b/lib/src/telegram/models/inline_query_result_contact.dart index 3e5ce2a..5b1154f 100644 --- a/lib/src/telegram/models/inline_query_result_contact.dart +++ b/lib/src/telegram/models/inline_query_result_contact.dart @@ -41,9 +41,9 @@ class InlineQueryResultContact implements InlineQueryResult { @override InlineKeyboardMarkup? replyMarkup; InputMessageContent? inputMessageContent; - String? thumbUrl; - int? thumbWidth; - int? thumbHeight; + String? thumbnailUrl; + int? thumbnailWidth; + int? thumbnailHeight; InlineQueryResultContact({ required this.id, this.type = InlineQueryResult.typeContact, @@ -53,9 +53,9 @@ class InlineQueryResultContact implements InlineQueryResult { this.vcard, this.replyMarkup, this.inputMessageContent, - this.thumbUrl, - this.thumbWidth, - this.thumbHeight, + 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 a1a931a..9d93372 100644 --- a/lib/src/telegram/models/inline_query_result_document.dart +++ b/lib/src/telegram/models/inline_query_result_document.dart @@ -44,9 +44,9 @@ class InlineQueryResultDocument implements InlineQueryResult { @override InlineKeyboardMarkup? replyMarkup; InputMessageContent? inputMessageContent; - String? thumbUrl; - int? thumbWidth; - int? thumbHeight; + String? thumbnailUrl; + int? thumbnailWidth; + int? thumbnailHeight; InlineQueryResultDocument({ required this.id, this.type = InlineQueryResult.typeDocument, @@ -59,9 +59,9 @@ class InlineQueryResultDocument implements InlineQueryResult { this.description, this.replyMarkup, this.inputMessageContent, - this.thumbUrl, - this.thumbWidth, - this.thumbHeight, + this.thumbnailUrl, + this.thumbnailWidth, + this.thumbnailHeight, }); factory InlineQueryResultDocument.fromJson(Map json) => _$InlineQueryResultDocumentFromJson(json); diff --git a/lib/src/telegram/models/inline_query_result_gif.dart b/lib/src/telegram/models/inline_query_result_gif.dart index 833c49a..af67983 100644 --- a/lib/src/telegram/models/inline_query_result_gif.dart +++ b/lib/src/telegram/models/inline_query_result_gif.dart @@ -34,8 +34,8 @@ class InlineQueryResultGif implements InlineQueryResult { int? gifWidth; int? gifHeight; int? gifDuration; - String thumbUrl; - String? thumbMimeType; + String thumbnailUrl; + String? thumbnailMimeType; String? title; String? caption; String? parseMode; @@ -51,8 +51,8 @@ class InlineQueryResultGif implements InlineQueryResult { this.gifWidth, this.gifHeight, this.gifDuration, - required this.thumbUrl, - this.thumbMimeType, + required this.thumbnailUrl, + this.thumbnailMimeType, this.title, this.caption, this.parseMode, diff --git a/lib/src/telegram/models/inline_query_result_location.dart b/lib/src/telegram/models/inline_query_result_location.dart index 55cba06..7ba8cf5 100644 --- a/lib/src/telegram/models/inline_query_result_location.dart +++ b/lib/src/telegram/models/inline_query_result_location.dart @@ -43,9 +43,9 @@ class InlineQueryResultLocation implements InlineQueryResult { @override InlineKeyboardMarkup? replyMarkup; InputMessageContent? inputMessageContent; - String? thumbUrl; - int? thumbWidth; - int? thumbHeight; + String? thumbnailUrl; + int? thumbnailWidth; + int? thumbnailHeight; InlineQueryResultLocation({ required this.id, @@ -59,9 +59,9 @@ class InlineQueryResultLocation implements InlineQueryResult { this.proximityAlertRadius, this.replyMarkup, this.inputMessageContent, - this.thumbUrl, - this.thumbWidth, - this.thumbHeight, + this.thumbnailUrl, + this.thumbnailWidth, + this.thumbnailHeight, }); @JsonKey(includeFromJson: false, includeToJson: false) 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 f7616ec..c1dab90 100644 --- a/lib/src/telegram/models/inline_query_result_mpeg4_gif.dart +++ b/lib/src/telegram/models/inline_query_result_mpeg4_gif.dart @@ -35,8 +35,8 @@ class InlineQueryResultMpeg4Gif implements InlineQueryResult { int? mpeg4Width; int? mpeg4Height; int? mpeg4Duration; - String thumbUrl; - String? thumbMimeType; + String thumbnailUrl; + String? thumbnailMimeType; String? title; String? caption; String? parseMode; @@ -52,8 +52,8 @@ class InlineQueryResultMpeg4Gif implements InlineQueryResult { this.mpeg4Width, this.mpeg4Height, this.mpeg4Duration, - required this.thumbUrl, - this.thumbMimeType, + required this.thumbnailUrl, + this.thumbnailMimeType, this.title, this.caption, this.parseMode, diff --git a/lib/src/telegram/models/inline_query_result_photo.dart b/lib/src/telegram/models/inline_query_result_photo.dart index cfa8bd9..36e45c3 100644 --- a/lib/src/telegram/models/inline_query_result_photo.dart +++ b/lib/src/telegram/models/inline_query_result_photo.dart @@ -32,7 +32,7 @@ class InlineQueryResultPhoto implements InlineQueryResult { @override String type; String photoUrl; - String thumbUrl; + String thumbnailUrl; int? photoWidth; int? photoHeight; String? title; @@ -47,7 +47,7 @@ class InlineQueryResultPhoto implements InlineQueryResult { required this.id, this.type = InlineQueryResult.typePhoto, required this.photoUrl, - required this.thumbUrl, + required this.thumbnailUrl, this.photoWidth, this.photoHeight, this.title, diff --git a/lib/src/telegram/models/inline_query_result_venue.dart b/lib/src/telegram/models/inline_query_result_venue.dart index 6237042..cc40229 100644 --- a/lib/src/telegram/models/inline_query_result_venue.dart +++ b/lib/src/telegram/models/inline_query_result_venue.dart @@ -45,9 +45,9 @@ class InlineQueryResultVenue implements InlineQueryResult { @override InlineKeyboardMarkup? replyMarkup; InputMessageContent? inputMessageContent; - String? thumbUrl; - int? thumbWidth; - int? thumbHeight; + String? thumbnailUrl; + int? thumbnailWidth; + int? thumbnailHeight; InlineQueryResultVenue({ required this.id, this.type = InlineQueryResult.typeVenue, @@ -61,9 +61,9 @@ class InlineQueryResultVenue implements InlineQueryResult { this.googlePlaceType, this.replyMarkup, this.inputMessageContent, - this.thumbUrl, - this.thumbWidth, - this.thumbHeight, + 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 a90b8a2..66d2179 100644 --- a/lib/src/telegram/models/inline_query_result_video.dart +++ b/lib/src/telegram/models/inline_query_result_video.dart @@ -36,7 +36,7 @@ class InlineQueryResultVideo implements InlineQueryResult { String type; String videoUrl; String mimeType; - String thumbUrl; + String thumbnailUrl; String title; String? caption; String? parseMode; @@ -54,7 +54,7 @@ class InlineQueryResultVideo implements InlineQueryResult { this.type = InlineQueryResult.typeVideo, required this.videoUrl, required this.mimeType, - required this.thumbUrl, + required this.thumbnailUrl, required this.title, this.caption, this.parseMode, 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 0000000..261523c --- /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_media.dart b/lib/src/telegram/models/input_media.dart index 36d0cac..a1960fd 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 @@ -42,12 +42,16 @@ class InputMedia { String? parseMode; List? captionEntities; + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? mediaFile; + InputMedia({ required this.type, required this.media, this.caption, 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 b5ef95b..98eff42 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 @@ -22,7 +22,7 @@ part of '../model.dart'; /// /// https://core.telegram.org/bots/api#inputmediaanimation @JsonSerializable(fieldRename: FieldRename.snake) -class InputMediaAnimation implements InputMedia { +class InputMediaAnimation implements InputMediaWithThumbnail { @override String type; @override @@ -33,23 +33,113 @@ class InputMediaAnimation implements InputMedia { String? parseMode; @override List? captionEntities; - dynamic thumb; // InputFile or String + @override + String? thumbnail; int? width; int? height; int? duration; bool? hasSpoiler; - InputMediaAnimation( - {this.type = InputMedia.typeAnimation, - required this.media, - this.thumb, - this.caption, - this.parseMode, - this.captionEntities, - this.width, - this.height, - this.duration, - this.hasSpoiler}); + @override + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? mediaFile; + @override + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? thumbnailFile; + + InputMediaAnimation({ + this.type = InputMedia.typeAnimation, + required this.media, + this.thumbnail, + this.caption, + this.parseMode, + this.captionEntities, + this.width, + this.height, + this.duration, + this.hasSpoiler, + }); + + // 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_ => diff --git a/lib/src/telegram/models/input_media_audio.dart b/lib/src/telegram/models/input_media_audio.dart index be8d6d7..f934110 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 @@ -22,7 +22,7 @@ part of '../model.dart'; /// /// https://core.telegram.org/bots/api#inputmediaaudio @JsonSerializable(fieldRename: FieldRename.snake) -class InputMediaAudio implements InputMedia { +class InputMediaAudio implements InputMediaWithThumbnail { @override String type; @override @@ -33,15 +33,23 @@ class InputMediaAudio implements InputMedia { String? parseMode; @override List? captionEntities; - dynamic thumb; // InputFile or String + @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.typeAudio, required this.media, - this.thumb, + this.thumbnail, this.caption, this.parseMode, this.captionEntities, @@ -50,6 +58,81 @@ class InputMediaAudio implements InputMedia { this.title, }); + // 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!); diff --git a/lib/src/telegram/models/input_media_document.dart b/lib/src/telegram/models/input_media_document.dart index 4e50262..ac5c5d5 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 @@ -22,7 +22,7 @@ part of '../model.dart'; /// /// https://core.telegram.org/bots/api#inputmediadocument @JsonSerializable(fieldRename: FieldRename.snake) -class InputMediaDocument implements InputMedia { +class InputMediaDocument implements InputMediaWithThumbnail { @override String type; @override @@ -33,17 +33,91 @@ class InputMediaDocument implements InputMedia { String? parseMode; @override List? captionEntities; - dynamic thumb; // InputFile or String + @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.typeDocument, required this.media, - this.thumb, + this.thumbnail, this.caption, 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 08be881..c211968 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 @@ -34,6 +34,11 @@ class InputMediaPhoto implements InputMedia { @override List? captionEntities; bool? hasSpoiler; + + @override + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? mediaFile; + InputMediaPhoto({ this.type = InputMedia.typePhoto, required this.media, @@ -42,6 +47,24 @@ class InputMediaPhoto implements InputMedia { 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 018aee4..2448bc6 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 @@ -22,7 +22,7 @@ part of '../model.dart'; /// /// https://core.telegram.org/bots/api#inputmediavideo @JsonSerializable(fieldRename: FieldRename.snake) -class InputMediaVideo implements InputMedia { +class InputMediaVideo implements InputMediaWithThumbnail { @override String type; @override @@ -33,20 +33,28 @@ class InputMediaVideo implements InputMedia { String? parseMode; @override List? captionEntities; - dynamic thumb; // InputFile or String + @override + String? thumbnail; int? width; int? height; int? duration; bool? supportsStreaming; bool? hasSpoiler; + @override + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? mediaFile; + @override + @JsonKey(includeFromJson: false, includeToJson: false) + MultipartFile? thumbnailFile; + InputMediaVideo({ this.type = InputMedia.typeVideo, required this.media, this.caption, this.parseMode, this.captionEntities, - this.thumb, + this.thumbnail, this.width, this.height, this.duration, @@ -54,6 +62,94 @@ class InputMediaVideo implements InputMedia { this.hasSpoiler, }); + // 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!); 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 0000000..806bc6e --- /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_sticker.dart b/lib/src/telegram/models/input_sticker.dart new file mode 100644 index 0000000..211db50 --- /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/keyboard_button.dart b/lib/src/telegram/models/keyboard_button.dart index 7b10b8f..b825df7 100644 --- a/lib/src/telegram/models/keyboard_button.dart +++ b/lib/src/telegram/models/keyboard_button.dart @@ -31,12 +31,15 @@ part of '../model.dart'; @JsonSerializable(fieldRename: FieldRename.snake) class KeyboardButton { String text; + KeyboardButtonRequestUser? requestUser; + KeyboardButtonRequestChat? requestChat; bool? requestContact; bool? requestLocation; KeyboardButtonPollType? requestPoll; WebAppInfo? webApp; KeyboardButton({ required this.text, + this.requestUser, this.requestContact, this.requestLocation, this.requestPoll, 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 0000000..0af563f --- /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 0000000..ba9b15d --- /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/message.dart b/lib/src/telegram/models/message.dart index 7776498..16c1506 100644 --- a/lib/src/telegram/models/message.dart +++ b/lib/src/telegram/models/message.dart @@ -50,6 +50,7 @@ class Message { Document? document; List? photo; Sticker? sticker; + Story? story; Video? video; VideoNote? videoNote; Voice? voice; @@ -76,6 +77,8 @@ class Message { Message? pinnedMessage; Invoice? invoice; SuccessfulPayment? successfulPayment; + UserShared? userShared; + ChatShared? chatShared; String? connectedWebsite; WriteAccessAllowed? writeAccessAllowed; PassportData? passportData; @@ -121,6 +124,7 @@ class Message { this.document, this.photo, this.sticker, + this.story, this.video, this.videoNote, this.voice, @@ -147,6 +151,8 @@ class Message { this.pinnedMessage, this.invoice, this.successfulPayment, + this.userShared, + this.chatShared, this.connectedWebsite, this.writeAccessAllowed, this.passportData, diff --git a/lib/src/telegram/models/poll_answer.dart b/lib/src/telegram/models/poll_answer.dart index a628ff4..f2e68cd 100644 --- a/lib/src/telegram/models/poll_answer.dart +++ b/lib/src/telegram/models/poll_answer.dart @@ -24,11 +24,13 @@ part of '../model.dart'; @JsonSerializable(fieldRename: FieldRename.snake) class PollAnswer { String pollId; - User user; + Chat? voterChat; + User? user; List optionIds; PollAnswer({ required this.pollId, - required this.user, + this.voterChat, + this.user, required this.optionIds, }); factory PollAnswer.fromJson(Map json) => diff --git a/lib/src/telegram/models/sticker.dart b/lib/src/telegram/models/sticker.dart index 73f2afd..30d4a96 100644 --- a/lib/src/telegram/models/sticker.dart +++ b/lib/src/telegram/models/sticker.dart @@ -29,12 +29,13 @@ class Sticker { int height; bool isAnimated; bool isVideo; - PhotoSize? thumb; + PhotoSize? thumbnail; String? emoji; String? setName; File? premiumAnimation; MaskPosition? maskPosition; String? customEmojiId; + bool? needsRepainting; int? fileSize; Sticker({ required this.fileId, @@ -43,12 +44,13 @@ class Sticker { required this.height, required this.isAnimated, required this.isVideo, - this.thumb, + this.thumbnail, this.emoji, this.setName, this.premiumAnimation, this.maskPosition, this.customEmojiId, + this.needsRepainting, this.fileSize, }); factory Sticker.fromJson(Map json) => diff --git a/lib/src/telegram/models/sticker_set.dart b/lib/src/telegram/models/sticker_set.dart index 5184753..5fcf6ab 100644 --- a/lib/src/telegram/models/sticker_set.dart +++ b/lib/src/telegram/models/sticker_set.dart @@ -29,7 +29,7 @@ class StickerSet { bool isAnimated; bool isVideo; List stickers; - PhotoSize? thumb; + PhotoSize? thumbnail; StickerSet({ required this.name, required this.title, @@ -37,7 +37,7 @@ class StickerSet { 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 0000000..42e8ac6 --- /dev/null +++ b/lib/src/telegram/models/story.dart @@ -0,0 +1,31 @@ +/* + * 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/switch_inline_query_chosen_chat.dart b/lib/src/telegram/models/switch_inline_query_chosen_chat.dart new file mode 100644 index 0000000..1f6d5ce --- /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/user_shared.dart b/lib/src/telegram/models/user_shared.dart new file mode 100644 index 0000000..c59f8cb --- /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/video.dart b/lib/src/telegram/models/video.dart index 650f1eb..25a15d4 100644 --- a/lib/src/telegram/models/video.dart +++ b/lib/src/telegram/models/video.dart @@ -28,7 +28,7 @@ class Video { int width; int height; int duration; - PhotoSize? thumb; + PhotoSize? thumbnail; String? fileName; String? mimeType; int? fileSize; @@ -39,7 +39,7 @@ class Video { required this.width, required this.height, required this.duration, - this.thumb, + this.thumbnail, this.fileName, this.mimeType, this.fileSize, diff --git a/lib/src/telegram/models/video_note.dart b/lib/src/telegram/models/video_note.dart index d453626..c031086 100644 --- a/lib/src/telegram/models/video_note.dart +++ b/lib/src/telegram/models/video_note.dart @@ -30,7 +30,7 @@ class VideoNote { String fileUniqueId; int length; int duration; - PhotoSize? thumb; + PhotoSize? thumbnail; int? fileSize; VideoNote({ @@ -38,7 +38,7 @@ class VideoNote { required this.fileUniqueId, required this.length, required this.duration, - this.thumb, + this.thumbnail, this.fileSize, }); diff --git a/lib/src/telegram/models/voice.dart b/lib/src/telegram/models/voice.dart index c391633..a9dbe5e 100644 --- a/lib/src/telegram/models/voice.dart +++ b/lib/src/telegram/models/voice.dart @@ -18,7 +18,7 @@ part of '../model.dart'; -///This object represents a voice note. +/// This object represents a voice note. /// /// https://core.telegram.org/bots/api#voice @JsonSerializable(fieldRename: FieldRename.snake) diff --git a/lib/src/telegram/models/write_access_allowed.dart b/lib/src/telegram/models/write_access_allowed.dart index 3c0120b..41e1638 100644 --- a/lib/src/telegram/models/write_access_allowed.dart +++ b/lib/src/telegram/models/write_access_allowed.dart @@ -20,12 +20,14 @@ 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#writeaccessallowed @JsonSerializable(fieldRename: FieldRename.snake) class WriteAccessAllowed { - 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 8f3e5c1..dcfcefa 100644 --- a/lib/src/telegram/telegram.dart +++ b/lib/src/telegram/telegram.dart @@ -340,7 +340,7 @@ class Telegram { int? duration, String? performer, String? title, - dynamic thumb, + dynamic thumbnail, bool? disableNotification, bool? protectContent, int? replyToMessageId, @@ -379,14 +379,14 @@ class Telegram { '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 fileId or image url)')); + 'Attribute \'thumbnail\' can only be either io.File or String (Telegram fileId or image url)')); } } @@ -407,7 +407,7 @@ class Telegram { /// https://core.telegram.org/bots/api#senddocument Future sendDocument(dynamic chatId, dynamic document, {int? messageThreadId, - dynamic thumb, + dynamic thumbnail, String? caption, String? parseMode, List? captionEntities, @@ -448,14 +448,14 @@ class Telegram { '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 fileId or image url)')); + 'Attribute \'thumbnail\' can only be either io.File or String (Telegram fileId or image url)')); } } @@ -481,7 +481,7 @@ class Telegram { int? duration, int? width, int? height, - dynamic thumb, + dynamic thumbnail, String? caption, String? parseMode, List? captionEntities, @@ -527,14 +527,14 @@ class Telegram { '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 fileId or image url)')); + 'Attribute \'thumbnail\' can only be either io.File or String (Telegram fileId or image url)')); } } @@ -557,7 +557,7 @@ class Telegram { int? duration, int? width, int? height, - dynamic thumb, + dynamic thumbnail, String? caption, String? parseMode, List? captionEntities, @@ -601,14 +601,14 @@ class Telegram { '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 fileId or image url)')); + 'Attribute \'thumbnail\' can only be either io.File or String (Telegram fileId or image url)')); } } @@ -694,7 +694,7 @@ class Telegram { {int? messageThreadId, int? duration, int? length, - dynamic thumb, + dynamic thumbnail, bool? disableNotification, bool? protectContent, int? replyToMessageId, @@ -728,14 +728,14 @@ class Telegram { '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 fileId or image url)')); + 'Attribute \'thumbnail\' can only be either io.File or String (Telegram fileId or image url)')); } } @@ -775,7 +775,20 @@ class Telegram { '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(); } @@ -1184,8 +1197,9 @@ 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 chatId, int userId, - {ChatPermissions? permissions, int? untilDate}) async { + 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 \'chatId\' can only be either type of String or int')); @@ -1194,7 +1208,8 @@ class Telegram { var body = { 'chat_id': chatId, 'user_id': userId, - 'permissions': permissions == null ? null : jsonEncode(permissions), + 'permissions': jsonEncode(permissions), + 'use_independent_chat_permissions': useIndependentChatPermissions, 'until_date': untilDate, }; return await HttpClient.httpPost(requestUrl, body: body); @@ -1310,8 +1325,8 @@ class Telegram { /// Returns *True* on success. /// /// https://core.telegram.org/bots/api#setchatpermissions - Future setChatPermissions( - dynamic chatId, ChatPermissions permissions) async { + Future setChatPermissions(dynamic chatId, ChatPermissions permissions, + {bool? useIndependentChatPermissions}) async { if (chatId is! String && chatId is! int) { return Future.error(TelegramException( 'Attribute \'chatId\' can only be either type of String or int')); @@ -1320,6 +1335,7 @@ class Telegram { var body = { 'chat_id': chatId, 'permissions': jsonEncode(permissions), + 'use_independent_chat_permissions': useIndependentChatPermissions, }; return await HttpClient.httpPost(requestUrl, body: body); } @@ -1990,6 +2006,24 @@ class Telegram { 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); + } + /// Use this method to send answers to callback queries sent from [inline keyboards] /// /// The answer will be displayed to the user as a notification at the top of the chat screen or as @@ -2074,6 +2108,90 @@ class Telegram { .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. @@ -2253,7 +2371,19 @@ class Telegram { 'parse_mode': parseMode, 'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup), }; - var res = await HttpClient.httpPost(requestUrl, body: body); + + 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); + if (res == true) { return Future.error( TelegramException('Edited message is NOT sent by the bot')); @@ -2353,6 +2483,7 @@ class Telegram { /// https://core.telegram.org/bots/api#sendsticker Future sendSticker(dynamic chatId, dynamic sticker, {int? messageThreadId, + String? emoji, bool? disableNotification, bool? protectContent, int? replyToMessageId, @@ -2366,6 +2497,7 @@ class Telegram { var body = { 'chat_id': chatId, 'message_thread_id': messageThreadId, + 'emoji': emoji, 'disable_notification': disableNotification, 'protect_content': protectContent, 'reply_to_message_id': replyToMessageId, @@ -2425,15 +2557,19 @@ class Telegram { /// Returns the uploaded [File] on success. /// /// https://core.telegram.org/bots/api#uploadstickerfile - Future uploadStickerFile(int userId, io.File pngSticker) async { + Future uploadStickerFile( + int userId, io.File sticker, String stickerFormat) async { var requestUrl = _apiUri('uploadStickerFile'); - var body = {'user_id': userId}; - // filename cannot be empty to post to Telegram server - var files = List.filled( - 1, - MultipartFile( - 'png_sticker', pngSticker.openRead(), pngSticker.lengthSync(), - filename: '${pngSticker.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)); } @@ -2446,48 +2582,31 @@ class Telegram { /// Returns *True* on success. /// /// https://core.telegram.org/bots/api#createnewstickerset - Future createNewStickerSet( - int userId, String name, String title, String emojis, - {dynamic pngSticker, - io.File? tgsSticker, - io.File? webmSticker, - String? stickerType, - MaskPosition? maskPosition}) 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': userId, 'name': '${name}_by_${botInfo.username}', 'title': title, - 'emojis': emojis, + 'stickers': jsonEncode(stickers), + 'sticker_format': stickerFormat, 'sticker_type': stickerType, - 'mask_position': maskPosition == null ? null : jsonEncode(maskPosition), + 'needs_repainting': needsRepainting, }; - if (pngSticker == null && tgsSticker == null && webmSticker == null) { - return Future.error(TelegramException( - 'You must use exactly one of the fields `pngSticker`, `tgsSticker` or `webmSticker`.')); - } else if (pngSticker is String) { - body.addAll({'png_sticker': pngSticker}); - return await HttpClient.httpPost(requestUrl, body: body); - } else if (pngSticker is io.File || - tgsSticker != null || - webmSticker != null) { - var file = pngSticker ?? tgsSticker ?? webmSticker; - var fieldName = pngSticker != null - ? 'png_sticker' - : tgsSticker != 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 \'pngSticker\' can only be either io.File or String (Telegram fileId or image url)')); + return await HttpClient.httpPost(requestUrl, body: body); } } @@ -2501,43 +2620,21 @@ class Telegram { /// Returns *True* on success. /// /// https://core.telegram.org/bots/api#addstickertoset - Future addStickerToSet(int userId, String name, String emojis, - {dynamic pngSticker, - io.File? tgsSticker, - io.File? webmSticker, - MaskPosition? maskPosition}) async { + Future addStickerToSet( + int userId, String name, InputSticker sticker) async { var requestUrl = _apiUri('addStickerToSet'); var body = { 'user_id': userId, 'name': name, - 'emojis': emojis, - 'mask_position': maskPosition == null ? null : jsonEncode(maskPosition), + 'stickers': jsonEncode(sticker), }; - if (pngSticker == null && tgsSticker == null && webmSticker == null) { - return Future.error(TelegramException( - 'You must use exactly one of the fields `pngSticker`, `tgsSticker` or `webmSticker`.')); - } else if (pngSticker is String) { - body.addAll({'png_sticker': pngSticker}); - return await HttpClient.httpPost(requestUrl, body: body); - } else if (pngSticker is io.File || - tgsSticker != null || - webmSticker != null) { - var file = pngSticker ?? tgsSticker ?? webmSticker; - var fieldName = pngSticker != null - ? 'png_sticker' - : tgsSticker != 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 \'pngSticker\' can only be either io.File or String (Telegram fileId or image url)')); + return await HttpClient.httpPost(requestUrl, body: body); } } @@ -2566,36 +2663,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 userId, - {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': 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 fileId 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. @@ -2604,12 +2792,13 @@ class Telegram { /// /// https://core.telegram.org/bots/api#answerinlinequery Future answerInlineQuery( - String inlineQueryId, List results, - {int? cacheTime, - bool? isPersonal, - String? nextOffset, - String? switchPmText, - String? switchPmParameter}) async { + String inlineQueryId, + List results, { + int? cacheTime, + bool? isPersonal, + String? nextOffset, + InlineQueryResultsButton? button, + }) async { var requestUrl = _apiUri('answerInlineQuery'); var body = { 'inline_query_id': inlineQueryId, @@ -2617,8 +2806,7 @@ class Telegram { 'cache_time': cacheTime, 'is_personal': isPersonal, 'next_offset': nextOffset, - 'switch_pm_text': switchPmText, - 'switch_pm_parameter': switchPmParameter, + 'button': button == null ? null : jsonEncode(button), }; return await HttpClient.httpPost(requestUrl, body: body); } diff --git a/pubspec.yaml b/pubspec.yaml index 4d79160..d1310ce 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.5.6 +version: 0.6.0 homepage: https://github.com/DinoLeung/TeleDart issue_tracker: https://github.com/DinoLeung/TeleDart/issues environment: - sdk: ">=2.18.0 <3.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: - json_annotation: ^4.7.0 - http: ^0.13.5 + json_annotation: ^4.8.1 + http: ^1.1.0 dev_dependencies: - test: ^1.22.1 - build_runner: ^2.3.3 - json_serializable: ^6.5.4 - lints: ^2.0.1 + test: ^1.24.6 + build_runner: ^2.4.6 + json_serializable: ^6.7.1 + lints: ^2.1.1