Skip to content

Commit

Permalink
🤖 Merge #290: Bot API 7.9
Browse files Browse the repository at this point in the history
  • Loading branch information
HeySreelal authored Aug 14, 2024
2 parents fe5f3d6 + 37221d9 commit 779e838
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.24.0

- 🤖 Bot API 7.9
- Added new methods
- Published Televerse Documentation website (https://televerse.xooniverse.com)

# 1.23.1

- Exposed couple of more properties in Context
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[![Pub Version](https://img.shields.io/pub/v/televerse?color=blue&logo=blue)](https://pub.dev/packages/televerse)
![GitHub](https://img.shields.io/github/license/xooniverse/televerse?color=green)
![](https://shields.io/badge/Latest-Bot%20API%207.8-blue)
![](https://shields.io/badge/Latest-Bot%20API%207.9-blue)

<a href="https://telegram.me/TeleverseDart">
<img src="https://img.shields.io/badge/Telegram%2F@TeleverseDart-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white"/>
Expand All @@ -13,7 +13,7 @@

---

🤖 `Bot API version: Bot API 7.8 (July 31, 2024)`
🤖 `Bot API version: Bot API 7.9 (August 14, 2024)`

Televerse is a powerful, easy-to-use, and highly customizable Telegram bot
framework built with Dart programming language. It provides a complete and
Expand All @@ -23,14 +23,13 @@ public interface, making it easy for developers to write strictly typed code.

## 🔥 What's latest?

### 🤖 Bot API 7.8
### 🤖 Bot API 7.9

(🗓️ July 31, 2024)
(🗓️ August 14, 2024)

Simply, this change brings support for ability to manage pinned messages on behalf of a Business.
Much more updates on Mini apps.
In a nutshell, this update brigngs support for channel subscription, and support for Paid Media across all chats.

Checkout [changelog](https://core.telegram.org/bots/api#july-31-2024) for more
Checkout [changelog](https://core.telegram.org/bots/api-changelog#august-14-2024) for more
details! 🚀

### 🎉 Support for Custom Contexts!
Expand Down
8 changes: 7 additions & 1 deletion lib/src/telegram/models/chat_member_member.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ class ChatMemberMember implements ChatMember {
@override
final User user;

/// Optional. Date when the user's subscription will expire; Unix time
final int? untilDate;

/// Creates a new [ChatMemberMember] object.
const ChatMemberMember({
required this.user,
this.untilDate,
});

/// Converts a [ChatMemberMember] to a [Map] for JSON encoding.
Expand All @@ -21,13 +25,15 @@ class ChatMemberMember implements ChatMember {
return {
'status': status.value,
'user': user.toJson(),
};
'until_date': untilDate,
}..removeWhere(_nullFilter);
}

/// Creates a new [ChatMemberMember] object from json.
factory ChatMemberMember.fromJson(Map<String, dynamic> json) {
return ChatMemberMember(
user: User.fromJson(json['user']),
untilDate: json['until_date'],
);
}

Expand Down
3 changes: 3 additions & 0 deletions lib/src/telegram/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,6 @@ part 'transaction_partner_telegram_ads.dart';

// Bot API 7.7
part 'refunded_payment.dart';

// Bot API 7.9
part 'reaction_type_paid.dart';
19 changes: 19 additions & 0 deletions lib/src/telegram/models/reaction_type_paid.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
part of 'models.dart';

/// The reaction is paid.
class ReactionTypePaid implements ReactionType {
/// Type of the reaction, always “custom”
@override
ReactionTypeType get type => ReactionTypeType.paid;

/// Constructs the
const ReactionTypePaid();

/// Converts the object into a JSON parsable Map
@override
Map<String, dynamic> toJson() {
return {
"type": type.value,
};
}
}
12 changes: 12 additions & 0 deletions lib/src/telegram/models/transaction_partner_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,28 @@ class TransactionPartnerUser extends TransactionPartner {
/// Bot-specified invoice payload.
final String? invoicePayload;

/// Optional. Information about the paid media bought by the user
final List<PaidMedia>? paidMedia;

/// Constructs a [TransactionPartnerUser] object.
const TransactionPartnerUser({
required this.user,
this.invoicePayload,
this.paidMedia,
});

/// Creates a [TransactionPartnerUser] object from JSON.
factory TransactionPartnerUser.fromJson(Map<String, dynamic> json) {
return TransactionPartnerUser(
user: User.fromJson(json['user']),
invoicePayload: json['invoice_payload'],
paidMedia: json['paid_media'] != null
? List<PaidMedia>.from(
(json['paid_media'] as List).map(
(e) => PaidMedia.fromJson(e),
),
)
: null,
);
}

Expand All @@ -32,6 +43,7 @@ class TransactionPartnerUser extends TransactionPartner {
'type': type.toJson(),
'user': user.toJson(),
'invoice_payload': invoicePayload,
'paid_media': paidMedia?.map((e) => e.toJson()).toList(),
}..removeWhere(_nullFilter);
}
}
44 changes: 44 additions & 0 deletions lib/src/televerse/api/raw_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3983,6 +3983,7 @@ class RawAPI {
bool? protectContent,
ReplyParameters? replyParameters,
ReplyMarkup? replyMarkup,
String? businessConnectionId,
}) async {
final params = {
"chat_id": chatId.id,
Expand All @@ -3995,6 +3996,7 @@ class RawAPI {
"protect_content": protectContent,
"reply_parameters": replyParameters?.toJson(),
"reply_markup": replyMarkup?.toJson(),
"business_connection_id": businessConnectionId,
};

List<_MultipartHelper> helpers = [];
Expand All @@ -4017,4 +4019,46 @@ class RawAPI {

return Message.fromJson(response);
}

/// Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator rights. The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method revokeChatInviteLink. Returns the new invite link as a ChatInviteLink object.
Future<ChatInviteLink> createChatSubscriptionInviteLink({
required ID chatId,
String? name,
required int subscriptionPeriod,
required int subscriptionPrice,
}) async {
final params = {
"chat_id": chatId.id,
"name": name,
"subscription_period": subscriptionPeriod,
"subscription_price": subscriptionPrice,
};

final response = await _makeApiJsonCall(
APIMethod.createChatSubscriptionInviteLink,
payload: Payload(params),
);

return ChatInviteLink.fromJson(response);
}

/// Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights. Returns the edited invite link as a ChatInviteLink object.
Future<ChatInviteLink> editChatSubscriptionInviteLink({
required ID chatId,
required String inviteLink,
String? name,
}) async {
final params = {
"chat_id": chatId.id,
"name": name,
"invite_link": inviteLink,
};

final response = await _makeApiJsonCall(
APIMethod.editChatSubscriptionInviteLink,
payload: Payload(params),
);

return ChatInviteLink.fromJson(response);
}
}
6 changes: 6 additions & 0 deletions lib/src/types/methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,12 @@ enum APIMethod {

/// Sends paid media
sendPaidMedia._("sendPaidMedia"),

/// Use this method to create a subscription invite link for a channel chat
createChatSubscriptionInviteLink._("createChatSubscriptionInviteLink"),

/// Use this method to edit a subscription invite link created by the bot.
editChatSubscriptionInviteLink._("editChatSubscriptionInviteLink"),
;

/// The name of the method.
Expand Down
5 changes: 5 additions & 0 deletions lib/src/types/reaction_type_emoji_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ enum ReactionTypeType {

/// Represents a custom emoji.
customEmoji._("custom_emoji"),

/// Paid reaction
paid._("paid"),
;

/// The inner value of this enum entry.
Expand All @@ -22,6 +25,8 @@ enum ReactionTypeType {
return emoji;
case "custom_emoji":
return customEmoji;
case "paid":
return paid;
default:
throw TeleverseException(
"Unknown value: $value",
Expand Down
4 changes: 2 additions & 2 deletions 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.8!
version: 1.23.1
description: Televerse lets you create your own efficient Telegram bots with ease in Dart. Supports latest Telegram Bot API - 7.9!
version: 1.24.0
homepage: https://televerse.xooniverse.com
repository: https://github.com/xooniverse/televerse
topics:
Expand Down

0 comments on commit 779e838

Please sign in to comment.