Skip to content

Commit

Permalink
Merge pull request #5 from pxthinh/feature/webhook_1
Browse files Browse the repository at this point in the history
feat: handle set and delete webhook telegram token
  • Loading branch information
pxthinh authored Oct 2, 2023
2 parents 50de6a0 + 27f40ef commit ecd08d0
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 ecd08d0

Please sign in to comment.