Skip to content

Commit

Permalink
Feature/0.6.2 (#267)
Browse files Browse the repository at this point in the history
* ✏️ Exports `HttpClientException`

* 🚧 Deleted test file

* 🚚 Rename & added one test

* Fix #263: Message updating methods now return `dynamic`

* Fix #265: Update the `stopPoll` method

* version bump

---------

Co-authored-by: Sreelal TS <heysreelal@gmail.com>
  • Loading branch information
DinoLeung and HeySreelal authored Feb 17, 2024
1 parent d0b8ec1 commit b87fab9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 48 deletions.
60 changes: 25 additions & 35 deletions lib/src/telegram/telegram.dart
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ class Telegram {
/// https://core.telegram.org/bots/api#editmessagelivelocation
///
/// [inline bots]: https://core.telegram.org/bots/api#inline-mode
Future<Message> editMessageLiveLocation(double latitude, double longitude,
Future<dynamic> editMessageLiveLocation(double latitude, double longitude,
{dynamic chatId,
int? messageId,
String? inlineMessageId,
Expand Down Expand Up @@ -872,7 +872,10 @@ class Telegram {
'proximity_alert_radius': proximityAlertRadius,
'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup),
};
return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body));

final res = await HttpClient.httpPost(requestUrl, body: body);

return res is bool ? res : Message.fromJson(res);
}

/// Use this method to stop updating a live location message sent by the bot or via the bot
Expand All @@ -884,7 +887,7 @@ class Telegram {
/// https://core.telegram.org/bots/api#stopmessagelivelocation
///
/// [inline bots]: https://core.telegram.org/bots/api#inline-mode
Future<Message> stopMessageLiveLocation(
Future<dynamic> stopMessageLiveLocation(
{dynamic chatId,
int? messageId,
String? inlineMessageId,
Expand All @@ -904,7 +907,10 @@ class Telegram {
'inline_message_id': inlineMessageId,
'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup),
};
return Message.fromJson(await HttpClient.httpPost(requestUrl, body: body));

final res = await HttpClient.httpPost(requestUrl, body: body);

return res is bool ? res : Message.fromJson(res);
}

/// Use this method to send information about a venue
Expand Down Expand Up @@ -2260,7 +2266,7 @@ class Telegram {
/// https://core.telegram.org/bots/api#editmessagetext
///
/// [inline bots]: https://core.telegram.org/bots/api#inline-mode
Future<Message> editMessageText(String text,
Future<dynamic> editMessageText(String text,
{dynamic chatId,
int? messageId,
String? inlineMessageId,
Expand All @@ -2286,12 +2292,7 @@ class Telegram {
'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup),
};
var res = await HttpClient.httpPost(requestUrl, body: body);
if (res == true) {
return Future.error(
TelegramException('Edited message is NOT sent by the bot'));
} else {
return Message.fromJson(res);
}
return res == true ? res : Message.fromJson(res);
}

/// Use this method to edit captions of messages sent by the bot or via the bot
Expand All @@ -2303,7 +2304,7 @@ class Telegram {
/// https://core.telegram.org/bots/api#editmessagecaption
///
/// [inline bots]: https://core.telegram.org/bots/api#inline-mode
Future<Message> editMessageCaption(
Future<dynamic> editMessageCaption(
{dynamic chatId,
int? messageId,
String? inlineMessageId,
Expand All @@ -2328,12 +2329,7 @@ class Telegram {
'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup),
};
var res = await HttpClient.httpPost(requestUrl, body: body);
if (res == true) {
return Future.error(
TelegramException('Edited message is NOT sent by the bot'));
} else {
return Message.fromJson(res);
}
return res == true ? res : Message.fromJson(res);
}

/// Use this method to edit audio, document, photo, or video messages
Expand All @@ -2347,7 +2343,7 @@ class Telegram {
/// otherwise *True* is returned.
///
/// https://core.telegram.org/bots/api#editMessageMedia
Future<Message> editMessageMedia(
Future<dynamic> editMessageMedia(
{dynamic chatId,
int? messageId,
String? inlineMessageId,
Expand Down Expand Up @@ -2384,12 +2380,7 @@ class Telegram {
: await HttpClient.httpMultipartPost(requestUrl, multiPartFiles,
body: body);

if (res == true) {
return Future.error(
TelegramException('Edited message is NOT sent by the bot'));
} else {
return Message.fromJson(res);
}
return res == true ? res : Message.fromJson(res);
}

/// Use this method to edit only the reply markup of messages sent by the bot or via the bot
Expand All @@ -2401,7 +2392,7 @@ class Telegram {
/// https://core.telegram.org/bots/api#editmessagereplymarkup
///
/// [inline bots]: https://core.telegram.org/bots/api#inline-mode
Future<Message> editMessageReplyMarkup(
Future<dynamic> editMessageReplyMarkup(
{dynamic chatId,
int? messageId,
String? inlineMessageId,
Expand All @@ -2422,12 +2413,8 @@ class Telegram {
'reply_markup': replyMarkup == null ? null : jsonEncode(replyMarkup),
};
var res = await HttpClient.httpPost(requestUrl, body: body);
if (res == true) {
return Future.error(
TelegramException('Edited message is NOT sent by the bot'));
} else {
return Message.fromJson(res);
}

return res == true ? res : Message.fromJson(res);
}

/// Use this method to stop a poll which was sent by the bot
Expand All @@ -2436,7 +2423,10 @@ class Telegram {
///
/// https://core.telegram.org/bots/api#stoppoll
Future<Poll> stopPoll(
dynamic chatId, int messageId, InlineKeyboardMarkup replyMarkup) async {
dynamic chatId,
int messageId, {
InlineKeyboardMarkup? replyMarkup,
}) async {
if (chatId is! String && chatId is! int) {
return Future.error(TelegramException(
'Attribute \'chatId\' can only be either type of String or int'));
Expand All @@ -2445,7 +2435,7 @@ class Telegram {
var body = <String, dynamic>{
'chat_id': chatId,
'message_id': messageId,
'reply_markup': replyMarkup,
'reply_markup': replyMarkup != null ? jsonEncode(replyMarkup) : null,
};
return Poll.fromJson(await HttpClient.httpPost(requestUrl, body: body));
}
Expand Down Expand Up @@ -2817,7 +2807,7 @@ class Telegram {
/// On success, a [SentWebAppMessage] object is returned.
///
/// https://core.telegram.org/bots/api#answerwebappquery
///
///
/// [Web App]: (https://core.telegram.org/bots/webapps)
Future<SentWebAppMessage> answerWebAppQuery(
String webAppQueryId, InlineQueryResult result) async {
Expand Down
1 change: 1 addition & 0 deletions lib/teledart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ export 'src/teledart/event/event.dart';
export 'src/teledart/fetch/abstract_update_fetcher.dart';
export 'src/teledart/fetch/long_polling.dart';
export 'src/teledart/fetch/webhook.dart';
export 'src/util/http_client.dart' show HttpClientException;
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: teledart
description: A Dart library interfacing with the latest Telegram Bot API.
version: 0.6.1
version: 0.6.2
homepage: https://github.com/DinoLeung/TeleDart
issue_tracker: https://github.com/DinoLeung/TeleDart/issues

Expand Down
12 changes: 0 additions & 12 deletions test/TeleDart_test.dart

This file was deleted.

22 changes: 22 additions & 0 deletions test/teledart_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'dart:io';

import 'package:teledart/teledart.dart';
import 'package:test/test.dart';

void main() {
TeleDart teleDart = TeleDart(
Platform.environment["BOT_TOKEN"]!,
Event(Platform.environment["BOT_USERNAME"] ?? ""),
);
group('Senders', () {
setUp(() {});

test('sendMessage', () async {
final msg = await teleDart.sendMessage(
Platform.environment["CHAT_ID"]!,
"Hello World!",
);
expect(msg.text, "Hello World!");
});
});
}

0 comments on commit b87fab9

Please sign in to comment.