diff --git a/src/SlackDriver.php b/src/SlackDriver.php index 0a142d4..3875b20 100644 --- a/src/SlackDriver.php +++ b/src/SlackDriver.php @@ -236,7 +236,15 @@ private function convertQuestion(Question $question) */ public function buildServicePayload($message, $matchingMessage, $additionalParameters = []) { - if (! Collection::make($matchingMessage->getPayload())->has('team_domain')) { + $matchingMessagePayload = $matchingMessage->getPayload(); + + // If the matching message is in a thread, reply there + $thread_ts = $matchingMessagePayload->get('thread_ts'); + if (! empty($thread_ts)) { + $additionalParameters['thread_ts'] = $thread_ts; + } + + if (! Collection::make($matchingMessagePayload)->has('team_domain')) { $this->resultType = self::RESULT_TOKEN; $payload = $this->replyWithToken($message, $matchingMessage, $additionalParameters); } else { @@ -270,9 +278,7 @@ public function sendPayload($payload) */ public function replyInThread($message, $additionalParameters, $matchingMessage, BotMan $bot) { - $additionalParameters['thread_ts'] = ! empty($matchingMessage->getPayload()->get('thread_ts')) - ? $matchingMessage->getPayload()->get('thread_ts') - : $matchingMessage->getPayload()->get('ts'); + $additionalParameters['thread_ts'] = $matchingMessage->getPayload()->get('ts'); $payload = $this->buildServicePayload($message, $matchingMessage, $additionalParameters); diff --git a/src/SlackRTMDriver.php b/src/SlackRTMDriver.php index 8a30458..45da037 100644 --- a/src/SlackRTMDriver.php +++ b/src/SlackRTMDriver.php @@ -250,6 +250,12 @@ protected function isBot() */ public function buildServicePayload($message, $matchingMessage, $additionalParameters = []) { + // If the matching message is in a thread, reply there + $thread_ts = $matchingMessage->getPayload()->get('thread_ts'); + if (! empty($thread_ts)) { + $additionalParameters['thread_ts'] = $thread_ts; + } + $parameters = array_replace_recursive([ 'channel' => $matchingMessage->getRecipient() ?: $matchingMessage->getSender(), 'as_user' => true, @@ -308,9 +314,7 @@ public function sendPayload($payload) */ public function replyInThread($message, $additionalParameters, $matchingMessage) { - $additionalParameters['thread_ts'] = ! empty($matchingMessage->getPayload()->get('thread_ts')) - ? $matchingMessage->getPayload()->get('thread_ts') - : $matchingMessage->getPayload()->get('ts'); + $additionalParameters['thread_ts'] = $matchingMessage->getPayload()->get('ts'); return $this->reply($message, $matchingMessage, $additionalParameters); }