From a3a7d7afa4e6923b9c5acc37bd510405bc002e09 Mon Sep 17 00:00:00 2001 From: "robin.de.croock" Date: Mon, 24 Apr 2023 17:55:09 +0200 Subject: [PATCH] Allow sending scheduled messages through the slack API --- .../Component/Notifier/Bridge/Slack/SlackOptions.php | 10 ++++++++++ .../Component/Notifier/Bridge/Slack/SlackTransport.php | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/Symfony/Component/Notifier/Bridge/Slack/SlackOptions.php b/src/Symfony/Component/Notifier/Bridge/Slack/SlackOptions.php index f6fe5d5411e18..dc7831d592b0a 100644 --- a/src/Symfony/Component/Notifier/Bridge/Slack/SlackOptions.php +++ b/src/Symfony/Component/Notifier/Bridge/Slack/SlackOptions.php @@ -87,6 +87,16 @@ public function asUser(bool $bool): static return $this; } + /** + * @return $this + */ + public function postAt(\DateTime $timestamp): static + { + $this->options['post_at'] = $timestamp->getTimestamp(); + + return $this; + } + /** * @return $this */ diff --git a/src/Symfony/Component/Notifier/Bridge/Slack/SlackTransport.php b/src/Symfony/Component/Notifier/Bridge/Slack/SlackTransport.php index d8235f48aa8d8..39e570d419fba 100644 --- a/src/Symfony/Component/Notifier/Bridge/Slack/SlackTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/Slack/SlackTransport.php @@ -76,6 +76,10 @@ protected function doSend(MessageInterface $message): SlackSentMessage $options['text'] = $message->getSubject(); $apiMethod = $message->getOptions() instanceof UpdateMessageSlackOptions ? 'chat.update' : 'chat.postMessage'; + if (\array_key_exists('post_at', $options)) { + $apiMethod = 'chat.scheduleMessage'; + } + $response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/api/'.$apiMethod, [ 'json' => array_filter($options), 'auth_bearer' => $this->accessToken,