Skip to content

Commit 8bd8e62

Browse files
authored
Merge pull request #27 from tanhongit/develop
Develop
2 parents 3fc983f + 12609cd commit 8bd8e62

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

index.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use GuzzleHttp\Exception\GuzzleException;
34
use TelegramGithubNotify\App\Http\Actions\SendNotifyAction;
45
use Dotenv\Dotenv;
56

@@ -10,5 +11,9 @@
1011

1112
date_default_timezone_set(config('app.timezone'));
1213

13-
$sendNotifyAction = new SendNotifyAction();
14-
$sendNotifyAction();
14+
try {
15+
$sendNotifyAction = new SendNotifyAction();
16+
$sendNotifyAction();
17+
} catch (GuzzleException $e) {
18+
error_log('\nError: ' . $e->getMessage());
19+
}

src/Http/Actions/SendNotifyAction.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,33 @@ public function __construct()
3030
* Handle send notify to telegram action
3131
*
3232
* @return void
33+
* @throws GuzzleException
3334
*/
3435
public function __invoke(): void
3536
{
3637
$this->telegramService->checkCallback();
3738
$chatMessageId = $this->telegramService->messageData['message']['chat']['id'] ?? '';
3839

39-
// Send a result to only the bot owner
40-
if (!empty($chatMessageId) && $chatMessageId == $this->telegramService->chatId) {
41-
$this->telegramService->telegramToolHandler($this->telegramService->messageData['message']['text']);
42-
return;
40+
if (!empty($chatMessageId)) {
41+
// Send a result to only the bot owner
42+
if ($chatMessageId == $this->telegramService->chatId) {
43+
$this->telegramService->telegramToolHandler($this->telegramService->messageData['message']['text']);
44+
return;
45+
}
46+
47+
// Notify access denied to other chat ids
48+
if (!in_array($chatMessageId, $this->chatIds)) {
49+
$this->notificationService->accessDenied($this->telegramService);
50+
return;
51+
}
4352
}
4453

4554
// Send a result to all chat ids in config
46-
try {
55+
if (!is_null($this->request->server->get('HTTP_X_GITHUB_EVENT')) && empty($chatMessageId)) {
4756
$this->notificationService->setPayload($this->request);
4857
foreach ($this->chatIds as $chatId) {
4958
$this->notificationService->sendNotify($chatId);
5059
}
51-
} catch (GuzzleException $e) {
52-
error_log($e->getMessage());
53-
$this->notificationService->accessDenied($this->telegramService); // Notify access denied to other chat ids
5460
}
5561
}
5662
}

0 commit comments

Comments
 (0)