From 72dab84c944b930166dc4b579918193a4fe5b189 Mon Sep 17 00:00:00 2001 From: LuongTienThinh Date: Thu, 25 Jan 2024 16:47:03 +0700 Subject: [PATCH 1/3] feat: add verify_system to work correctly on window and linux --- config/tg-notifier.php | 2 ++ src/Webhook.php | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/config/tg-notifier.php b/config/tg-notifier.php index 894ca7a..adcf24e 100644 --- a/config/tg-notifier.php +++ b/config/tg-notifier.php @@ -9,6 +9,8 @@ 'url' => $_ENV['TGN_APP_URL'] ?? 'http://localhost:3000', 'timezone' => $_ENV['TIMEZONE'] ?? 'Asia/Ho_Chi_Minh', + + 'verify_system' => $_ENV['VERIFY_SYSTEM'] ?? 'true', ], 'bot' => [ diff --git a/src/Webhook.php b/src/Webhook.php index 1ac9240..41e07c4 100644 --- a/src/Webhook.php +++ b/src/Webhook.php @@ -33,9 +33,12 @@ public function setUrl(string $url): void public function setWebhook(): string { $url = "https://api.telegram.org/bot{$this->token}/setWebhook?url={$this->url}"; + $options = [ + 'verify' => config('telegram-git-notifier.app.verify_system'), + ]; try { - $response = $this->client->request('GET', $url); + $response = $this->client->request('GET', $url, $options); return $response->getBody()->getContents(); } catch (GuzzleException) { @@ -46,9 +49,12 @@ public function setWebhook(): string public function deleteWebHook(): string { $url = "https://api.telegram.org/bot{$this->token}/deleteWebhook"; + $options = [ + 'verify' => config('telegram-git-notifier.app.verify_system'), + ]; try { - $response = $this->client->request('GET', $url); + $response = $this->client->request('GET', $url, $options); return $response->getBody()->getContents(); } catch (GuzzleException) { @@ -59,9 +65,12 @@ public function deleteWebHook(): string public function getWebHookInfo(): string { $url = "https://api.telegram.org/bot{$this->token}/getWebhookInfo"; + $options = [ + 'verify' => config('telegram-git-notifier.app.verify_system'), + ]; try { - $response = $this->client->request('GET', $url); + $response = $this->client->request('GET', $url, $options); return $response->getBody()->getContents(); } catch (GuzzleException) { @@ -72,9 +81,12 @@ public function getWebHookInfo(): string public function getUpdates(): string { $url = "https://api.telegram.org/bot{$this->token}/getUpdates"; + $options = [ + 'verify' => config('telegram-git-notifier.app.verify_system'), + ]; try { - $response = $this->client->request('GET', $url); + $response = $this->client->request('GET', $url, $options); return $response->getBody()->getContents(); } catch (GuzzleException) { From 44cc9e8a9c57e50efc6c8be2223c944e726701fc Mon Sep 17 00:00:00 2001 From: LuongTienThinh Date: Thu, 25 Jan 2024 17:27:54 +0700 Subject: [PATCH 2/3] refactor: rename request verify --- config/tg-notifier.php | 2 +- src/Structures/Notification.php | 7 +++++-- src/Webhook.php | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/config/tg-notifier.php b/config/tg-notifier.php index adcf24e..14535a8 100644 --- a/config/tg-notifier.php +++ b/config/tg-notifier.php @@ -10,7 +10,7 @@ 'timezone' => $_ENV['TIMEZONE'] ?? 'Asia/Ho_Chi_Minh', - 'verify_system' => $_ENV['VERIFY_SYSTEM'] ?? 'true', + 'request_verify' => $_ENV['TGN_REQUEST_VERIFY'] ?? 'true', ], 'bot' => [ diff --git a/src/Structures/Notification.php b/src/Structures/Notification.php index 4a6ce37..0f79066 100644 --- a/src/Structures/Notification.php +++ b/src/Structures/Notification.php @@ -90,9 +90,12 @@ public function sendNotify(string $message = null, array $options = []): bool $url = 'https://api.telegram.org/bot' . config('telegram-git-notifier.bot.token') . '/sendMessage'; try { - $response = $this->client->request('POST', $url, [ + $options = [ 'form_params' => $queryParams, - ]); + 'verify' => config('telegram-git-notifier.app.request_verify'), + ]; + + $response = $this->client->request('POST', $url, $options); if ($response->getStatusCode() === 200) { return true; diff --git a/src/Webhook.php b/src/Webhook.php index 41e07c4..bd4eb07 100644 --- a/src/Webhook.php +++ b/src/Webhook.php @@ -34,7 +34,7 @@ public function setWebhook(): string { $url = "https://api.telegram.org/bot{$this->token}/setWebhook?url={$this->url}"; $options = [ - 'verify' => config('telegram-git-notifier.app.verify_system'), + 'verify' => config('telegram-git-notifier.app.request_verify'), ]; try { @@ -50,7 +50,7 @@ public function deleteWebHook(): string { $url = "https://api.telegram.org/bot{$this->token}/deleteWebhook"; $options = [ - 'verify' => config('telegram-git-notifier.app.verify_system'), + 'verify' => config('telegram-git-notifier.app.request_verify'), ]; try { @@ -66,7 +66,7 @@ public function getWebHookInfo(): string { $url = "https://api.telegram.org/bot{$this->token}/getWebhookInfo"; $options = [ - 'verify' => config('telegram-git-notifier.app.verify_system'), + 'verify' => config('telegram-git-notifier.app.request_verify'), ]; try { @@ -82,7 +82,7 @@ public function getUpdates(): string { $url = "https://api.telegram.org/bot{$this->token}/getUpdates"; $options = [ - 'verify' => config('telegram-git-notifier.app.verify_system'), + 'verify' => config('telegram-git-notifier.app.request_verify'), ]; try { From 78e19500564b356e0da5618afa6ec342cafbf741 Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Thu, 25 Jan 2024 22:36:53 +0700 Subject: [PATCH 3/3] chore: update default value for the request verify env variable --- config/tg-notifier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/tg-notifier.php b/config/tg-notifier.php index 14535a8..3b731d0 100644 --- a/config/tg-notifier.php +++ b/config/tg-notifier.php @@ -10,7 +10,7 @@ 'timezone' => $_ENV['TIMEZONE'] ?? 'Asia/Ho_Chi_Minh', - 'request_verify' => $_ENV['TGN_REQUEST_VERIFY'] ?? 'true', + 'request_verify' => $_ENV['TGN_REQUEST_VERIFY'] ?? false, ], 'bot' => [