Skip to content

Commit

Permalink
🤖 Merge #306: Bot API 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HeySreelal authored Nov 18, 2024
2 parents 7b0a38c + f485ee7 commit 22cfc51
Show file tree
Hide file tree
Showing 12 changed files with 331 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 1.28.0

- 🤖 Bot API 8.0
- Updated `RawAPI.createInvoiceLink` to the docs.
- Updated `SuccessfulPayment`, `TransactionPartnerUser` to reflect the new Star Subscription features.
- 🆕 Added new API Methods - `editUserStarSubscription`, `setUserEmojiStatus`, `savePreparedInlineMessage`, `getAvailableGifts`, `sendGift`.
- 🆕 Added new classes - `PreparedInlineMessage`, `Gift`, `Gifts`.

# 1.27.3

- ⚠️ Removed `baseURL` from `Bot` primary constructor.
Expand Down
12 changes: 6 additions & 6 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.11-blue)
![](https://shields.io/badge/Latest-Bot%20API%208.0-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 @@ -12,7 +12,7 @@

---

🤖 `Bot API version: Bot API 7.11 (October 31, 2024)` 🎃
🤖 `Bot API version: Bot API 8.0 (November 17, 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 @@ -22,13 +22,13 @@ public interface, making it easy for developers to write strictly typed code.

## 🔥 What's latest?

### 🤖 Bot API 7.11 🎃
### 🤖 Bot API 8.0 🎃

(🗓️ October 31, 2024)
(🗓️ November 17, 2024)

In a nutshell, this update brigngs support for broadcasting upto 1000 Messages per second. New Copy Text Inline Button, and more.
In a nutshell, this update majorly is about Telegram Mini Apps, though we have a few new methods for Bot API including `editUserStarSubscription`, `getAvailableGifts` etc. Being said that, now Bots can send Gifts to the user. 🎁

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

### 🎉 Support for Custom Contexts!
Expand Down
50 changes: 50 additions & 0 deletions lib/src/telegram/models/gift.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
part of 'models.dart';

/// Represents a gift that can be sent by the bot.
class Gift {
/// Unique identifier of the gift.
final String id;

/// The sticker that represents the gift.
final Sticker sticker;

/// The number of Telegram Stars that must be paid to send the sticker.
final int starCount;

/// Optional. The total number of gifts of this type that can be sent; for limited gifts only.
final int? totalCount;

/// Optional. The number of remaining gifts of this type that can be sent; for limited gifts only.
final int? remainingCount;

/// Creates a [Gift] object.
const Gift({
required this.id,
required this.sticker,
required this.starCount,
this.totalCount,
this.remainingCount,
});

/// Creates a [Gift] object from a JSON map.
factory Gift.fromJson(Map<String, dynamic> json) {
return Gift(
id: json['id'],
sticker: Sticker.fromJson(json['sticker']),
starCount: json['star_count'],
totalCount: json['total_count'],
remainingCount: json['remaining_count'],
);
}

/// Converts this object to a JSON map.
Map<String, dynamic> toJson() {
return {
'id': id,
'sticker': sticker.toJson(),
'star_count': starCount,
'total_count': totalCount,
'remaining_count': remainingCount,
};
}
}
28 changes: 28 additions & 0 deletions lib/src/telegram/models/gifts.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
part of 'models.dart';

/// Represents a list of gifts.
class Gifts {
/// The list of gifts.
final List<Gift> gifts;

/// Creates a [Gifts] object.
const Gifts({
required this.gifts,
});

/// Creates a [Gifts] object from a JSON map.
factory Gifts.fromJson(Map<String, dynamic> json) {
return Gifts(
gifts: List<Gift>.from(
(json['gifts'] as List).map((gift) => Gift.fromJson(gift)),
),
);
}

/// Converts this object to a JSON map.
Map<String, dynamic> toJson() {
return {
'gifts': gifts.map((gift) => gift.toJson()).toList(),
};
}
}
5 changes: 5 additions & 0 deletions lib/src/telegram/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,8 @@ part 'paid_media_purchased.dart';
// Bot API 7.11
part 'copy_text_button.dart';
part 'transaction_partner_telegram_api.dart';

// Bot API 8.0
part 'prepared_inline_message.dart';
part 'gift.dart';
part 'gifts.dart';
33 changes: 33 additions & 0 deletions lib/src/telegram/models/prepared_inline_message.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
part of 'models.dart';

/// Describes an inline message to be sent by a user of a Mini App.
class PreparedInlineMessage {
/// Unique identifier of the prepared message.
final String id;

/// Expiration date of the prepared message, in Unix time.
/// Expired prepared messages can no longer be used.
final int expirationDate;

/// Creates a [PreparedInlineMessage] object.
const PreparedInlineMessage({
required this.id,
required this.expirationDate,
});

/// Creates a [PreparedInlineMessage] object from a JSON map.
factory PreparedInlineMessage.fromJson(Map<String, dynamic> json) {
return PreparedInlineMessage(
id: json['id'],
expirationDate: json['expiration_date'],
);
}

/// Converts this object to a JSON map.
Map<String, dynamic> toJson() {
return {
'id': id,
'expiration_date': expirationDate,
};
}
}
12 changes: 12 additions & 0 deletions lib/src/telegram/models/successful_payment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class SuccessfulPayment {
/// Provider payment identifier
final String providerPaymentChargeId;

/// Optional. True, if the payment is a recurring payment for a subscription
final bool? isRecurring;

/// Optional. True, if the payment is the first payment for a subscription
final bool? isFirstRecurring;

/// Constructs a [SuccessfulPayment] object
const SuccessfulPayment({
required this.currency,
Expand All @@ -32,6 +38,8 @@ class SuccessfulPayment {
this.orderInfo,
required this.telegramPaymentChargeId,
required this.providerPaymentChargeId,
this.isRecurring,
this.isFirstRecurring,
});

/// Converts a [SuccessfulPayment] object to a JSON object
Expand All @@ -44,6 +52,8 @@ class SuccessfulPayment {
'order_info': orderInfo?.toJson(),
'telegram_payment_charge_id': telegramPaymentChargeId,
'provider_payment_charge_id': providerPaymentChargeId,
'is_recurring': isRecurring,
'is_first_recurring': isFirstRecurring,
}..removeWhere(_nullFilter);
}

Expand All @@ -59,6 +69,8 @@ class SuccessfulPayment {
: null,
telegramPaymentChargeId: json['telegram_payment_charge_id']!,
providerPaymentChargeId: json['provider_payment_charge_id']!,
isRecurring: json['is_recurring'],
isFirstRecurring: json['is_first_recurring'],
);
}
}
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 @@ -17,12 +17,20 @@ class TransactionPartnerUser extends TransactionPartner {
/// Optional. Bot-specified paid media payload
final String? paidMediaPayload;

/// Optional. The duration of the paid subscription.
final int? subscriptionPeriod;

/// Optional. The gift sent to the user by the bot.
final Gift? gift;

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

/// Creates a [TransactionPartnerUser] object from JSON.
Expand All @@ -38,6 +46,8 @@ class TransactionPartnerUser extends TransactionPartner {
)
: null,
paidMediaPayload: json['paid_media_payload'],
subscriptionPeriod: json['subscription_period'],
gift: json['gift'] != null ? Gift.fromJson(json['gift']) : null,
);
}

Expand All @@ -50,6 +60,8 @@ class TransactionPartnerUser extends TransactionPartner {
'invoice_payload': invoicePayload,
'paid_media': paidMedia?.map((e) => e.toJson()).toList(),
'paid_media_payload': paidMediaPayload,
'subscription_period': subscriptionPeriod,
'gift': gift?.toJson(),
}..removeWhere(_nullFilter);
}
}
Loading

0 comments on commit 22cfc51

Please sign in to comment.