Skip to content

Commit ecd08d0

Browse files
authored
Merge pull request #5 from pxthinh/feature/webhook_1
feat: handle set and delete webhook telegram token
2 parents 50de6a0 + 27f40ef commit ecd08d0

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

config/telegram-git-notifier.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,31 @@
33
return [
44
'app' => [
55
'name' => env('APP_NAME', 'Laravel Telegram Git Notify'),
6+
'url' => env('APP_URL', 'http://localhost:8000'),
7+
'timezone' => env('TIMEZONE','Asia/Ho_Chi_Minh'),
68
],
9+
10+
'telegram-bot' => [
11+
'token' => env('TELEGRAM_BOT_TOKEN', ''),
12+
'chat_id' => env('TELEGRAM_BOT_CHAT_ID', ''),
13+
'notify_chat_ids' => explode(
14+
',',
15+
env('TELEGRAM_NOTIFY_CHAT_IDS', '')
16+
),
17+
],
18+
19+
'author' => [
20+
'contact' => env('TGN_AUTHOR_CONTACT', 'https://t.me/tannp27'),
21+
'source_code' => env('TGN_AUTHOR_SOURCE_CODE','https://github.com/lbiltech/telegram-git-notifier'),
22+
],
23+
24+
'view' => [
25+
'path' => env('TGN_VIEW_PATH', 'resources/views/telegram-git-notifier'),
26+
'event' => [
27+
'default' => env('TGN_VIEW_EVENT_DEFAULT', 'default'),
28+
],
29+
'globals' => [
30+
'access_denied' => env('TGN_VIEW_GLOBALS_ACCESS_DENIED', 'globals.access_denied'),
31+
]
32+
]
733
];

routes/bot.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Route;
4+
use LbilTech\LaravelTelegramGitNotifier\Http\Actions\WebhookAction;
5+
6+
/*
7+
|--------------------------------------------------------------------------
8+
| Bot Routes
9+
|--------------------------------------------------------------------------
10+
|
11+
| Here is where you can register web routes for your application. These
12+
| routes are loaded by the RouteServiceProvider and all of them will
13+
| be assigned to the "web" middleware group. Make something great!
14+
|
15+
*/
16+
17+
Route::prefix('telegram-git-notifier')->group(function () {
18+
Route::get('/set-webhook', [WebhookAction::class, 'set'])->name('set-webhook');
19+
Route::get('/delete-webhook', [WebhookAction::class, 'delete'])->name('delete-webhook');
20+
});
21+

src/Http/Actions/WebhookAction.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace LbilTech\LaravelTelegramGitNotifier\Http\Actions;
4+
5+
use LbilTech\TelegramGitNotifier\Services\WebhookService;
6+
7+
/**
8+
* Class WebhookAction
9+
*
10+
* @package LbilTech\LaravelTelegramGitNotifier\Http\Actions
11+
*/
12+
class WebhookAction
13+
{
14+
protected string $token;
15+
16+
protected WebhookService $webhookService;
17+
18+
public function __construct(WebhookService $webhookService)
19+
{
20+
$this->webhookService = $webhookService;
21+
$this->webhookService->setToken(config('telegram-git-notifier.telegram-bot.token'));
22+
$this->webhookService->setUrl(config('telegram-git-notifier.app.url'));
23+
}
24+
25+
/**
26+
* Set webhook for telegram bot
27+
*
28+
* @return false|string
29+
*/
30+
public function set(): false|string
31+
{
32+
return $this->webhookService->setWebhook();
33+
}
34+
35+
/**
36+
* Delete webhook for telegram bot
37+
*
38+
* @return false|string
39+
*/
40+
public function delete(): false|string
41+
{
42+
return $this->webhookService->deleteWebHook();
43+
}
44+
}

0 commit comments

Comments
 (0)