Skip to content

Commit

Permalink
Merge pull request #25 from KaikyuLotus/APIv7.1
Browse files Browse the repository at this point in the history
Updated to bot API 7.1
  • Loading branch information
ale183 committed Apr 16, 2024
2 parents afe5991 + 86bc117 commit 4fa972a
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.3.0

- Updated to bot API 7.1

## 1.2.0

- Updated to bot API 7.0
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Dart Telegram Bot is a [Dart](https://dart.dev) wrapper for [Telegram](https://t
bot [API](https://core.telegram.org/bots/api). \
It is compatible with Native, Flutter and JS.

[![Bot API Version](https://img.shields.io/badge/Bot%20API-7.0-blue.svg?style=flat-square)](https://core.telegram.org/bots/api)
[![Dart Version](https://img.shields.io/badge/Dart-2.15.0-blue.svg?style=flat-square)](https://dart.dev)
[![Bot API Version](https://img.shields.io/badge/Bot%20API-7.1-blue.svg?style=flat-square)](https://core.telegram.org/bots/api)
[![Dart Version](https://img.shields.io/badge/Dart-2.17.7-blue.svg?style=flat-square)](https://dart.dev)

Using Dart Telegram Bot is straightforward, here's an example echo bot:
```dart
Expand Down
18 changes: 18 additions & 0 deletions lib/src/entities/telegram/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ class Chat {
/// Returned only in getChat.
int? slowModeDelay;

/// Optional.
/// For supergroups, the minimum number of boosts that a non-administrator
/// user needs to add in order to ignore slow mode and chat permissions.
/// Returned only in getChat.
int? unrestrictBoostCount;

/// Optional.
/// The time after which all messages sent to the chat will be automatically
/// deleted; in seconds.
Expand Down Expand Up @@ -181,6 +187,12 @@ class Chat {
/// Returned only in getChat.
bool? canSetStickerSet;

/// Optional.
/// For supergroups, the name of the group's custom emoji sticker set.
/// Custom emoji from this set can be used by all users and bots in the group.
/// Returned only in getChat.
String? customEmojiStickerSetName;

/// Optional.
/// Unique identifier for the linked chat, i.e. the discussion group
/// identifier for a channel and vice versa;
Expand Down Expand Up @@ -225,13 +237,15 @@ class Chat {
this.pinnedMessage,
this.permissions,
this.slowModeDelay,
this.unrestrictBoostCount,
this.messageAutoDeleteTime,
this.hasAggressiveAntiSpamEnabled,
this.hasHiddenMembers,
this.hasProtectedContent,
this.hasVisibleHistory,
this.stickerSetName,
this.canSetStickerSet,
this.customEmojiStickerSetName,
this.linkedChatId,
this.location,
});
Expand Down Expand Up @@ -270,13 +284,15 @@ class Chat {
pinnedMessage: callIfNotNull(Message.fromJson, json['pinned_message']),
permissions: callIfNotNull(ChatPermissions.fromJson, json['permissions']),
slowModeDelay: json['slow_mode_delay'],
unrestrictBoostCount: json['unrestrict_boost_count'],
messageAutoDeleteTime: json['message_auto_delete_time'],
hasAggressiveAntiSpamEnabled: json['has_aggressive_anti_spam_enabled'],
hasHiddenMembers: json['has_hidden_members'],
hasProtectedContent: json['has_protected_content'],
hasVisibleHistory: json['has_visible_history'],
stickerSetName: json['sticker_set_name'],
canSetStickerSet: json['can_set_sticker_set'],
customEmojiStickerSetName: json['custom_emoji_sticker_set_name'],
linkedChatId: json['linked_chat_id'],
location: callIfNotNull(ChatLocation.fromJson, json['location']),
);
Expand Down Expand Up @@ -317,13 +333,15 @@ class Chat {
'pinned_message': pinnedMessage,
'permissions': permissions,
'slow_mode_delay': slowModeDelay,
'unrestrict_boost_count': unrestrictBoostCount,
'message_auto_delete_time': messageAutoDeleteTime,
'has_aggressive_anti_spam_enabled': hasAggressiveAntiSpamEnabled,
'has_hidden_members': hasHiddenMembers,
'has_protected_content': hasProtectedContent,
'has_visible_history': hasVisibleHistory,
'sticker_set_name': stickerSetName,
'can_set_sticker_set': canSetStickerSet,
'custom_emoji_sticker_set_name': customEmojiStickerSetName,
'linked_chat_id': linkedChatId,
'location': location,
}..removeWhere((_, v) => v == null);
Expand Down
27 changes: 27 additions & 0 deletions lib/src/entities/telegram/chat_boost_added.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'dart:convert';

/// This object represents a service message about a user boosting a chat.
class ChatBoostAdded {
/// Number of boosts added by the user
int boostCount;

/// Basic constructor
ChatBoostAdded(this.boostCount);

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

/// Creates a json from the object
Map toJson() {
return {
'boost_count': boostCount,
};
}

@override
String toString() => json.encode(this);
}
10 changes: 5 additions & 5 deletions lib/src/entities/telegram/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class UpdateType extends _Enum<String> {
..toList();
}

const UpdateType._(String value) : super(value);
const UpdateType._(super.value);

/// Get the object from string
static UpdateType forValue(String value) => UpdateType.values[value]!;
Expand All @@ -123,7 +123,7 @@ class ParseMode extends _Enum<String> {
'html': html,
};

const ParseMode._(String value) : super(value);
const ParseMode._(super.value);

/// Get the object from string
static ParseMode forValue(String value) => ParseMode.values[value]!;
Expand All @@ -143,7 +143,7 @@ class PollType extends _Enum<String> {
'quiz': quiz,
};

const PollType._(String value) : super(value);
const PollType._(super.value);

/// Get the object from string
static PollType forValue(String value) => PollType.values[value]!;
Expand Down Expand Up @@ -199,7 +199,7 @@ class ChatAction extends _Enum<String> {
'upload_video_note': uploadVideoNote,
};

const ChatAction._(String value) : super(value);
const ChatAction._(super.value);

/// Get the object from string
static ChatAction forValue(String value) => ChatAction.values[value]!;
Expand Down Expand Up @@ -235,7 +235,7 @@ class Emoji extends _Enum<String> {
'🎰': casino,
};

const Emoji._(String value) : super(value);
const Emoji._(super.value);

/// Get the object from string
static Emoji forValue(String value) => Emoji.values[value]!;
Expand Down
25 changes: 25 additions & 0 deletions lib/src/entities/telegram/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class Message extends MaybeInaccessibleMessage {
/// non-channel chats, if the message was sent on behalf of a chat.
Chat? senderChat;

/// Optional.
/// If the sender of the message boosted the chat,
/// the number of boosts added by the user
int? senderBoostCount;

/// Date the message was sent in Unix time
@override
int date;
Expand Down Expand Up @@ -66,6 +71,10 @@ class Message extends MaybeInaccessibleMessage {
/// the quoted part of the message
TextQuote? quote;

/// Optional.
/// For replies to a story, the original story
Story? replyToStory;

/// Optional.
/// Bot through which the message was sent
User? viaBot;
Expand Down Expand Up @@ -282,6 +291,10 @@ class Message extends MaybeInaccessibleMessage {
/// alert while sharing Live Location.
ProximityAlertTriggered? proximityAlertTriggered;

/// Optional.
/// Service message: user boosted the chat
ChatBoostAdded? boostAdded;

/// Optional.
/// Service message: forum topic created
ForumTopicCreated? forumTopicCreated;
Expand Down Expand Up @@ -353,6 +366,7 @@ class Message extends MaybeInaccessibleMessage {
this.messageThreadId,
this.from,
this.senderChat,
this.senderBoostCount,
required this.date,
required this.chat,
this.forwardOrigin,
Expand All @@ -361,6 +375,7 @@ class Message extends MaybeInaccessibleMessage {
this.replyToMessage,
this.externalReply,
this.quote,
this.replyToStory,
this.viaBot,
this.editDate,
this.hasProtectedContent,
Expand Down Expand Up @@ -406,6 +421,7 @@ class Message extends MaybeInaccessibleMessage {
this.connectedWebsite,
this.passportData,
this.proximityAlertTriggered,
this.boostAdded,
this.forumTopicCreated,
this.forumTopicClosed,
this.forumTopicReopened,
Expand All @@ -430,6 +446,7 @@ class Message extends MaybeInaccessibleMessage {
messageThreadId: json['message_thread_id'],
from: callIfNotNull(User.fromJson, json['from']),
senderChat: callIfNotNull(Chat.fromJson, json['sender_chat']),
senderBoostCount: json['sender_boost_count'],
date: json['date']!,
chat: Chat.fromJson(json['chat']!),
forwardOrigin: callIfNotNull(
Expand All @@ -447,6 +464,7 @@ class Message extends MaybeInaccessibleMessage {
json['external_reply'],
),
quote: callIfNotNull(TextQuote.fromJson, json['quote']),
replyToStory: callIfNotNull(Story.fromJson, json['reply_to_story']),
viaBot: callIfNotNull(User.fromJson, json['via_bot']),
editDate: json['edit_date'],
hasProtectedContent: json['has_protected_content'],
Expand Down Expand Up @@ -531,6 +549,10 @@ class Message extends MaybeInaccessibleMessage {
ProximityAlertTriggered.fromJson,
json['proximity_alert_triggered'],
),
boostAdded: callIfNotNull(
ChatBoostAdded.fromJson,
json['boost_added'],
),
forumTopicCreated: callIfNotNull(
ForumTopicCreated.fromJson,
json['forum_topic_created'],
Expand Down Expand Up @@ -609,6 +631,7 @@ class Message extends MaybeInaccessibleMessage {
'message_thread_id': messageThreadId,
'from': from,
'sender_chat': senderChat,
'sender_boost_count': senderBoostCount,
'date': date,
'chat': chat,
'forward_origin': forwardOrigin,
Expand All @@ -617,6 +640,7 @@ class Message extends MaybeInaccessibleMessage {
'reply_to_message': replyToMessage,
'external_reply': externalReply,
'quote': quote,
'reply_to_story': replyToStory,
'via_bot': viaBot,
'edit_date': editDate,
'has_protected_content': hasProtectedContent,
Expand Down Expand Up @@ -662,6 +686,7 @@ class Message extends MaybeInaccessibleMessage {
'connected_website': connectedWebsite,
'passport_data': passportData,
'proximity_alert_triggered': proximityAlertTriggered,
'boost_added': boostAdded,
'forum_topic_created': forumTopicCreated,
'forum_topic_closed': forumTopicClosed,
'forum_topic_reopened': forumTopicReopened,
Expand Down
28 changes: 22 additions & 6 deletions lib/src/entities/telegram/story.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
import 'dart:convert';

/// This object represents a message about a forwarded story in the chat
/// Currently holds no information.
import '../../../telegram_entities.dart';

/// This object represents a story.
class Story {
/// Chat that posted the story
Chat chat;

/// Unique identifier for the story in the chat
int id;

/// Basic constructor
Story();
Story(
this.chat,
this.id,
);

/// Creates a object from a json
factory Story.fromJson(Map<String, dynamic> _) {
return Story();
factory Story.fromJson(Map<String, dynamic> json) {
return Story(
Chat.fromJson(json['chat']),
json['id'],
);
}

/// Creates a json from the object
Map toJson() {
return {};
return {
'chat': chat,
'id': id,
};
}

@override
Expand Down
1 change: 1 addition & 0 deletions lib/telegram_entities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export 'src/entities/telegram/callback_query.dart';
export 'src/entities/telegram/chat.dart';
export 'src/entities/telegram/chat_administrator_rights.dart';
export 'src/entities/telegram/chat_boost.dart';
export 'src/entities/telegram/chat_boost_added.dart';
export 'src/entities/telegram/chat_boost_removed.dart';
export 'src/entities/telegram/chat_boost_source.dart';
export 'src/entities/telegram/chat_boost_source_gift_code.dart';
Expand Down
10 changes: 5 additions & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: dart_telegram_bot
description: A Telegram Bot API wrapper made to make fast Telegram bots with as less code as possible.
version: 1.2.0
version: 1.3.0
homepage: https://github.com/KaikyuDev/dart-telegram-bot

environment:
sdk: '>=2.15.0 <4.0.0'
sdk: '>=2.17.7 <4.0.0'

dependencies:
http: ^1.0.0
logging: ^1.0.1
http: ^1.2.1
logging: ^1.2.0

dev_dependencies:
lints: ^3.0.0
test: ^1.16.0
test: ^1.25.3

0 comments on commit 4fa972a

Please sign in to comment.