Skip to content

Commit

Permalink
🪐 Merge #255: Improved code quality
Browse files Browse the repository at this point in the history
Improved edit methods and code quality
  • Loading branch information
HeySreelal authored Jun 18, 2024
2 parents a0556b8 + b44a7c4 commit a4e8995
Show file tree
Hide file tree
Showing 27 changed files with 837 additions and 259 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.18.0

- 🤖 Bot API 7.5
- Improved context aware methods
- Added `WithID` abstraction

# 1.17.2

- Added `considerCaption` parameter in `Bot.command` mehtod to match commands in the caption of video/photo messages.
Expand Down
10 changes: 5 additions & 5 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/HeySreelal/televerse?color=green)
![](https://shields.io/badge/Latest-Bot%20API%207.4-blue)
![](https://shields.io/badge/Latest-Bot%20API%207.5-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,15 +13,15 @@

---

🤖 `Bot API version: Bot API 7.4 (May 28, 2024)`
🤖 `Bot API version: Bot API 7.5 (June 18, 2024)`

Televerse is a powerful, easy-to-use, and highly customizable Telegram bot framework built with Dart programming language. It provides a complete and well-structured API that enables developers to create and deploy complex Telegram bots with ease. Televerse provides a total of 0 dynamic types on its public interface, making it easy for developers to write strictly typed code.

## 🔥 Bot API 7.4 (May 28, 2024)
## 🔥 Bot API 7.5 (June 18, 2024)

In a nutshell, the updates include new Payment system with [Telegram Stars](https://t.me/BotNews/90), support for message effects and expandable blockquotes.
In a nutshell, the updates include new Payment system with [Telegram Stars](https://t.me/BotNews/90). Includes a bunch of new models related to Star Payments and new method to get Bot's Star Payment history. This update also includes support for Business Bots to edit messages as well as accept callback and inline queries.

Checkout [changelog](https://core.telegram.org/bots/api#may-28-2024) for more details! 🚀
Checkout [changelog](https://core.telegram.org/bots/api#june-18-2024) for more details! 🚀

<hr>

Expand Down
6 changes: 6 additions & 0 deletions lib/src/telegram/models/abstractions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ abstract class WithUser {
User? get from;
}

/// The base class for all the models that have a user.
abstract class WithID {
/// The user who triggered the event.
int get id;
}

/// Null filter function.
bool _nullFilter(String _, dynamic value) => value == null;
29 changes: 29 additions & 0 deletions lib/src/telegram/models/abstracts/revenue_withdrawal_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
part of '../models.dart';

/// This object describes the state of a revenue withdrawal operation.
/// Currently, it can be one of [RevenueWithdrawalStatePending], [RevenueWithdrawalStateSucceeded], [RevenueWithdrawalStateFailed].
abstract class RevenueWithdrawalState {
/// Type of the revenue withdrawal state.
RevenueWithdrawalStateType get type;

/// Creates a new [RevenueWithdrawalState] object.
/// This method decides which [RevenueWithdrawalState] subclass to use based on the [type] field.
static RevenueWithdrawalState fromJson(Map<String, dynamic> json) {
switch (RevenueWithdrawalStateType.fromJson(json['type'])) {
case RevenueWithdrawalStateType.pending:
return RevenueWithdrawalStatePending.fromJson(json);
case RevenueWithdrawalStateType.succeeded:
return RevenueWithdrawalStateSucceeded.fromJson(json);
case RevenueWithdrawalStateType.failed:
return RevenueWithdrawalStateFailed.fromJson(json);
default:
throw ArgumentError('Invalid revenue withdrawal state type');
}
}

/// Creates a new [RevenueWithdrawalState] object from JSON.
const RevenueWithdrawalState();

/// Converts a [RevenueWithdrawalState] to a [Map] for JSON encoding.
Map<String, dynamic> toJson();
}
25 changes: 25 additions & 0 deletions lib/src/telegram/models/abstracts/transaction_partner.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
part of '../models.dart';

/// This object describes the source of a transaction, or its recipient for outgoing transactions.
/// Currently, it can be one of [TransactionPartnerFragment], [TransactionPartnerUser], [TransactionPartnerOther].
abstract class TransactionPartner {
/// Type of the transaction partner.
TransactionPartnerType get type;

/// Creates a new [TransactionPartner] object.
/// This method decides which [TransactionPartner] subclass to use based on the [type] field.
static TransactionPartner fromJson(Map<String, dynamic> json) {
return switch (json['type']) {
'fragment' => TransactionPartnerFragment.fromJson(json),
'user' => TransactionPartnerUser.fromJson(json),
'other' => TransactionPartnerOther.fromJson(json),
_ => throw ArgumentError('Invalid transaction partner type')
};
}

/// Creates a new [TransactionPartner] object from JSON.
const TransactionPartner();

/// Converts a [TransactionPartner] to a [Map] for JSON encoding.
Map<String, dynamic> toJson();
}
3 changes: 2 additions & 1 deletion lib/src/telegram/models/chat.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
part of 'models.dart';

/// This object represents a chat.
class Chat {
class Chat implements WithID {
/// Unique identifier for this chat.
@override
final int id;

/// Type of the chat, can be either "private", "group", "supergroup" or "channel".
Expand Down
2 changes: 1 addition & 1 deletion lib/src/telegram/models/chat_full_info.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
part of 'models.dart';

/// This object represents a chat.
class ChatFullInfo extends Chat {
class ChatFullInfo extends Chat implements WithID {
/// Optional. Chat photo.
final ChatPhoto? photo;

Expand Down
12 changes: 12 additions & 0 deletions lib/src/telegram/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,15 @@ part 'background_fill_freeform_gradient.dart';
part 'background_fill_gradient.dart';
part 'chat_background.dart';
part 'chat.dart';

// Bot API 7.5
part 'star_transaction.dart';
part 'star_transactions.dart';
part 'abstracts/transaction_partner.dart';
part 'transaction_partner_fragment.dart';
part 'transaction_partner_other.dart';
part 'transaction_partner_user.dart';
part 'abstracts/revenue_withdrawal_state.dart';
part 'revenue_withdrawal_state_pending.dart';
part 'revenue_withdrawal_state_succeeded.dart';
part 'revenue_withdrawal_state_failed.dart';
23 changes: 23 additions & 0 deletions lib/src/telegram/models/revenue_withdrawal_state_failed.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
part of 'models.dart';

/// The withdrawal failed and the transaction was refunded.
class RevenueWithdrawalStateFailed extends RevenueWithdrawalState {
@override
RevenueWithdrawalStateType get type => RevenueWithdrawalStateType.failed;

/// Constructs a [RevenueWithdrawalStateFailed] object.
const RevenueWithdrawalStateFailed();

/// Creates a [RevenueWithdrawalStateFailed] object from JSON.
factory RevenueWithdrawalStateFailed.fromJson(Map<String, dynamic> json) {
return RevenueWithdrawalStateFailed();
}

/// Converts a [RevenueWithdrawalStateFailed] object to JSON.
@override
Map<String, dynamic> toJson() {
return {
'type': type.toJson(),
};
}
}
23 changes: 23 additions & 0 deletions lib/src/telegram/models/revenue_withdrawal_state_pending.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
part of 'models.dart';

/// The withdrawal is in progress.
class RevenueWithdrawalStatePending extends RevenueWithdrawalState {
@override
RevenueWithdrawalStateType get type => RevenueWithdrawalStateType.pending;

/// Constructs a [RevenueWithdrawalStatePending] object.
const RevenueWithdrawalStatePending();

/// Creates a [RevenueWithdrawalStatePending] object from JSON.
factory RevenueWithdrawalStatePending.fromJson(Map<String, dynamic> json) {
return RevenueWithdrawalStatePending();
}

/// Converts a [RevenueWithdrawalStatePending] object to JSON.
@override
Map<String, dynamic> toJson() {
return {
'type': type.toJson(),
};
}
}
37 changes: 37 additions & 0 deletions lib/src/telegram/models/revenue_withdrawal_state_succeeded.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
part of 'models.dart';

/// The withdrawal succeeded.
class RevenueWithdrawalStateSucceeded extends RevenueWithdrawalState {
@override
RevenueWithdrawalStateType get type => RevenueWithdrawalStateType.succeeded;

/// Date the withdrawal was completed in Unix time.
final int date;

/// An HTTPS URL that can be used to see transaction details.
final String url;

/// Constructs a [RevenueWithdrawalStateSucceeded] object.
const RevenueWithdrawalStateSucceeded({
required this.date,
required this.url,
});

/// Creates a [RevenueWithdrawalStateSucceeded] object from JSON.
factory RevenueWithdrawalStateSucceeded.fromJson(Map<String, dynamic> json) {
return RevenueWithdrawalStateSucceeded(
date: json['date'],
url: json['url'],
);
}

/// Converts a [RevenueWithdrawalStateSucceeded] object to JSON.
@override
Map<String, dynamic> toJson() {
return {
'type': type.toJson(),
'date': date,
'url': url,
};
}
}
58 changes: 58 additions & 0 deletions lib/src/telegram/models/star_transaction.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
part of 'models.dart';

/// This object describes a Telegram Star transaction.
class StarTransaction {
/// Unique identifier of the transaction.
/// Coincides with the identifier of the original transaction for refund transactions.
/// Coincides with [SuccessfulPayment.telegramPaymentChargeId] for successful incoming payments from users.
final String id;

/// Number of Telegram Stars transferred by the transaction.
final int amount;

/// Date the transaction was created in Unix time.
final int date;

/// Optional. Source of an incoming transaction (e.g., a user purchasing goods or services,
/// Fragment refunding a failed withdrawal). Only for incoming transactions.
final TransactionPartner? source;

/// Optional. Receiver of an outgoing transaction (e.g., a user for a purchase refund,
/// Fragment for a withdrawal). Only for outgoing transactions.
final TransactionPartner? receiver;

/// Creates a new [StarTransaction] object.
const StarTransaction({
required this.id,
required this.amount,
required this.date,
this.source,
this.receiver,
});

/// Creates a new [StarTransaction] object from json.
factory StarTransaction.fromJson(Map<String, dynamic> json) {
return StarTransaction(
id: json['id'],
amount: json['amount'],
date: json['date'],
source: json['source'] != null
? TransactionPartner.fromJson(json['source'])
: null,
receiver: json['receiver'] != null
? TransactionPartner.fromJson(json['receiver'])
: null,
);
}

/// Converts a [StarTransaction] object to json.
Map<String, dynamic> toJson() {
return {
'id': id,
'amount': amount,
'date': date,
'source': source?.toJson(),
'receiver': receiver?.toJson(),
};
}
}
28 changes: 28 additions & 0 deletions lib/src/telegram/models/star_transactions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
part of 'models.dart';

/// This object represents a list of Telegram Star transactions.
class StarTransactions {
/// The list of transactions.
final List<StarTransaction> transactions;

/// Creates a new [StarTransactions] object.
const StarTransactions({
required this.transactions,
});

/// Creates a new [StarTransactions] object from json.
factory StarTransactions.fromJson(Map<String, dynamic> json) {
return StarTransactions(
transactions: (json['transactions'] as List)
.map((item) => StarTransaction.fromJson(item))
.toList(),
);
}

/// Converts a [StarTransactions] object to json.
Map<String, dynamic> toJson() {
return {
'transactions': transactions.map((item) => item.toJson()).toList(),
};
}
}
33 changes: 33 additions & 0 deletions lib/src/telegram/models/transaction_partner_fragment.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
part of 'models.dart';

/// Describes a withdrawal transaction with Fragment.
class TransactionPartnerFragment extends TransactionPartner {
@override
TransactionPartnerType get type => TransactionPartnerType.fragment;

/// State of the transaction if the transaction is outgoing.
final RevenueWithdrawalState? withdrawalState;

/// Constructs a [TransactionPartnerFragment] object.
const TransactionPartnerFragment({
this.withdrawalState,
});

/// Creates a [TransactionPartnerFragment] object from JSON.
factory TransactionPartnerFragment.fromJson(Map<String, dynamic> json) {
return TransactionPartnerFragment(
withdrawalState: json['withdrawal_state'] != null
? RevenueWithdrawalState.fromJson(json['withdrawal_state'])
: null,
);
}

/// Converts a [TransactionPartnerFragment] object to JSON.
@override
Map<String, dynamic> toJson() {
return {
'type': type,
'withdrawal_state': withdrawalState?.toJson(),
};
}
}
23 changes: 23 additions & 0 deletions lib/src/telegram/models/transaction_partner_other.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
part of 'models.dart';

/// Describes a transaction with an unknown source or recipient.
class TransactionPartnerOther extends TransactionPartner {
@override
TransactionPartnerType get type => TransactionPartnerType.other;

/// Constructs a [TransactionPartnerOther] object.
const TransactionPartnerOther();

/// Creates a [TransactionPartnerOther] object from JSON.
factory TransactionPartnerOther.fromJson(Map<String, dynamic> json) {
return TransactionPartnerOther();
}

/// Converts a [TransactionPartnerOther] object to JSON.
@override
Map<String, dynamic> toJson() {
return {
'type': type,
};
}
}
Loading

0 comments on commit a4e8995

Please sign in to comment.