From e42d0de0da80d5d147ebfed13af1aa7f6180f1a3 Mon Sep 17 00:00:00 2001
From: Ricardo <ricardo@noah.club>
Date: Thu, 5 Apr 2018 04:16:17 -0500
Subject: [PATCH] Add option to unregister the webhook (#38)

---
 .../Commands/TelegramRegisterCommand.php       | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/Console/Commands/TelegramRegisterCommand.php b/src/Console/Commands/TelegramRegisterCommand.php
index 3e65bdc..db75a64 100644
--- a/src/Console/Commands/TelegramRegisterCommand.php
+++ b/src/Console/Commands/TelegramRegisterCommand.php
@@ -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.
@@ -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);
 
@@ -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')) {