Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handle set and delete webhook telegram token #5

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'),
pxthinh marked this conversation as resolved.
Show resolved Hide resolved
],

'view' => [
'path' => env('TGN_VIEW_PATH', 'resources/views/telegram-git-notifier'),
pxthinh marked this conversation as resolved.
Show resolved Hide resolved
'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();
}
}