Skip to content

Commit

Permalink
Always reply in existing threads
Browse files Browse the repository at this point in the history
  • Loading branch information
rzumer committed Oct 12, 2023
1 parent 8be4609 commit c1e2a14
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/SlackDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 7 additions & 3 deletions src/SlackRTMDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit c1e2a14

Please sign in to comment.