|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CSlant\LaravelTelegramGitNotifier\Http\Actions; |
|
4
|
|
|
|
|
5
|
|
|
use CSlant\LaravelTelegramGitNotifier\Services\CallbackService; |
|
6
|
|
|
use CSlant\LaravelTelegramGitNotifier\Services\CommandService; |
|
7
|
|
|
use CSlant\LaravelTelegramGitNotifier\Services\NotificationService; |
|
8
|
|
|
use CSlant\TelegramGitNotifier\Bot; |
|
9
|
|
|
use CSlant\TelegramGitNotifier\Exceptions\BotException; |
|
10
|
|
|
use CSlant\TelegramGitNotifier\Exceptions\CallbackException; |
|
11
|
|
|
use CSlant\TelegramGitNotifier\Exceptions\ConfigFileException; |
|
12
|
|
|
use CSlant\TelegramGitNotifier\Exceptions\EntryNotFoundException; |
|
13
|
|
|
use CSlant\TelegramGitNotifier\Exceptions\InvalidViewTemplateException; |
|
14
|
|
|
use CSlant\TelegramGitNotifier\Exceptions\MessageIsEmptyException; |
|
15
|
|
|
use CSlant\TelegramGitNotifier\Exceptions\SendNotificationException; |
|
16
|
|
|
use CSlant\TelegramGitNotifier\Notifier; |
|
17
|
|
|
use GuzzleHttp\Client; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
19
|
|
|
use Telegram; |
|
20
|
|
|
|
|
21
|
|
|
class IndexAction |
|
22
|
|
|
{ |
|
23
|
|
|
protected Client $client; |
|
24
|
|
|
|
|
25
|
|
|
protected Bot $bot; |
|
26
|
|
|
|
|
27
|
|
|
protected Notifier $notifier; |
|
28
|
|
|
|
|
29
|
|
|
protected Request $request; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @throws ConfigFileException |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->client = new Client(); |
|
37
|
|
|
|
|
38
|
|
|
$telegram = new Telegram(config('telegram-git-notifier.bot.token')); |
|
39
|
|
|
$this->bot = new Bot($telegram); |
|
40
|
|
|
$this->notifier = new Notifier(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Handle telegram git notifier app. |
|
45
|
|
|
* |
|
46
|
|
|
* @return void |
|
47
|
|
|
* |
|
48
|
|
|
* @throws InvalidViewTemplateException |
|
49
|
|
|
* @throws MessageIsEmptyException |
|
50
|
|
|
* @throws SendNotificationException |
|
51
|
|
|
* @throws BotException |
|
52
|
|
|
* @throws CallbackException |
|
53
|
|
|
* @throws EntryNotFoundException |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __invoke(): void |
|
56
|
|
|
{ |
|
57
|
|
|
if ($this->bot->isCallback()) { |
|
58
|
|
|
$callbackAction = new CallbackService($this->bot); |
|
59
|
|
|
$callbackAction->handle(); |
|
60
|
|
|
|
|
61
|
|
|
return; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if ($this->bot->isMessage() && $this->bot->isOwner()) { |
|
65
|
|
|
$commandAction = new CommandService($this->bot); |
|
66
|
|
|
$commandAction->handle(); |
|
67
|
|
|
|
|
68
|
|
|
return; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$sendNotification = new NotificationService( |
|
72
|
|
|
$this->notifier, |
|
73
|
|
|
$this->bot->setting |
|
74
|
|
|
); |
|
75
|
|
|
$sendNotification->handle(); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|