Skip to content

Commit 53a3024

Browse files
committed
bug #57384 [Notifier] Fix thread key in GoogleChat bridge (romain-jacquart)
This PR was merged into the 5.4 branch. Discussion ---------- [Notifier] Fix thread key in GoogleChat bridge | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #57323 | License | MIT Hello, Google Chat API [has deprecated](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.messages/create#query-parameters) the use of `threadKey` query parameter in favor of `thread.threadKey` in request's body. In order for the thread key value to not be ignored, a [new query parameter `messageReplyOption`](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.messages/create#messagereplyoption) has been added which controls the way the key is handled. I chose **not to expose** the values used by this new parameter as I wanted to focus this PR on the actual fix. To do so, I've forced the value of `messageReplyOption` to `REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD` which replicates the original behavior of this bridge. Commits ------- e792b16 [Notifier] Fix thread key in GoogleChat bridge
2 parents e480b38 + e792b16 commit 53a3024

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy