-
-
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 #58 from LuongTienThinh/feat/webhook-command
feat: set webhook using cli
- Loading branch information
Showing
5 changed files
with
117 additions
and
11 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,40 @@ | ||
<?php | ||
|
||
namespace CSlant\LaravelTelegramGitNotifier\Commands; | ||
|
||
use CSlant\LaravelTelegramGitNotifier\Services\WebhookService; | ||
use CSlant\TelegramGitNotifier\Exceptions\WebhookException; | ||
use Illuminate\Console\Command; | ||
|
||
class SetWebhook extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'tg-notifier:webhook:set'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Set webhook'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle(): void | ||
{ | ||
try { | ||
$webhookService = new WebhookService(); | ||
|
||
$this->info($webhookService->setWebhook()); | ||
} catch (WebhookException $e) { | ||
$this->error($e->getMessage()); | ||
} | ||
} | ||
} |
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
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,66 @@ | ||
<?php | ||
|
||
namespace CSlant\LaravelTelegramGitNotifier\Services; | ||
|
||
use CSlant\TelegramGitNotifier\Exceptions\WebhookException; | ||
use CSlant\TelegramGitNotifier\Webhook; | ||
|
||
class WebhookService | ||
{ | ||
protected Webhook $webhook; | ||
|
||
public function __construct(?Webhook $webhook = null) | ||
{ | ||
$this->webhook = $webhook ?? new Webhook(); | ||
$this->webhook->setToken(config('telegram-git-notifier.bot.token')); | ||
$this->webhook->setUrl(config('telegram-git-notifier.app.url')); | ||
} | ||
|
||
/** | ||
* Set webhook for telegram bot. | ||
* | ||
* @return string | ||
* | ||
* @throws WebhookException | ||
*/ | ||
public function setWebhook(): string | ||
{ | ||
return $this->webhook->setWebhook(); | ||
} | ||
|
||
/** | ||
* Delete webhook for telegram bot. | ||
* | ||
* @return string | ||
* | ||
* @throws WebhookException | ||
*/ | ||
public function deleteWebHook(): string | ||
{ | ||
return $this->webhook->deleteWebHook(); | ||
} | ||
|
||
/** | ||
* Get webhook update. | ||
* | ||
* @return string | ||
* | ||
* @throws WebhookException | ||
*/ | ||
public function getUpdates(): string | ||
{ | ||
return $this->webhook->getUpdates(); | ||
} | ||
|
||
/** | ||
* Get webhook info. | ||
* | ||
* @return string | ||
* | ||
* @throws WebhookException | ||
*/ | ||
public function getWebHookInfo(): string | ||
{ | ||
return $this->webhook->getWebHookInfo(); | ||
} | ||
} |