Skip to content

Commit

Permalink
feat: handle set and delete webhook telegram token
Browse files Browse the repository at this point in the history
  • Loading branch information
Xuan Thinh committed Oct 2, 2023
1 parent 50de6a0 commit 27f40ef
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
26 changes: 26 additions & 0 deletions config/telegram-git-notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,31 @@
return [
'app' => [
'name' => env('APP_NAME', 'Laravel Telegram Git Notify'),
'url' => env('APP_URL', 'http://localhost:8000'),
'timezone' => env('TIMEZONE','Asia/Ho_Chi_Minh'),
],

'telegram-bot' => [
'token' => env('TELEGRAM_BOT_TOKEN', ''),
'chat_id' => env('TELEGRAM_BOT_CHAT_ID', ''),
'notify_chat_ids' => explode(
',',
env('TELEGRAM_NOTIFY_CHAT_IDS', '')
),
],

'author' => [
'contact' => env('TGN_AUTHOR_CONTACT', 'https://t.me/tannp27'),
'source_code' => env('TGN_AUTHOR_SOURCE_CODE','https://github.com/lbiltech/telegram-git-notifier'),
],

'view' => [
'path' => env('TGN_VIEW_PATH', 'resources/views/telegram-git-notifier'),
'event' => [
'default' => env('TGN_VIEW_EVENT_DEFAULT', 'default'),
],
'globals' => [
'access_denied' => env('TGN_VIEW_GLOBALS_ACCESS_DENIED', 'globals.access_denied'),
]
]
];
21 changes: 21 additions & 0 deletions routes/bot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Support\Facades\Route;
use LbilTech\LaravelTelegramGitNotifier\Http\Actions\WebhookAction;

/*
|--------------------------------------------------------------------------
| Bot Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::prefix('telegram-git-notifier')->group(function () {
Route::get('/set-webhook', [WebhookAction::class, 'set'])->name('set-webhook');
Route::get('/delete-webhook', [WebhookAction::class, 'delete'])->name('delete-webhook');
});

44 changes: 44 additions & 0 deletions src/Http/Actions/WebhookAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace LbilTech\LaravelTelegramGitNotifier\Http\Actions;

use LbilTech\TelegramGitNotifier\Services\WebhookService;

/**
* Class WebhookAction
*
* @package LbilTech\LaravelTelegramGitNotifier\Http\Actions
*/
class WebhookAction
{
protected string $token;

protected WebhookService $webhookService;

public function __construct(WebhookService $webhookService)
{
$this->webhookService = $webhookService;
$this->webhookService->setToken(config('telegram-git-notifier.telegram-bot.token'));
$this->webhookService->setUrl(config('telegram-git-notifier.app.url'));
}

/**
* Set webhook for telegram bot
*
* @return false|string
*/
public function set(): false|string
{
return $this->webhookService->setWebhook();
}

/**
* Delete webhook for telegram bot
*
* @return false|string
*/
public function delete(): false|string
{
return $this->webhookService->deleteWebHook();
}
}

0 comments on commit 27f40ef

Please sign in to comment.