Skip to content

Commit

Permalink
Merge #289: v1.23.1
Browse files Browse the repository at this point in the history
Refactors and Docs Stuff
  • Loading branch information
HeySreelal committed Aug 9, 2024
2 parents 3234659 + 58f8056 commit fe5f3d6
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 8 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.23.1

- Exposed couple of more properties in Context
- Added `Bot.additionalInfo`
- Documentation website is up.

# 1.23.0

- 🤖 Bot API 7.8
Expand Down Expand Up @@ -71,7 +77,7 @@

- 🥳 Support for Custom Context
- Added detailed
[usage documentation for custom context here](https://televerse.web.app/doc/custom-context).
[usage documentation for custom context here](https://televerse.xooniverse.com/advanced/custom-context.html).
- The custom context feature allows you to extend the base functionality of your
bot by using your own custom context classes.
- Added `Bot.contextBuilder` method
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ With the new `Bot.contextBuilder` method, you can define specialized context
constructors to create context objects with personalized behaviors and
capabilities. This update allows you to tailor your bot's responses, handle
complex workflows, and integrate additional features seamlessly.
[Read more here.](https://televerse.xooniverse.com/doc/custom-context)
[Read more here.](https://televerse.xooniverse.com/advanced/custom-context.html)

<hr>

Expand Down
19 changes: 14 additions & 5 deletions lib/src/televerse/bot/bot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Bot<CTX extends Context> {
/// Options to configure the logger.
final LoggerOptions? _loggerOptions;

/// Acts as the dfault error handler
void _defaultErrorHandler(BotError<CTX> err) {
print("‼️ An error occurred while processing the update.");
if (err.sourceIsMiddleware) {
Expand All @@ -48,6 +49,7 @@ class Bot<CTX extends Context> {
_report();
}

/// Prints the issue reporting statement
static void _report() {
print("---------------------");
print(
Expand Down Expand Up @@ -162,7 +164,7 @@ class Bot<CTX extends Context> {
}

/// Handles the error in initial `getMe` call
Future<void> _thenHandleGetMeError(Object err, StackTrace st) async {
Future<void> _handleTheGetMeError(Object err, StackTrace st) async {
if (err is DioException) {
if (err.type == DioExceptionType.connectionTimeout ||
err.type == DioExceptionType.receiveTimeout ||
Expand Down Expand Up @@ -244,7 +246,7 @@ class Bot<CTX extends Context> {
try {
await getMe();
} catch (err, st) {
_thenHandleGetMeError(err, st);
_handleTheGetMeError(err, st);
}
// Set instance variable
_instance = this;
Expand Down Expand Up @@ -403,6 +405,11 @@ class Bot<CTX extends Context> {
}
}
/// Additional infomration on the bot
///
/// This space can be used for plugins or any other utilities to improve user experience
final Map<String, dynamic> additionalInfo = {};
/// List of Handler Scopes
final List<HandlerScope<CTX>> _handlerScopes = [];
Expand Down Expand Up @@ -485,7 +492,7 @@ class Bot<CTX extends Context> {
/// bot.contextBuilder(MyCustomContext.new);
/// ```
///
/// For detailed usage instructions and examples, visit the [Custom Context Documentation](https://televerse.web.app/doc/custom-context).
/// For detailed usage instructions and examples, visit the [Custom Context Documentation](https://televerse.xooniverse.com/advanced/custom-context.html).
void contextBuilder(ContextConstructor<CTX> constructor) {
_usingCustomContext = true;
_contextConstructor = constructor;
Expand Down Expand Up @@ -550,7 +557,7 @@ class Bot<CTX extends Context> {
"If you still encounter issues, make sure that your custom context class extends `Context` "
"and its constructor matches the required parameters:\n\n"
" MyContext({required super.api, required super.me, required super.update});\n"
"📖 Check out the complete usage documentation here: https://televerse.web.app/doc/custom-context\n",
"📖 Check out the complete usage documentation here: https://televerse.xooniverse.com/advanced/custom-context.html \n",
);
}
Expand Down Expand Up @@ -578,7 +585,9 @@ class Bot<CTX extends Context> {
/// This method simply initalizes the bot - performs the initial getMe request
/// to fill the `bot.me` property.
Future<void> init() async {
await _initializeBot();
if (!initialized) {
await _initializeBot();
}
}
/// Start polling or webhook listener for fetching updates.
Expand Down
13 changes: 13 additions & 0 deletions lib/src/televerse/context/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ class Context {
msg?.sticker?.fileId;
}

/// The File ID if the incoming message contains a File of any kind.
///
/// This includes Photo, Animation, Audio, Document, Video, Video Note, Voice, or Sticker
String? get fileId => _fileId;

/// The Chat ID for internal use
int? get _chatId {
return chat?.id;
Expand All @@ -109,12 +114,20 @@ class Context {
callbackQuery?.message?.messageId;
}

/// The Message ID of the incoming message.
int? get messageId => _msgId;

/// Internal getter for inline message id
String? get _inlineMsgId {
return callbackQuery?.inlineMessageId ??
chosenInlineResult?.inlineMessageId;
}

/// Inline Message ID from the incoming update.
///
/// This can be Inline Message ID from a Callback Query generated from an inline message or Chosen Inline Result.
String? get inlineMessageId => _inlineMsgId;

/// Executes the middleware on the current context
Future<void> use(MiddlewareBase middleware) async {
if (middleware is Middleware) {
Expand Down
9 changes: 9 additions & 0 deletions lib/src/televerse/models/telegram_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,13 @@ class TelegramException implements Exception {
stackTrace: stackTrace,
);
}

/// Returns the JSON encodable Map
Map<String, dynamic> toJson() {
return {
"error_code": code,
"description": description,
"parameters": parameters?.toJson(),
}..removeWhere((_, v) => v != null);
}
}
10 changes: 10 additions & 0 deletions lib/televerse.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,35 @@ export 'src/televerse/links/links.dart';
export 'src/televerse/models/models.dart';
export 'src/types/types.dart';

// Bot & API
part 'src/televerse/api/raw_api.dart';
part 'src/televerse/bot/bot.dart';

// Context
part 'src/televerse/context/constructor.dart';
part 'src/televerse/context/context.dart';
part 'src/televerse/context/methods.dart';
part 'src/televerse/context/properties.dart';

// The On Method
part 'src/televerse/filters/filters.dart';
part 'src/televerse/filters/on.dart';

// Keyboards & Menus
part 'src/televerse/markups/inline_keyboard.dart';
part 'src/televerse/markups/inline_menu.dart';
part 'src/televerse/markups/keyboard.dart';
part 'src/televerse/markups/keyboard_menu.dart';
part 'src/televerse/markups/menu.dart';

// Other utilities
part 'src/televerse/models/logger_options.dart';
part 'src/televerse/models/multipart_helper.dart';
part 'src/utils/date.dart';
part 'src/utils/http.dart';
part 'src/utils/utils.dart';

// Fetchers
part 'src/televerse/fetch/fetch.dart';
part 'src/televerse/fetch/long_polling.dart';
part 'src/televerse/fetch/webhook.dart';
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.8!
version: 1.23.0
version: 1.23.1
homepage: https://televerse.xooniverse.com
repository: https://github.com/xooniverse/televerse
topics:
Expand Down

0 comments on commit fe5f3d6

Please sign in to comment.