From 5f8079c2eb1bc9838c373ff7c11c97038ab43ba9 Mon Sep 17 00:00:00 2001 From: Daniel Pigott Date: Thu, 23 May 2019 21:01:46 +1000 Subject: [PATCH] Added --heartbeat-interval option. Fixes botman/driver-slack/#13 --- src/Commands/SlackRTMListenCommand.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Commands/SlackRTMListenCommand.php b/src/Commands/SlackRTMListenCommand.php index 7b151fc..30bc4fe 100644 --- a/src/Commands/SlackRTMListenCommand.php +++ b/src/Commands/SlackRTMListenCommand.php @@ -16,7 +16,8 @@ class SlackRTMListenCommand extends Command * * @var string */ - protected $signature = 'botman:listen-on-slack'; + protected $signature = 'botman:listen-on-slack + {--heartbeat-interval=120 : Seconds to wait before checking the connection. Set to 0 to disable}'; /** * The console command description. @@ -27,8 +28,6 @@ class SlackRTMListenCommand extends Command /** * Execute the console command. - * - * @return mixed */ public function handle() { @@ -46,6 +45,18 @@ public function handle() require base_path('routes/botman.php'); } + //If a heartbeat is set, add a periodic timer to check the connection to the server + if ($this->option('heartbeat-interval') > 0) { + $checkConnection = function () { + $botman = resolve('botman'); + $botman->getDriver()->getClient()->checkConnection(); + }; + $loop->addPeriodicTimer( + $this->option('heartbeat-interval'), + $checkConnection + ); + } + $loop->run(); } }