Description
Symfony version(s) affected
7.0.8
Description
Hey.
I know. Nobody use Google Chat :D
When using Notifier component with Google Chat as notification channel there is a problem when you want to send messages into thread. Currently in transport implementation (GoogleChatTransport.php
) the threadKey
is added in URL. That options is deprecated (https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.messages/create?hl=en). Also if you want to send message into thread you also must define a messageReplyOption
that is missing in current implementation.
So even if you define a threadKey
, messages will be always sent to as new thread.
How to reproduce
Fragment of my code:
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatOptions;
use Symfony\Component\Notifier\ChatterInterface;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Notification\Notification;
class SendNotificationToGoogleChat
{
public function __construct(
private ChatterInterface $chatter,
) {
}
public function send(): void
{
$subject = 'Topic';
$content = 'Message';
$notification = (new Notification($subject, ['chat/google']))->content($content);
$options = (new GoogleChatOptions(GoogleChatOptions::fromNotification($notification)->toArray()));
$options->setThreadKey('threadKey');
$message = ChatMessage::fromNotification($notification)->options($options);
$this->chatter->send($message);
}
}
Possible Solution
I see three possible solutions.
- Just add
&messageReplyOption=REPLY_MESSAGE_FALLBACK_TO_NEW_THREAD
to$url
inGoogleChatTransport
ifthreadKey
is defined. - Add to
GoogleChatOptions
property withmessageReplyOption
that user can define for his own. - Also refactor deprecated code. Removes
threadKey
from$url
and add it in body like documentation says.
Additional Context
I also have ready and tested fix so I can send a PR but didn't sure for which versions in should be. If you help me with this I can add a PR with my changes for review.