-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from pxthinh/feature/webhook_1
feat: handle set and delete webhook telegram token
- Loading branch information
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |