Skip to content

Commit cfb0366

Browse files
authored
Merge pull request #104 from tanhongit/main
fix: update webhook request with exceptions
2 parents 750cf9f + e073b1c commit cfb0366

File tree

14 files changed

+78
-39
lines changed

14 files changed

+78
-39
lines changed

.docker/conf.d/site.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
server {
22
listen 80;
3-
server_name telegram-nofity-bot.com;
3+
server_name telegram-git-notifier.com;
44

5-
error_log /var/log/nginx/telegram-nofity-bot-error.log;
6-
access_log /var/log/nginx/telegram-nofity-bot-access.log;
5+
error_log /var/log/nginx/telegram-git-notifier-error.log;
6+
access_log /var/log/nginx/telegram-git-notifier-access.log;
77

88
root /var/www/html/;
99
index index.php index.html index.htm;

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
$finder = Symfony\Component\Finder\Finder::create()
44
->in([
55
__DIR__ . '/src',
6+
__DIR__ . '/webhooks',
67
])
78
->name('*.php')
89
->ignoreDotFiles(true)

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Tan Nguyen
3+
Copyright (c) 2023 CSlant
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and manage customization through messages and buttons on Telegram.
1111

1212
![License](https://img.shields.io/github/license/cslant/telegram-git-notifier-app.svg?style=flat-square)
1313
[![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)
14+
![Test Status](https://img.shields.io/github/actions/workflow/status/cslant/telegram-git-notifier-app/setup_test.yml?label=tests&branch=main)
15+
![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)
1416
[![StyleCI](https://styleci.io/repos/656960426/shield)](https://styleci.io/repos/656960426)
1517
[![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)
1618
[![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
131133

132134
1. Open a chat with your bot.
133135
2. Send any message to your bot. (This handle needs to get your chat ID)
134-
3. Go to the following URL: `<TGN_APP_URL>/webhook/getUpdate.php`
136+
3. Go to the following URL: `<TGN_APP_URL>/webhooks/getUpdate.php`
135137
4. Look for the `"chat":{"id":` field and copy the number after it. This is your Chat ID.
136138
5. Paste the Chat ID in your `.env` file.
137139

@@ -240,7 +242,7 @@ TGN_APP_URL=https://123456789.ngrok-free.app
240242

241243
1. Open a chat with your bot.
242244
2. Send any message to your bot. (This handle needs to get your chat ID)
243-
3. Go to the following URL: `<TGN_APP_URL>/webhook/getUpdate.php`
245+
3. Go to the following URL: `<TGN_APP_URL>/webhooks/getUpdate.php`
244246
4. Look for the `"chat":{"id":` field and copy the number after it. This is your Chat ID.
245247
5. Paste the Chat ID in your `.env` file.
246248

@@ -261,7 +263,7 @@ After setting up your domain and SSL certificate, you need to set up the webhook
261263
**Go to:**
262264

263265
```text
264-
<APP_URL>/webhook/set.php
266+
<APP_URL>/webhooks/set.php
265267
```
266268

267269
> **Note:** Replace `<APP_URL>` with your app URL in .env file.

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ parameters:
22
level: 8
33
paths:
44
- src
5+
- webhooks
56
tmpDir: build/phpstan
67
checkMissingIterableValueType: false

src/Http/Actions/IndexAction.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace CSlant\TelegramGitNotifierApp\Http\Actions;
44

55
use CSlant\TelegramGitNotifier\Bot;
6+
use CSlant\TelegramGitNotifier\Exceptions\BotException;
7+
use CSlant\TelegramGitNotifier\Exceptions\CallbackException;
8+
use CSlant\TelegramGitNotifier\Exceptions\ConfigFileException;
69
use CSlant\TelegramGitNotifier\Exceptions\EntryNotFoundException;
710
use CSlant\TelegramGitNotifier\Exceptions\InvalidViewTemplateException;
811
use CSlant\TelegramGitNotifier\Exceptions\MessageIsEmptyException;
@@ -25,6 +28,9 @@ class IndexAction
2528

2629
protected Request $request;
2730

31+
/**
32+
* @throws ConfigFileException
33+
*/
2834
public function __construct()
2935
{
3036
$this->client = new Client();
@@ -38,10 +44,12 @@ public function __construct()
3844
* Handle telegram git notifier app
3945
*
4046
* @return void
41-
* @throws InvalidViewTemplateException
42-
* @throws SendNotificationException
4347
* @throws EntryNotFoundException
48+
* @throws InvalidViewTemplateException
4449
* @throws MessageIsEmptyException
50+
* @throws SendNotificationException
51+
* @throws BotException
52+
* @throws CallbackException
4553
*/
4654
public function __invoke(): void
4755
{

src/Http/Actions/WebhookAction.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CSlant\TelegramGitNotifierApp\Http\Actions;
44

5+
use CSlant\TelegramGitNotifier\Exceptions\WebhookException;
56
use CSlant\TelegramGitNotifier\Webhook;
67

78
class WebhookAction
@@ -20,29 +21,32 @@ public function __construct()
2021
/**
2122
* Set webhook for telegram bot
2223
*
23-
* @return false|string
24+
* @return string
25+
* @throws WebhookException
2426
*/
25-
public function set(): false|string
27+
public function set(): string
2628
{
2729
return $this->webhook->setWebhook();
2830
}
2931

3032
/**
3133
* Delete webhook for telegram bot
3234
*
33-
* @return false|string
35+
* @return string
36+
* @throws WebhookException
3437
*/
35-
public function delete(): false|string
38+
public function delete(): string
3639
{
3740
return $this->webhook->deleteWebHook();
3841
}
3942

4043
/**
4144
* Get webhook update
4245
*
43-
* @return false|string
46+
* @return string
47+
* @throws WebhookException
4448
*/
45-
public function getUpdates(): false|string
49+
public function getUpdates(): string
4650
{
4751
return $this->webhook->getUpdates();
4852
}

src/Services/CallbackService.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use CSlant\TelegramGitNotifier\Bot;
66
use CSlant\TelegramGitNotifier\Constants\SettingConstant;
7+
use CSlant\TelegramGitNotifier\Exceptions\BotException;
8+
use CSlant\TelegramGitNotifier\Exceptions\CallbackException;
79
use CSlant\TelegramGitNotifier\Exceptions\InvalidViewTemplateException;
810
use CSlant\TelegramGitNotifier\Exceptions\MessageIsEmptyException;
911
use CSlant\TelegramGitNotifierApp\Traits\Markup;
@@ -26,6 +28,8 @@ public function __construct(Bot $bot)
2628
*
2729
* @return void
2830
* @throws MessageIsEmptyException
31+
* @throws BotException
32+
* @throws CallbackException
2933
*/
3034
public function answerBackButton(string $callback): void
3135
{
@@ -67,6 +71,7 @@ public function answerBackButton(string $callback): void
6771
* @return void
6872
* @throws MessageIsEmptyException
6973
* @throws InvalidViewTemplateException
74+
* @throws BotException|CallbackException
7075
*/
7176
public function handle(): void
7277
{

webhook/delete.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

webhook/getUpdate.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

webhook/set.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

webhooks/delete.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
use CSlant\TelegramGitNotifier\Exceptions\WebhookException;
4+
use CSlant\TelegramGitNotifierApp\Http\Actions\WebhookAction;
5+
6+
require __DIR__ . '/../init.php';
7+
8+
$webhookAction = new WebhookAction();
9+
10+
try {
11+
echo $webhookAction->delete();
12+
} catch (WebhookException $e) {
13+
echo $e->getMessage();
14+
}

webhooks/getUpdate.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
use CSlant\TelegramGitNotifier\Exceptions\WebhookException;
4+
use CSlant\TelegramGitNotifierApp\Http\Actions\WebhookAction;
5+
6+
require __DIR__ . '/../init.php';
7+
8+
$webhookAction = new WebhookAction();
9+
10+
try {
11+
echo $webhookAction->getUpdates();
12+
} catch (WebhookException $e) {
13+
echo $e->getMessage();
14+
}

webhooks/set.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
use CSlant\TelegramGitNotifier\Exceptions\WebhookException;
4+
use CSlant\TelegramGitNotifierApp\Http\Actions\WebhookAction;
5+
6+
require __DIR__ . '/../init.php';
7+
8+
$webhookAction = new WebhookAction();
9+
10+
try {
11+
echo $webhookAction->set();
12+
} catch (WebhookException $e) {
13+
echo $e->getMessage();
14+
}

0 commit comments

Comments
 (0)