@@ -236,7 +236,15 @@ private function convertQuestion(Question $question)
236236 */
237237 public function buildServicePayload ($ message , $ matchingMessage , $ additionalParameters = [])
238238 {
239- if (! Collection::make ($ matchingMessage ->getPayload ())->has ('team_domain ' )) {
239+ $ matchingMessagePayload = $ matchingMessage ->getPayload ();
240+
241+ // If the matching message is in a thread, reply there
242+ $ thread_ts = $ matchingMessagePayload ->get ('thread_ts ' );
243+ if (! empty ($ thread_ts )) {
244+ $ additionalParameters ['thread_ts ' ] = $ thread_ts ;
245+ }
246+
247+ if (! Collection::make ($ matchingMessagePayload )->has ('team_domain ' )) {
240248 $ this ->resultType = self ::RESULT_TOKEN ;
241249 $ payload = $ this ->replyWithToken ($ message , $ matchingMessage , $ additionalParameters );
242250 } else {
@@ -270,9 +278,7 @@ public function sendPayload($payload)
270278 */
271279 public function replyInThread ($ message , $ additionalParameters , $ matchingMessage , BotMan $ bot )
272280 {
273- $ additionalParameters ['thread_ts ' ] = ! empty ($ matchingMessage ->getPayload ()->get ('thread_ts ' ))
274- ? $ matchingMessage ->getPayload ()->get ('thread_ts ' )
275- : $ matchingMessage ->getPayload ()->get ('ts ' );
281+ $ additionalParameters ['thread_ts ' ] = $ matchingMessage ->getPayload ()->get ('ts ' );
276282
277283 $ payload = $ this ->buildServicePayload ($ message , $ matchingMessage , $ additionalParameters );
278284
0 commit comments