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

Skip to content

Commit 3fae769

Browse files
committed
[Notifier] [Bridge] Store message id for slack transport's SendMessage
1 parent 2ad08d5 commit 3fae769

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/Symfony/Component/Notifier/Bridge/Slack/SlackTransport.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ protected function doSend(MessageInterface $message): SentMessage
9191
throw new TransportException(sprintf('Unable to post the Slack message: "%s".', $result['error']), $response);
9292
}
9393

94-
return new SentMessage($message, (string) $this);
94+
$sentMessage = new SentMessage($message, (string) $this);
95+
$sentMessage->setMessageId($result['ts']);
96+
97+
return $sentMessage;
9598
}
9699
}

src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,42 @@ public function testSendWith200ResponseButNotOk()
203203

204204
$transport->send(new ChatMessage('testMessage'));
205205
}
206+
207+
public function testMessageIdSet()
208+
{
209+
$channel = 'testChannel';
210+
$message = 'testMessage';
211+
212+
$response = $this->createMock(ResponseInterface::class);
213+
214+
$response->expects($this->exactly(2))
215+
->method('getStatusCode')
216+
->willReturn(200);
217+
218+
$response->expects($this->once())
219+
->method('getContent')
220+
->willReturn(json_encode(['ok' => true, 'ts' => '1503435956.000247']));
221+
222+
$notification = new Notification($message);
223+
$chatMessage = ChatMessage::fromNotification($notification);
224+
$options = SlackOptions::fromNotification($notification);
225+
226+
$expectedBody = json_encode([
227+
'blocks' => $options->toArray()['blocks'],
228+
'channel' => $channel,
229+
'text' => $message,
230+
]);
231+
232+
$client = new MockHttpClient(function (string $method, string $url, array $options = []) use ($response, $expectedBody): ResponseInterface {
233+
$this->assertJsonStringEqualsJsonString($expectedBody, $options['body']);
234+
235+
return $response;
236+
});
237+
238+
$transport = $this->createTransport($client, $channel);
239+
240+
$sentMessage = $transport->send($chatMessage);
241+
242+
$this->assertEquals('1503435956.000247', $sentMessage->getMessageId());
243+
}
206244
}

0 commit comments

Comments
 (0)