Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Notifier] [Bridge] Fix missed messageId for SendMessage object in slack notifier #40955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ protected function doSend(MessageInterface $message): SentMessage
throw new TransportException(sprintf('Unable to post the Slack message: "%s".', $result['error']), $response);
}

return new SentMessage($message, (string) $this);
$sentMessage = new SentMessage($message, (string) $this);
$sentMessage->setMessageId($result['ts']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we check if the key exists in the array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already check for "ok" status. I had looked to another transports/bridges, they did not have even this checks.

Which behavior do you expect, if by some unknown reason slack return response with ok status, but with no messageid specified?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but ok let's keep it


return $sentMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function testSendWithOptions()

$response->expects($this->once())
->method('getContent')
->willReturn(json_encode(['ok' => true]));
->willReturn(json_encode(['ok' => true, 'ts' => '1503435956.000247']));

$expectedBody = json_encode(['channel' => $channel, 'text' => $message]);

Expand All @@ -122,7 +122,9 @@ public function testSendWithOptions()

$transport = $this->createTransport($client, $channel);

$transport->send(new ChatMessage('testMessage'));
$sentMessage = $transport->send(new ChatMessage('testMessage'));

$this->assertSame('1503435956.000247', $sentMessage->getMessageId());
}

public function testSendWithNotification()
Expand All @@ -138,7 +140,7 @@ public function testSendWithNotification()

$response->expects($this->once())
->method('getContent')
->willReturn(json_encode(['ok' => true]));
->willReturn(json_encode(['ok' => true, 'ts' => '1503435956.000247']));

$notification = new Notification($message);
$chatMessage = ChatMessage::fromNotification($notification);
Expand All @@ -158,7 +160,9 @@ public function testSendWithNotification()

$transport = $this->createTransport($client, $channel);

$transport->send($chatMessage);
$sentMessage = $transport->send($chatMessage);

$this->assertSame('1503435956.000247', $sentMessage->getMessageId());
}

public function testSendWithInvalidOptions()
Expand Down