Skip to content

Add Notifier SentMessage #36611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Transport\AbstractTransport;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
Expand Down Expand Up @@ -50,7 +51,7 @@ public function supports(MessageInterface $message): bool
return $message instanceof ChatMessage;
}

protected function doSend(MessageInterface $message): void
protected function doSend(MessageInterface $message): SentMessage
{
if (!$message instanceof ChatMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, get_debug_type($message)));
Expand Down Expand Up @@ -84,5 +85,12 @@ protected function doSend(MessageInterface $message): void
if ($jsonContents && isset($jsonContents['results']['error'])) {
throw new TransportException(sprintf('Unable to post the Firebase message: %s.', $jsonContents['error']), $response);
}

$success = $response->toArray(false);

$message = new SentMessage($message, (string) $this);
$message->setMessageId($success['results'][0]['message_id']);

return $message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.0"
"symfony/notifier": "^5.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Firebase\\": "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Transport\AbstractTransport;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -51,7 +52,7 @@ public function supports(MessageInterface $message): bool
return $message instanceof SmsMessage && $this->phone === $message->getPhone();
}

protected function doSend(MessageInterface $message): void
protected function doSend(MessageInterface $message): SentMessage
{
if (!$this->supports($message)) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given) and configured with your phone number.', __CLASS__, SmsMessage::class, \get_class($message)));
Expand All @@ -75,5 +76,7 @@ protected function doSend(MessageInterface $message): void

throw new TransportException(sprintf('Unable to send the SMS: error %d: ', $response->getStatusCode()).($errors[$response->getStatusCode()] ?? ''), $response);
}

return new SentMessage($message, (string) $this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.1",
"symfony/notifier": "^5.1"
"symfony/notifier": "^5.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\FreeMobile\\": "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Transport\AbstractTransport;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
Expand Down Expand Up @@ -50,7 +51,7 @@ public function supports(MessageInterface $message): bool
/**
* @see https://api.mattermost.com
*/
protected function doSend(MessageInterface $message): void
protected function doSend(MessageInterface $message): SentMessage
{
if (!$message instanceof ChatMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, get_debug_type($message)));
Expand All @@ -74,5 +75,12 @@ protected function doSend(MessageInterface $message): void

throw new TransportException(sprintf('Unable to post the Mattermost message: %s (%s).', $result['message'], $result['id']), $response);
}

$success = $response->toArray(false);

$message = new SentMessage($message, (string) $this);
$message->setMessageId($success['id']);

return $message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.0"
"symfony/notifier": "^5.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Mattermost\\": "" },
Expand Down
10 changes: 9 additions & 1 deletion src/Symfony/Component/Notifier/Bridge/Nexmo/NexmoTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Transport\AbstractTransport;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -51,7 +52,7 @@ public function supports(MessageInterface $message): bool
return $message instanceof SmsMessage;
}

protected function doSend(MessageInterface $message): void
protected function doSend(MessageInterface $message): SentMessage
{
if (!$message instanceof SmsMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, get_debug_type($message)));
Expand All @@ -73,5 +74,12 @@ protected function doSend(MessageInterface $message): void
throw new TransportException('Unable to send the SMS: '.$msg['error-text'].sprintf(' (code %s).', $msg['status']), $response);
}
}

$success = $response->toArray(false);

$message = new SentMessage($message, (string) $this);
$message->setMessageId($success['messages'][0]['message-id']);

return $message;
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Notifier/Bridge/Nexmo/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.0"
"symfony/notifier": "^5.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Nexmo\\": "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Transport\AbstractTransport;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -53,7 +54,7 @@ public function supports(MessageInterface $message): bool
return $message instanceof SmsMessage;
}

protected function doSend(MessageInterface $message): void
protected function doSend(MessageInterface $message): SentMessage
{
if (!$message instanceof SmsMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, get_debug_type($message)));
Expand Down Expand Up @@ -90,6 +91,13 @@ protected function doSend(MessageInterface $message): void

