Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: sendPaidMedia #303

Merged
merged 3 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.27.1

- Fix `RawAPI.sendPaidMedia` crashes while sending local file using `InputFile.fromFile`

# 1.27.0

- 🤖 Bot API 7.11 🎃
Expand All @@ -12,7 +16,7 @@

# 1.26.5

- Fixed in `ReactionTypeCustomEmoji.customEmojiId`
- Fix typo in `ReactionTypeCustomEmoji.customEmojiId`

# 1.26.4

Expand Down
3 changes: 3 additions & 0 deletions lib/src/telegram/models/abstracts/input_paid_media.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ sealed class InputPaidMedia {

/// Converts an [InputPaidMedia] to a [Map] for JSON encoding.
Map<String, dynamic> toJson();

/// Converts [InputPaidMedia] to a [Map] for JSON encoding
Map<String, dynamic> getValue([String? field, String? thumb]);
}
8 changes: 8 additions & 0 deletions lib/src/telegram/models/input_paid_media_photo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ class InputPaidMediaPhoto implements InputPaidMedia {
'media': media.getValue('media'),
};
}

@override
Map<String, dynamic> getValue([String? field, String? thumb]) {
return {
'type': type.value,
'media': media.getValue(field),
};
}
}
14 changes: 14 additions & 0 deletions lib/src/telegram/models/input_paid_media_video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,18 @@ class InputPaidMediaVideo implements InputPaidMedia {
'supports_streaming': supportsStreaming,
}..removeWhere(_nullFilter);
}

/// Converts a [InputPaidMediaVideo] object to JSON.
@override
Map<String, dynamic> getValue([String? field, String? thumb]) {
return {
'type': type.value,
'media': media.getValue(field),
'thumbnail': thumbnail?.getValue(thumb),
'width': width,
'height': height,
'duration': duration,
'supports_streaming': supportsStreaming,
}..removeWhere(_nullFilter);
}
}
6 changes: 4 additions & 2 deletions lib/src/televerse/api/raw_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4076,9 +4076,11 @@ class RawAPI {
final length = media.length;

for (int i = 0; i < length; i++) {
final id = "media$i";
final thumb = "$_thumb$i";
final m = media[i];
mediaList.add(m.toJson());
helpers.add(_MultipartHelper(m.media, "media$i"));
mediaList.add(m.getValue(id, thumb));
helpers.add(_MultipartHelper(m.media, id));
}

final files = _getFiles(helpers);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: televerse
description: Televerse lets you create your own efficient Telegram bots with ease in Dart. Supports latest Telegram Bot API - 7.11!
version: 1.27.0
version: 1.27.1
homepage: https://televerse.xooniverse.com
repository: https://github.com/xooniverse/televerse
topics:
Expand Down
Loading