Skip to content

Commit e42d0de

Browse files
RicardoRamirezRmpociot
authored andcommitted
Add option to unregister the webhook (#38)
1 parent 45ed1e8 commit e42d0de

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/Console/Commands/TelegramRegisterCommand.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ class TelegramRegisterCommand extends Command
1111
*
1212
* @var string
1313
*/
14-
protected $signature = 'botman:telegram:register {--output}';
14+
protected $signature = 'botman:telegram:register {--remove} {--output}';
1515

1616
/**
1717
* The console command description.
1818
*
1919
* @var string
2020
*/
21-
protected $description = 'Register your bot with Telegram\'s webhook';
21+
protected $description = 'Register or unregister your bot with Telegram\'s webhook';
2222

2323
/**
2424
* Execute the console command.
@@ -29,8 +29,13 @@ public function handle()
2929
{
3030
$url = 'https://api.telegram.org/bot'
3131
.config('botman.telegram.token')
32-
.'/setWebhook?url='
33-
.$this->ask('What is the target url for the telegram bot?');
32+
.'/setWebhook';
33+
34+
$remove = $this->option('remove', null);
35+
36+
if (! $remove) {
37+
$url .= '?url='.$this->ask('What is the target url for the telegram bot?');
38+
}
3439

3540
$this->info('Using '.$url);
3641

@@ -39,7 +44,10 @@ public function handle()
3944
$output = json_decode(file_get_contents($url));
4045

4146
if ($output->ok == true && $output->result == true) {
42-
$this->info('Your bot is now set up with Telegram\'s webhook!');
47+
$this->info($remove
48+
? 'Your bot Telegram\'s webhook has been removed!'
49+
: 'Your bot is now set up with Telegram\'s webhook!'
50+
);
4351
}
4452

4553
if ($this->option('output')) {

0 commit comments

Comments
 (0)