From 8e968c91f5d412c0e2331e15f0194d85be0c1168 Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Sat, 4 Nov 2023 23:44:04 +0700 Subject: [PATCH 1/4] fix: update webhook request with exceptions --- .php-cs-fixer.dist.php | 1 + phpstan.neon.dist | 1 + src/Http/Actions/WebhookAction.php | 4 ++++ webhook/delete.php | 8 -------- webhook/getUpdate.php | 8 -------- webhook/set.php | 8 -------- webhooks/delete.php | 14 ++++++++++++++ webhooks/getUpdate.php | 14 ++++++++++++++ webhooks/set.php | 14 ++++++++++++++ 9 files changed, 48 insertions(+), 24 deletions(-) delete mode 100644 webhook/delete.php delete mode 100644 webhook/getUpdate.php delete mode 100644 webhook/set.php create mode 100644 webhooks/delete.php create mode 100644 webhooks/getUpdate.php create mode 100644 webhooks/set.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index cc7238f..98ff80d 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -3,6 +3,7 @@ $finder = Symfony\Component\Finder\Finder::create() ->in([ __DIR__ . '/src', + __DIR__ . '/webhooks', ]) ->name('*.php') ->ignoreDotFiles(true) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 2e837cd..a1d3a4a 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,5 +2,6 @@ parameters: level: 8 paths: - src + - webhooks tmpDir: build/phpstan checkMissingIterableValueType: false diff --git a/src/Http/Actions/WebhookAction.php b/src/Http/Actions/WebhookAction.php index 9c92b35..56cf2e7 100644 --- a/src/Http/Actions/WebhookAction.php +++ b/src/Http/Actions/WebhookAction.php @@ -2,6 +2,7 @@ namespace CSlant\TelegramGitNotifierApp\Http\Actions; +use CSlant\TelegramGitNotifier\Exceptions\WebhookException; use CSlant\TelegramGitNotifier\Webhook; class WebhookAction @@ -21,6 +22,7 @@ public function __construct() * Set webhook for telegram bot * * @return false|string + * @throws WebhookException */ public function set(): false|string { @@ -31,6 +33,7 @@ public function set(): false|string * Delete webhook for telegram bot * * @return false|string + * @throws WebhookException */ public function delete(): false|string { @@ -41,6 +44,7 @@ public function delete(): false|string * Get webhook update * * @return false|string + * @throws WebhookException */ public function getUpdates(): false|string { diff --git a/webhook/delete.php b/webhook/delete.php deleted file mode 100644 index a8874ae..0000000 --- a/webhook/delete.php +++ /dev/null @@ -1,8 +0,0 @@ -delete(); diff --git a/webhook/getUpdate.php b/webhook/getUpdate.php deleted file mode 100644 index bb58536..0000000 --- a/webhook/getUpdate.php +++ /dev/null @@ -1,8 +0,0 @@ -getUpdates(); diff --git a/webhook/set.php b/webhook/set.php deleted file mode 100644 index a55fae9..0000000 --- a/webhook/set.php +++ /dev/null @@ -1,8 +0,0 @@ -set(); diff --git a/webhooks/delete.php b/webhooks/delete.php new file mode 100644 index 0000000..c80913d --- /dev/null +++ b/webhooks/delete.php @@ -0,0 +1,14 @@ +delete(); +} catch (WebhookException $e) { + echo $e->getMessage(); +} diff --git a/webhooks/getUpdate.php b/webhooks/getUpdate.php new file mode 100644 index 0000000..5d14eb4 --- /dev/null +++ b/webhooks/getUpdate.php @@ -0,0 +1,14 @@ +getUpdates(); +} catch (WebhookException $e) { + echo $e->getMessage(); +} diff --git a/webhooks/set.php b/webhooks/set.php new file mode 100644 index 0000000..5a1ceaf --- /dev/null +++ b/webhooks/set.php @@ -0,0 +1,14 @@ +set(); +} catch (WebhookException $e) { + echo $e->getMessage(); +} From 024f17f86f27e5fa8a6f73183dadfc0696f327fe Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Wed, 8 Nov 2023 01:27:23 +0700 Subject: [PATCH 2/4] update license --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 8cc32b7..792c300 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Tan Nguyen +Copyright (c) 2023 CSlant Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From f40c6b588d9f413f069619aacc2f6a9b740d61ef Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Wed, 8 Nov 2023 01:27:41 +0700 Subject: [PATCH 3/4] update docblock --- .docker/conf.d/site.conf | 6 +++--- src/Http/Actions/IndexAction.php | 12 ++++++++++-- src/Services/CallbackService.php | 5 +++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.docker/conf.d/site.conf b/.docker/conf.d/site.conf index ad4cbcb..fa4e1ef 100755 --- a/.docker/conf.d/site.conf +++ b/.docker/conf.d/site.conf @@ -1,9 +1,9 @@ server { listen 80; - server_name telegram-nofity-bot.com; + server_name telegram-git-notifier.com; - error_log /var/log/nginx/telegram-nofity-bot-error.log; - access_log /var/log/nginx/telegram-nofity-bot-access.log; + error_log /var/log/nginx/telegram-git-notifier-error.log; + access_log /var/log/nginx/telegram-git-notifier-access.log; root /var/www/html/; index index.php index.html index.htm; diff --git a/src/Http/Actions/IndexAction.php b/src/Http/Actions/IndexAction.php index 1c51bb8..0944d74 100644 --- a/src/Http/Actions/IndexAction.php +++ b/src/Http/Actions/IndexAction.php @@ -3,6 +3,9 @@ namespace CSlant\TelegramGitNotifierApp\Http\Actions; use CSlant\TelegramGitNotifier\Bot; +use CSlant\TelegramGitNotifier\Exceptions\BotException; +use CSlant\TelegramGitNotifier\Exceptions\CallbackException; +use CSlant\TelegramGitNotifier\Exceptions\ConfigFileException; use CSlant\TelegramGitNotifier\Exceptions\EntryNotFoundException; use CSlant\TelegramGitNotifier\Exceptions\InvalidViewTemplateException; use CSlant\TelegramGitNotifier\Exceptions\MessageIsEmptyException; @@ -25,6 +28,9 @@ class IndexAction protected Request $request; + /** + * @throws ConfigFileException + */ public function __construct() { $this->client = new Client(); @@ -38,10 +44,12 @@ public function __construct() * Handle telegram git notifier app * * @return void - * @throws InvalidViewTemplateException - * @throws SendNotificationException * @throws EntryNotFoundException + * @throws InvalidViewTemplateException * @throws MessageIsEmptyException + * @throws SendNotificationException + * @throws BotException + * @throws CallbackException */ public function __invoke(): void { diff --git a/src/Services/CallbackService.php b/src/Services/CallbackService.php index ae649fb..03c5c5e 100644 --- a/src/Services/CallbackService.php +++ b/src/Services/CallbackService.php @@ -4,6 +4,8 @@ use CSlant\TelegramGitNotifier\Bot; use CSlant\TelegramGitNotifier\Constants\SettingConstant; +use CSlant\TelegramGitNotifier\Exceptions\BotException; +use CSlant\TelegramGitNotifier\Exceptions\CallbackException; use CSlant\TelegramGitNotifier\Exceptions\InvalidViewTemplateException; use CSlant\TelegramGitNotifier\Exceptions\MessageIsEmptyException; use CSlant\TelegramGitNotifierApp\Traits\Markup; @@ -26,6 +28,8 @@ public function __construct(Bot $bot) * * @return void * @throws MessageIsEmptyException + * @throws BotException + * @throws CallbackException */ public function answerBackButton(string $callback): void { @@ -67,6 +71,7 @@ public function answerBackButton(string $callback): void * @return void * @throws MessageIsEmptyException * @throws InvalidViewTemplateException + * @throws BotException|CallbackException */ public function handle(): void { From e073b1cb52d16a5349321096a5bcf1480251c5ab Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Wed, 8 Nov 2023 09:37:51 +0700 Subject: [PATCH 4/4] update docblock and readme --- README.md | 8 +++++--- src/Http/Actions/WebhookAction.php | 12 ++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b40d325..220e301 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ and manage customization through messages and buttons on Telegram. ![License](https://img.shields.io/github/license/cslant/telegram-git-notifier-app.svg?style=flat-square) [![Latest Version](https://img.shields.io/github/release/cslant/telegram-git-notifier-app.svg?style=flat-square)](https://github.com/cslant/telegram-git-notifier-app/releases) +![Test Status](https://img.shields.io/github/actions/workflow/status/cslant/telegram-git-notifier-app/setup_test.yml?label=tests&branch=main) +![Code Style Status](https://img.shields.io/github/actions/workflow/status/cslant/telegram-git-notifier-app/php-cs-fixer.yml?label=code%20style&branch=main) [![StyleCI](https://styleci.io/repos/656960426/shield)](https://styleci.io/repos/656960426) [![Quality Score](https://img.shields.io/scrutinizer/g/cslant/telegram-git-notifier-app.svg?style=flat-square)](https://scrutinizer-ci.com/g/cslant/telegram-git-notifier-app) [![Maintainability](https://api.codeclimate.com/v1/badges/7ccaccebe9cd58ff3df5/maintainability)](https://codeclimate.com/github/cslant/telegram-git-notifier-app/maintainability) @@ -131,7 +133,7 @@ TGN_APP_URL=https://123456789.ngrok.io 1. Open a chat with your bot. 2. Send any message to your bot. (This handle needs to get your chat ID) -3. Go to the following URL: `/webhook/getUpdate.php` +3. Go to the following URL: `/webhooks/getUpdate.php` 4. Look for the `"chat":{"id":` field and copy the number after it. This is your Chat ID. 5. Paste the Chat ID in your `.env` file. @@ -240,7 +242,7 @@ TGN_APP_URL=https://123456789.ngrok-free.app 1. Open a chat with your bot. 2. Send any message to your bot. (This handle needs to get your chat ID) -3. Go to the following URL: `/webhook/getUpdate.php` +3. Go to the following URL: `/webhooks/getUpdate.php` 4. Look for the `"chat":{"id":` field and copy the number after it. This is your Chat ID. 5. Paste the Chat ID in your `.env` file. @@ -261,7 +263,7 @@ After setting up your domain and SSL certificate, you need to set up the webhook **Go to:** ```text -/webhook/set.php +/webhooks/set.php ``` > **Note:** Replace `` with your app URL in .env file. diff --git a/src/Http/Actions/WebhookAction.php b/src/Http/Actions/WebhookAction.php index 56cf2e7..4bd933b 100644 --- a/src/Http/Actions/WebhookAction.php +++ b/src/Http/Actions/WebhookAction.php @@ -21,10 +21,10 @@ public function __construct() /** * Set webhook for telegram bot * - * @return false|string + * @return string * @throws WebhookException */ - public function set(): false|string + public function set(): string { return $this->webhook->setWebhook(); } @@ -32,10 +32,10 @@ public function set(): false|string /** * Delete webhook for telegram bot * - * @return false|string + * @return string * @throws WebhookException */ - public function delete(): false|string + public function delete(): string { return $this->webhook->deleteWebHook(); } @@ -43,10 +43,10 @@ public function delete(): false|string /** * Get webhook update * - * @return false|string + * @return string * @throws WebhookException */ - public function getUpdates(): false|string + public function getUpdates(): string { return $this->webhook->getUpdates(); }