Skip to content

Commit

Permalink
Add option to unregister the webhook (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoRamirezR authored and mpociot committed Apr 5, 2018
1 parent 45ed1e8 commit e42d0de
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Console/Commands/TelegramRegisterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class TelegramRegisterCommand extends Command
*
* @var string
*/
protected $signature = 'botman:telegram:register {--output}';
protected $signature = 'botman:telegram:register {--remove} {--output}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Register your bot with Telegram\'s webhook';
protected $description = 'Register or unregister your bot with Telegram\'s webhook';

/**
* Execute the console command.
Expand All @@ -29,8 +29,13 @@ public function handle()
{
$url = 'https://api.telegram.org/bot'
.config('botman.telegram.token')
.'/setWebhook?url='
.$this->ask('What is the target url for the telegram bot?');
.'/setWebhook';

$remove = $this->option('remove', null);

if (! $remove) {
$url .= '?url='.$this->ask('What is the target url for the telegram bot?');
}

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

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

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

if ($this->option('output')) {
Expand Down

0 comments on commit e42d0de

Please sign in to comment.