Skip to content

Commit e8b6a2d

Browse files
[Notifier] Fix thread key in GoogleChat bridge
Google Chat API has deprecated the use of `threadKey` query parameter in favor of `thread.threadKey` in request's body.
1 parent 916718c commit e8b6a2d

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/Symfony/Component/Notifier/Bridge/GoogleChat/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.2
5+
---
6+
7+
* Fix thread management with updated Google Chat API
8+
49
7.0
510
---
611

src/Symfony/Component/Notifier/Bridge/GoogleChat/GoogleChatTransport.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,17 @@ protected function doSend(MessageInterface $message): SentMessage
9292
$this->space,
9393
urlencode($this->accessKey),
9494
urlencode($this->accessToken),
95-
$threadKey ? '&threadKey='.urlencode($threadKey) : ''
95+
$threadKey ? '&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD' : ''
9696
);
97+
98+
$body = array_filter($options->toArray());
99+
100+
if ($threadKey) {
101+
$body['thread']['threadKey'] = $threadKey;
102+
}
103+
97104
$response = $this->client->request('POST', $url, [
98-
'json' => array_filter($options->toArray()),
105+
'json' => $body,
99106
]);
100107

101108
try {

src/Symfony/Component/Notifier/Bridge/GoogleChat/Tests/GoogleChatTransportTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ public function testSendWithOptions()
108108
->method('getContent')
109109
->willReturn('{"name":"spaces/My-Space/messages/abcdefg.hijklmno"}');
110110

111-
$expectedBody = json_encode(['text' => $message]);
111+
$expectedBody = json_encode(['text' => $message, 'thread' => ['threadKey' => 'My-Thread']]);
112112

113113
$client = new MockHttpClient(function (string $method, string $url, array $options = []) use ($response, $expectedBody): ResponseInterface {
114114
$this->assertSame('POST', $method);
115-
$this->assertSame('https://chat.googleapis.com/v1/spaces/My-Space/messages?key=theAccessKey&token=theAccessToken%3D&threadKey=My-Thread', $url);
115+
$this->assertSame('https://chat.googleapis.com/v1/spaces/My-Space/messages?key=theAccessKey&token=theAccessToken%3D&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD', $url);
116116
$this->assertSame($expectedBody, $options['body']);
117117

118118
return $response;

0 commit comments

Comments
 (0)