Skip to content

Commit e792b16

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 e480b38 commit e792b16

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,22 @@ protected function doSend(MessageInterface $message): SentMessage
9696

9797
$threadKey = $opts->getThreadKey() ?: $this->threadKey;
9898

99-
$options = $opts->toArray();
10099
$url = sprintf('https://%s/v1/spaces/%s/messages?key=%s&token=%s%s',
101100
$this->getEndpoint(),
102101
$this->space,
103102
urlencode($this->accessKey),
104103
urlencode($this->accessToken),
105-
$threadKey ? '&threadKey='.urlencode($threadKey) : ''
104+
$threadKey ? '&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD' : ''
106105
);
106+
107+
$body = array_filter($opts->toArray());
108+
109+
if ($threadKey) {
110+
$body['thread']['threadKey'] = $threadKey;
111+
}
112+
107113
$response = $this->client->request('POST', $url, [
108-
'json' => array_filter($options),
114+
'json' => $body,
109115
]);
110116

111117
try {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ public function testSendWithOptions()
116116
->method('getContent')
117117
->willReturn('{"name":"spaces/My-Space/messages/abcdefg.hijklmno"}');
118118

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

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

126126
return $response;

0 commit comments

Comments
 (0)