throw new TransportException(sprintf('Unable to send the SMS: %s.', $error['message']), $response);
}

$success = $response->toArray(false);

$message = new SentMessage($message, (string) $this);
$message->setMessageId($success['ids'][0]);

return $message;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.0"
"symfony/notifier": "^5.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\OvhCloud\\": "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Transport\AbstractTransport;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
Expand Down Expand Up @@ -55,7 +56,7 @@ public function supports(MessageInterface $message): bool
/**
* @see https://rocket.chat/docs/administrator-guides/integrations/
*/
protected function doSend(MessageInterface $message): void
protected function doSend(MessageInterface $message): SentMessage
{
if (!$message instanceof ChatMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, get_debug_type($message)));
Expand Down Expand Up @@ -86,5 +87,12 @@ protected function doSend(MessageInterface $message): void
if (!$result['success']) {
throw new TransportException(sprintf('Unable to post the RocketChat message: %s.', $result['error']), $response);
}

$success = $response->toArray(false);

$message = new SentMessage($message, (string) $this);
$message->setMessageId($success['message']['_id']);

return $message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.0"
"symfony/notifier": "^5.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\RocketChat\\": "" },
Expand Down
10 changes: 9 additions & 1 deletion src/Symfony/Component/Notifier/Bridge/Sinch/SinchTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Transport\AbstractTransport;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -51,7 +52,7 @@ public function supports(MessageInterface $message): bool
return $message instanceof SmsMessage;
}

protected function doSend(MessageInterface $message): void
protected function doSend(MessageInterface $message): SentMessage
{
if (!$message instanceof SmsMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, get_debug_type($message)));
Expand All @@ -72,5 +73,12 @@ protected function doSend(MessageInterface $message): void

throw new TransportException(sprintf('Unable to send the SMS: %s (%s).', $error['text'], $error['code']), $response);
}

$success = $response->toArray(false);

$message = new SentMessage($message, (string) $this);
$message->setMessageId($success['id']);

return $message;
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Notifier/Bridge/Sinch/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php": ">=7.2.5",
"ext-json": "*",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.0"
"symfony/notifier": "^5.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Sinch\\": "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Transport\AbstractTransport;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
Expand Down Expand Up @@ -58,7 +59,7 @@ public function supports(MessageInterface $message): bool
return $message instanceof ChatMessage && (null === $message->getOptions() || $message->getOptions() instanceof SlackOptions);
}

protected function doSend(MessageInterface $message): void
protected function doSend(MessageInterface $message): SentMessage
{
if (!$message instanceof ChatMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, get_debug_type($message)));
Expand Down Expand Up @@ -86,5 +87,7 @@ protected function doSend(MessageInterface $message): void
if ('ok' !== $result) {
throw new TransportException('Unable to post the Slack message: '.$result, $response);
}

return new SentMessage($message, (string) $this);
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Notifier/Bridge/Slack/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=7.2.5",
"symfony/http-client": "^4.3|^5.0",
"symfony/notifier": "^5.1"
"symfony/notifier": "^5.2"
},
"require-dev": {
"symfony/event-dispatcher": "^4.3|^5.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SentMessage;
use Symfony\Component\Notifier\Transport\AbstractTransport;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
Expand Down Expand Up @@ -60,7 +61,7 @@ public function supports(MessageInterface $message): bool
/**
* @see https://core.telegram.org/bots/api
*/
protected function doSend(MessageInterface $message): void
protected function doSend(MessageInterface $message): SentMessage
{
if (!$message instanceof ChatMessage) {
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, ChatMessage::class, get_debug_type($message)));
Expand All @@ -82,5 +83,12 @@ protected function doSend(MessageInterface $message): void

throw new TransportException('Unable to post the Telegram message: '.$result['description'].sprintf(' (code %s).', $result['error_code']), $response);
}

$success = $response->toArray(false);

$message = new SentMessage($message, (string) $this);
$message->setMessageId($success['result']['message_id']);

return $message;
}
}
Loading