|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Skater4\LaravelSentryNotifications\Providers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Application; |
|
6
|
|
|
use Illuminate\Notifications\Notification; |
|
7
|
|
|
use Illuminate\Support\ServiceProvider; |
|
8
|
|
|
use Skater4\LaravelSentryNotifications\Exceptions\SentryNotifierException; |
|
9
|
|
|
use Skater4\LaravelSentryNotifications\Notifications\Services\Telegram\Entities\NotifableTelegramChannel; |
|
10
|
|
|
use Skater4\LaravelSentryNotifications\Notifications\Services\Telegram\TelegramSentryNotification; |
|
11
|
|
|
use Skater4\LaravelSentryNotifications\Services\Messengers\Clients\Telegram\TelegramClient; |
|
12
|
|
|
use Skater4\LaravelSentryNotifications\Services\Messengers\Clients\Telegram\TelegramMessageFormatter; |
|
13
|
|
|
use Skater4\LaravelSentryNotifications\Services\Messengers\Interfaces\MessageFormatterInterface; |
|
14
|
|
|
|
|
15
|
|
|
class TelegramServiceProvider extends ServiceProvider |
|
16
|
|
|
{ |
|
17
|
|
|
public function register(): void |
|
18
|
|
|
{ |
|
19
|
|
|
$this->mergeConfigFrom( |
|
20
|
|
|
__DIR__ . '/../../config/services.php', 'services' |
|
21
|
|
|
); |
|
22
|
|
|
|
|
23
|
|
|
$this->app->when(TelegramClient::class) |
|
24
|
|
|
->needs(MessageFormatterInterface::class) |
|
25
|
|
|
->give(TelegramMessageFormatter::class); |
|
26
|
|
|
|
|
27
|
|
|
$this->app->bind(NotifableTelegramChannel::class, function (Application $app) { |
|
28
|
|
|
if (empty($app['config']['services']['laravel-sentry-notifications']['telegram']['chat_id'])) { |
|
29
|
|
|
throw new SentryNotifierException('Empty telegram Chat ID'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if (empty($app['config']['services']['telegram-bot-api']['token'])) { |
|
33
|
|
|
throw new SentryNotifierException('Empty telegram bit token'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
return new NotifableTelegramChannel($app['config']['services']['laravel-sentry-notifications']['telegram']['chat_id']); |
|
37
|
|
|
}); |
|
38
|
|
|
|
|
39
|
|
|
$this->app->when(TelegramClient::class) |
|
40
|
|
|
->needs(Notification::class) |
|
41
|
|
|
->give(TelegramSentryNotification::class); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|