Skip to content

Commit

Permalink
use enum in inline query results
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoLeung committed Mar 31, 2024
1 parent 80c9651 commit e46f659
Show file tree
Hide file tree
Showing 22 changed files with 78 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- support Telegram API 6.9
- **Breaking** Updated class `Dice`, function `telegram:Telegram.sendDice` and function `teledart:Message.replyDice` to accept enum of `DiceEmoji` instead of emoji string
- **Breaking** Updated class `InlineQueryResult` to use enum for `type`

## 0.6.1

Expand Down
38 changes: 37 additions & 1 deletion lib/src/telegram/models/inline_query_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,41 @@ part of '../model.dart';
/// * [InlineQueryResultVoice](https://core.telegram.org/bots/api#inlinequeryresultvoice)
///
/// https://core.telegram.org/bots/api#inlinequeryresult
@JsonEnum()
enum InlineQueryResultType {
@JsonValue('article')
article,
@JsonValue('audio')
audio,
@JsonValue('document')
document,
@JsonValue('gif')
gif,
@JsonValue('mpeg4_gif')
mpeg4Gif,
@JsonValue('photo')
photo,
@JsonValue('sticker')
sticker,
@JsonValue('video')
video,
@JsonValue('voice')
voice,
@JsonValue('contact')
contact,
@JsonValue('game')
game,
@JsonValue('location')
location,
@JsonValue('venue')
venue,
}

extension InlineQueryResultTypeExtenson on InlineQueryResultType {
String value() => _$InlineQueryResultTypeEnumMap[this]!;
}

