Skip to content

Commit

Permalink
Merge pull request #104 from tanhongit/main
Browse files Browse the repository at this point in the history
fix: update webhook request with exceptions
  • Loading branch information
tanhongit authored Nov 8, 2023
2 parents 750cf9f + e073b1c commit cfb0366
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 39 deletions.
6 changes: 3 additions & 3 deletions .docker/conf.d/site.conf
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$finder = Symfony\Component\Finder\Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/webhooks',
])
->name('*.php')
->ignoreDotFiles(true)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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: `<TGN_APP_URL>/webhook/getUpdate.php`
3. Go to the following URL: `<TGN_APP_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.

Expand Down Expand Up @@ -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: `<TGN_APP_URL>/webhook/getUpdate.php`
3. Go to the following URL: `<TGN_APP_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.

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

```text
<APP_URL>/webhook/set.php
<APP_URL>/webhooks/set.php
```

> **Note:** Replace `<APP_URL>` with your app URL in .env file.
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ parameters:
level: 8
paths:
- src
- webhooks
tmpDir: build/phpstan
checkMissingIterableValueType: false
12 changes: 10 additions & 2 deletions src/Http/Actions/IndexAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +28,9 @@ class IndexAction

protected Request $request;

/**
* @throws ConfigFileException
*/
public function __construct()
{
$this->client = new Client();
Expand All @@ -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
{
Expand Down
16 changes: 10 additions & 6 deletions src/Http/Actions/WebhookAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace CSlant\TelegramGitNotifierApp\Http\Actions;

use CSlant\TelegramGitNotifier\Exceptions\WebhookException;
use CSlant\TelegramGitNotifier\Webhook;

class WebhookAction
Expand All @@ -20,29 +21,32 @@ 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();
}

/**
* 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();
}

/**
* Get webhook update
*
* @return false|string
* @return string
* @throws WebhookException
*/
public function getUpdates(): false|string
public function getUpdates(): string
{
return $this->webhook->getUpdates();
}
Expand Down
5 changes: 5 additions & 0 deletions src/Services/CallbackService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +28,8 @@ public function __construct(Bot $bot)
*
* @return void
* @throws MessageIsEmptyException
* @throws BotException
* @throws CallbackException
*/
public function answerBackButton(string $callback): void
{
Expand Down Expand Up @@ -67,6 +71,7 @@ public function answerBackButton(string $callback): void
* @return void
* @throws MessageIsEmptyException
* @throws InvalidViewTemplateException
* @throws BotException|CallbackException
*/
public function handle(): void
{
Expand Down
8 changes: 0 additions & 8 deletions webhook/delete.php

This file was deleted.

8 changes: 0 additions & 8 deletions webhook/getUpdate.php

This file was deleted.

8 changes: 0 additions & 8 deletions webhook/set.php

This file was deleted.

14 changes: 14 additions & 0 deletions webhooks/delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use CSlant\TelegramGitNotifier\Exceptions\WebhookException;
use CSlant\TelegramGitNotifierApp\Http\Actions\WebhookAction;

require __DIR__ . '/../init.php';

$webhookAction = new WebhookAction();

try {
echo $webhookAction->delete();
} catch (WebhookException $e) {
echo $e->getMessage();
}
14 changes: 14 additions & 0 deletions webhooks/getUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use CSlant\TelegramGitNotifier\Exceptions\WebhookException;
use CSlant\TelegramGitNotifierApp\Http\Actions\WebhookAction;

require __DIR__ . '/../init.php';

$webhookAction = new WebhookAction();

try {
echo $webhookAction->getUpdates();
} catch (WebhookException $e) {
echo $e->getMessage();
}
14 changes: 14 additions & 0 deletions webhooks/set.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use CSlant\TelegramGitNotifier\Exceptions\WebhookException;
use CSlant\TelegramGitNotifierApp\Http\Actions\WebhookAction;

require __DIR__ . '/../init.php';

$webhookAction = new WebhookAction();

try {
echo $webhookAction->set();
} catch (WebhookException $e) {
echo $e->getMessage();
}

0 comments on commit cfb0366

Please sign in to comment.