Skip to content

Commit

Permalink
Merge pull request #38 from LuongTienThinh/feat/verify-system
Browse files Browse the repository at this point in the history
feat: add verify_system to work correctly on window and linux
  • Loading branch information
tanhongit authored Jan 25, 2024
2 parents 50951d2 + 78e1950 commit 349d959
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions config/tg-notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
'url' => $_ENV['TGN_APP_URL'] ?? 'http://localhost:3000',

'timezone' => $_ENV['TIMEZONE'] ?? 'Asia/Ho_Chi_Minh',

'request_verify' => $_ENV['TGN_REQUEST_VERIFY'] ?? false,
],

'bot' => [
Expand Down
7 changes: 5 additions & 2 deletions src/Structures/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 16 additions & 4 deletions src/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.request_verify'),
];

try {
$response = $this->client->request('GET', $url);
$response = $this->client->request('GET', $url, $options);

return $response->getBody()->getContents();
} catch (GuzzleException) {
Expand All @@ -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.request_verify'),
];

try {
$response = $this->client->request('GET', $url);
$response = $this->client->request('GET', $url, $options);

return $response->getBody()->getContents();
} catch (GuzzleException) {
Expand All @@ -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.request_verify'),
];

try {
$response = $this->client->request('GET', $url);
$response = $this->client->request('GET', $url, $options);

return $response->getBody()->getContents();
} catch (GuzzleException) {
Expand All @@ -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.request_verify'),
];

try {
$response = $this->client->request('GET', $url);
$response = $this->client->request('GET', $url, $options);

return $response->getBody()->getContents();
} catch (GuzzleException) {
Expand Down

0 comments on commit 349d959

Please sign in to comment.