Skip to content

Commit 9179c45

Browse files
committed
Merge branch 'develop'
2 parents dac52e9 + e5f9068 commit 9179c45

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.4
2+
3+
- Webhook to throw error when `setWebhook` failed
4+
15
## 0.3.3
26

37
- Support API 5.7

lib/src/teledart/fetch/webhook.dart

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -126,35 +126,36 @@ class Webhook extends AbstractUpdateFetcher {
126126
allowed_updates: allowed_updates);
127127
}
128128

129-
Future<void> setWebhook() async {
130-
await telegram.setWebhook('$url:$port$secretPath',
131-
ip_address: ip_address,
132-
certificate: uploadCertificate ? certificate : null,
133-
max_connections: max_connections,
134-
allowed_updates: allowed_updates,
135-
drop_pending_updates: drop_pending_updates);
136-
}
129+
Future<bool> setWebhook() async =>
130+
await telegram.setWebhook('$url:$port$secretPath',
131+
ip_address: ip_address,
132+
certificate: uploadCertificate ? certificate : null,
133+
max_connections: max_connections,
134+
allowed_updates: allowed_updates,
135+
drop_pending_updates: drop_pending_updates);
137136

138137
/// Apply webhook configuration on Telegram API, and start the webhook server.
139138
@override
140139
Future<void> start() async {
141-
await setWebhook();
142-
143-
_server.listen((io.HttpRequest request) {
144-
if (request.method == 'POST' && request.uri.path == secretPath) {
145-
request.cast<List<int>>().transform(utf8.decoder).join().then((data) {
146-
emitUpdate(Update.fromJson(jsonDecode(data)));
140+
if (await setWebhook()) {
141+
_server.listen((io.HttpRequest request) {
142+
if (request.method == 'POST' && request.uri.path == secretPath) {
143+
request.cast<List<int>>().transform(utf8.decoder).join().then((data) {
144+
emitUpdate(Update.fromJson(jsonDecode(data)));
145+
request.response
146+
..write(jsonEncode({'ok': true}))
147+
..close();
148+
});
149+
} else {
147150
request.response
148-
..write(jsonEncode({'ok': true}))
151+
..statusCode = io.HttpStatus.methodNotAllowed
152+
..write(jsonEncode({'ok': false}))
149153
..close();
150-
});
151-
} else {
152-
request.response
153-
..statusCode = io.HttpStatus.methodNotAllowed
154-
..write(jsonEncode({'ok': false}))
155-
..close();
156-
}
157-
});
154+
}
155+
});
156+
} else {
157+
throw WebhookException('Telegram API returns an error while attempting to set the webhook.');
158+
}
158159
}
159160

160161
/// Remove webhook configuration from Telegram API, and stop the webhook server.

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: teledart
22
description: A Dart library interfacing with the latest Telegram Bot API.
3-
version: 0.3.3
3+
version: 0.3.4
44
homepage: https://github.com/DinoLeung/TeleDart
55
issue_tracker: https://github.com/DinoLeung/TeleDart/issues
66

0 commit comments

Comments
 (0)