@JsonSerializable(fieldRename: FieldRename.snake)
class InlineQueryResult {
static const typeArticle = 'article';
Expand All @@ -59,7 +94,8 @@ class InlineQueryResult {
static const typeLocation = 'location';
static const typeVenue = 'venue';

String type;
// String type;
InlineQueryResultType type;
String id;
InlineKeyboardMarkup? replyMarkup;
InlineQueryResult({
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/inline_query_result_article.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class InlineQueryResultArticle implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String title;
InputMessageContent inputMessageContent;
@override
Expand All @@ -39,7 +39,7 @@ class InlineQueryResultArticle implements InlineQueryResult {
String? thumbnailHeight;
InlineQueryResultArticle({
required this.id,
this.type = InlineQueryResult.typeArticle,
this.type = InlineQueryResultType.article,
required this.title,
required this.inputMessageContent,
this.replyMarkup,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/inline_query_result_audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class InlineQueryResultAudio implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String audioUrl;
String title;
String? caption;
Expand All @@ -47,7 +47,7 @@ class InlineQueryResultAudio implements InlineQueryResult {

InlineQueryResultAudio({
required this.id,
this.type = InlineQueryResult.typeAudio,
this.type = InlineQueryResultType.audio,
required this.audioUrl,
required this.title,
this.caption,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/inline_query_result_cached_audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class InlineQueryResultCachedAudio implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String audioFileId;
String? caption;
String? parseMode;
Expand All @@ -43,7 +43,7 @@ class InlineQueryResultCachedAudio implements InlineQueryResult {
InputMessageContent? inputMessageContent;
InlineQueryResultCachedAudio({
required this.id,
this.type = InlineQueryResult.typeAudio,
this.type = InlineQueryResultType.article,
required this.audioFileId,
this.caption,
this.parseMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class InlineQueryResultCachedDocument implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String title;
String documentFileId;
String? description;
Expand All @@ -45,7 +45,7 @@ class InlineQueryResultCachedDocument implements InlineQueryResult {
InputMessageContent? inputMessageContent;
InlineQueryResultCachedDocument({
required this.id,
this.type = InlineQueryResult.typeDocument,
this.type = InlineQueryResultType.document,
required this.title,
required this.documentFileId,
this.description,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/inline_query_result_cached_gif.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class InlineQueryResultCachedGif implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String gifFileId;
String? title;
String? caption;
Expand All @@ -41,7 +41,7 @@ class InlineQueryResultCachedGif implements InlineQueryResult {
InputMessageContent? inputMessageContent;
InlineQueryResultCachedGif({
required this.id,
this.type = InlineQueryResult.typeGif,
this.type = InlineQueryResultType.gif,
required this.gifFileId,
this.title,
this.caption,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class InlineQueryResultCachedMpeg4Gif implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String mpeg4FileId;
String? title;
String? caption;
Expand All @@ -41,7 +41,7 @@ class InlineQueryResultCachedMpeg4Gif implements InlineQueryResult {
InputMessageContent? inputMessageContent;
InlineQueryResultCachedMpeg4Gif({
required this.id,
this.type = InlineQueryResult.typeMpeg4Gif,
this.type = InlineQueryResultType.mpeg4Gif,
required this.mpeg4FileId,
this.title,
this.caption,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/inline_query_result_cached_photo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class InlineQueryResultCachedPhoto implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String photoFileId;
String? title;
String? description;
Expand All @@ -42,7 +42,7 @@ class InlineQueryResultCachedPhoto implements InlineQueryResult {
InputMessageContent? inputMessageContent;
InlineQueryResultCachedPhoto({
required this.id,
this.type = InlineQueryResult.typePhoto,
this.type = InlineQueryResultType.photo,
required this.photoFileId,
this.title,
this.description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class InlineQueryResultCachedSticker implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String? stickerFileId;
@override
InlineKeyboardMarkup? replyMarkup;
InputMessageContent? inputMessageContent;
InlineQueryResultCachedSticker({
required this.id,
this.type = InlineQueryResult.typeSticker,
this.type = InlineQueryResultType.sticker,
required this.stickerFileId,
this.replyMarkup,
this.inputMessageContent,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/inline_query_result_cached_video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class InlineQueryResultCachedVideo implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String videoFileId;
String title;
String? description;
Expand All @@ -42,7 +42,7 @@ class InlineQueryResultCachedVideo implements InlineQueryResult {
InputMessageContent? inputMessageContent;
InlineQueryResultCachedVideo({
required this.id,
this.type = InlineQueryResult.typeVideo,
this.type = InlineQueryResultType.video,
required this.videoFileId,
required this.title,
this.description,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/inline_query_result_cached_voice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class InlineQueryResultCachedVoice implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String voiceFileId;
String title;
String? caption;
Expand All @@ -44,7 +44,7 @@ class InlineQueryResultCachedVoice implements InlineQueryResult {
InputMessageContent? inputMessageContent;
InlineQueryResultCachedVoice({
required this.id,
this.type = InlineQueryResult.typeVoice,
this.type = InlineQueryResultType.voice,
required this.voiceFileId,
required this.title,
this.caption,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/inline_query_result_contact.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class InlineQueryResultContact implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String phoneNumber;
String firstName;
String? lastName;
Expand All @@ -46,7 +46,7 @@ class InlineQueryResultContact implements InlineQueryResult {
int? thumbnailHeight;
InlineQueryResultContact({
required this.id,
this.type = InlineQueryResult.typeContact,
this.type = InlineQueryResultType.contact,
required this.phoneNumber,
required this.firstName,
this.lastName,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/inline_query_result_document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class InlineQueryResultDocument implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String title;
String? caption;
String? parseMode;
Expand All @@ -49,7 +49,7 @@ class InlineQueryResultDocument implements InlineQueryResult {
int? thumbnailHeight;
InlineQueryResultDocument({
required this.id,
this.type = InlineQueryResult.typeDocument,
this.type = InlineQueryResultType.document,
required this.title,
this.caption,
this.parseMode,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/inline_query_result_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class InlineQueryResultGame implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String gameShortName;
@override
InlineKeyboardMarkup? replyMarkup;
InlineQueryResultGame({
required this.id,
this.type = InlineQueryResult.typeGame,
this.type = InlineQueryResultType.game,
required this.gameShortName,
this.replyMarkup,
});
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/inline_query_result_gif.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class InlineQueryResultGif implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String gifUrl;
int? gifWidth;
int? gifHeight;
Expand All @@ -46,7 +46,7 @@ class InlineQueryResultGif implements InlineQueryResult {

InlineQueryResultGif({
required this.id,
this.type = InlineQueryResult.typeGif,
this.type = InlineQueryResultType.gif,
required this.gifUrl,
this.gifWidth,
this.gifHeight,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/inline_query_result_location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class InlineQueryResultLocation implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
double latitude;
double longitude;
String title;
Expand All @@ -49,7 +49,7 @@ class InlineQueryResultLocation implements InlineQueryResult {

InlineQueryResultLocation({
required this.id,
this.type = InlineQueryResult.typeLocation,
this.type = InlineQueryResultType.location,
required this.latitude,
required this.longitude,
required this.title,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/inline_query_result_mpeg4_gif.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class InlineQueryResultMpeg4Gif implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String mpeg4Url;
int? mpeg4Width;
int? mpeg4Height;
Expand All @@ -47,7 +47,7 @@ class InlineQueryResultMpeg4Gif implements InlineQueryResult {

InlineQueryResultMpeg4Gif({
required this.id,
this.type = InlineQueryResult.typeMpeg4Gif,
this.type = InlineQueryResultType.mpeg4Gif,
required this.mpeg4Url,
this.mpeg4Width,
this.mpeg4Height,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/inline_query_result_photo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class InlineQueryResultPhoto implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String photoUrl;
String thumbnailUrl;
int? photoWidth;
Expand All @@ -45,7 +45,7 @@ class InlineQueryResultPhoto implements InlineQueryResult {
InputMessageContent? inputMessageContent;
InlineQueryResultPhoto({
required this.id,
this.type = InlineQueryResult.typePhoto,
this.type = InlineQueryResultType.photo,
required this.photoUrl,
required this.thumbnailUrl,
this.photoWidth,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/inline_query_result_venue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class InlineQueryResultVenue implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
double latitude;
double longitude;
String title;
Expand All @@ -50,7 +50,7 @@ class InlineQueryResultVenue implements InlineQueryResult {
int? thumbnailHeight;
InlineQueryResultVenue({
required this.id,
this.type = InlineQueryResult.typeVenue,
this.type = InlineQueryResultType.venue,
required this.latitude,
required this.longitude,
required this.title,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/telegram/models/inline_query_result_video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class InlineQueryResultVideo implements InlineQueryResult {
@override
String id;
@override
String type;
InlineQueryResultType type;
String videoUrl;
String mimeType;
String thumbnailUrl;
Expand All @@ -51,7 +51,7 @@ class InlineQueryResultVideo implements InlineQueryResult {

InlineQueryResultVideo({
required this.id,
this.type = InlineQueryResult.typeVideo,
this.type = InlineQueryResultType.video,
required this.videoUrl,
required this.mimeType,
required this.thumbnailUrl,
Expand Down
Loading

0 comments on commit e46f659

Please sign in to comment.