Skip to content

Commit c0deeb0

Browse files
authored
Merge pull request #122 from irazasyed/improvement
Improvements
2 parents 26a736d + ee7eb16 commit c0deeb0

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ Then, configure your Telegram Bot API Token:
5757

5858
#### (Optional) Proxy or Bridge Support
5959

60-
You may not be able to send notifications if Telegram Bot API is not accessible in your country,
61-
you can either set a proxy by following the instructions [here](http://docs.guzzlephp.org/en/stable/quickstart.html#environment-variables) or
60+
You may not be able to send notifications if Telegram Bot API is not accessible in your country,
61+
you can either set a proxy by following the instructions [here](http://docs.guzzlephp.org/en/stable/quickstart.html#environment-variables) or
6262
use a web bridge by setting the `base_uri` config above with the bridge uri.
6363

6464
You can set `HTTPS_PROXY` in your `.env` file.
@@ -89,10 +89,10 @@ class InvoicePaid extends Notification
8989
->to($notifiable->telegram_user_id)
9090
// Markdown supported.
9191
->content("Hello there!\nYour invoice has been *PAID*")
92-
92+
9393
// (Optional) Blade template for the content.
9494
// ->view('notification', ['url' => $url])
95-
95+
9696
// (Optional) Inline Buttons
9797
->button('View Invoice', $url)
9898
->button('Download Invoice', $url)
@@ -213,11 +213,9 @@ For a complete list of response fields, please refer the Telegram Bot API's [Mes
213213

214214
### On-Demand Notifications
215215

216-
> Sometimes you may need to send a notification to someone who is not stored as a "user" of your application. Using the `Notification::route` method, you may specify ad-hoc notification routing information before sending the notification. For more details, you can check out the [on-demand notifications](https://laravel.com/docs/5.8/notifications#on-demand-notifications) docs.
216+
> Sometimes you may need to send a notification to someone who is not stored as a "user" of your application. Using the `Notification::route` method, you may specify ad-hoc notification routing information before sending the notification. For more details, you can check out the [on-demand notifications](https://laravel.com/docs/8.x/notifications#mailables-and-on-demand-notifications) docs.
217217
218218
```php
219-
use NotificationChannels\Telegram\TelegramChannel;
220-
221219
Notification::route('telegram', 'TELEGRAM_CHAT_ID')
222220
->notify(new InvoicePaid($invoice));
223221
```

src/TelegramChannel.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public function send($notifiable, Notification $notification): ?array
5252
}
5353

5454
if ($message->toNotGiven()) {
55-
if (! $to = $notifiable->routeNotificationFor('telegram', $notification)) {
55+
$to = $notifiable->routeNotificationFor('telegram', $notification)
56+
?? $notifiable->routeNotificationFor(self::class, $notification);
57+
58+
if (! $to) {
5659
return null;
5760
}
5861

src/TelegramServiceProvider.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace NotificationChannels\Telegram;
44

55
use GuzzleHttp\Client as HttpClient;
6-
use Illuminate\Contracts\Events\Dispatcher;
76
use Illuminate\Notifications\ChannelManager;
87
use Illuminate\Support\Facades\Notification;
98
use Illuminate\Support\ServiceProvider;
@@ -34,16 +33,9 @@ public function boot(): void
3433
*/
3534
public function register()
3635
{
37-
Notification::resolved(function (ChannelManager $service) {
38-
$service->extend('telegram', function ($app) {
39-
return new TelegramChannel(
40-
new Telegram(
41-
config('services.telegram-bot-api.token'),
42-
app(HttpClient::class),
43-
config('services.telegram-bot-api.base_uri')
44-
),
45-
app(Dispatcher::class)
46-
);
36+
Notification::resolved(static function (ChannelManager $service) {
37+
$service->extend('telegram', static function ($app) {
38+
return $app->make(TelegramChannel::class);
4739
});
4840
});
4941
}

0 commit comments

Comments
 (0)