Skip to content

[Notifier] Add from in SmsMessage #45987

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
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 @@ -61,11 +61,13 @@ protected function doSend(MessageInterface $message): SentMessage
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
}

$from = $message->getFrom() ?: $this->from;

$endpoint = sprintf('https://%s/sms/send/', $this->getEndpoint());
$response = $this->client->request('POST', $endpoint, [
'auth_basic' => $this->login.':'.$this->apiKey,
'json' => [
'from' => $this->from,
'from' => $from,
'to' => $message->getPhone(),
'text' => $message->getSubject(),
],
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Notifier/Bridge/AllMySms/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.2
---

* Use `SmsMessage->from` when defined

5.3
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Notifier\Bridge\AmazonSns;

use AsyncAws\Sns\SnsClient;
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\ChatMessage;
Expand Down Expand Up @@ -53,6 +54,10 @@ protected function doSend(MessageInterface $message): SentMessage
throw new UnsupportedMessageTypeException(__CLASS__, sprintf('"%s" or "%s"', SmsMessage::class, ChatMessage::class), $message);
}

if ($message instanceof SmsMessage && '' !== $message->getFrom()) {
throw new InvalidArgumentException(sprintf('The "%s" transport does not support "from" in "%s".', __CLASS__, SmsMessage::class));
}

if ($message instanceof ChatMessage && $message->getOptions() instanceof AmazonSnsOptions) {
$options = $message->getOptions()->toArray();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.2
---

* Throw exception when `SmsMessage->from` defined

5.4
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use AsyncAws\Sns\SnsClient;
use Symfony\Component\Notifier\Bridge\AmazonSns\AmazonSnsOptions;
use Symfony\Component\Notifier\Bridge\AmazonSns\AmazonSnsTransport;
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
Expand Down Expand Up @@ -46,6 +47,16 @@ public function unsupportedMessagesProvider(): iterable
yield [new ChatMessage('hello', $this->createMock(MessageOptionsInterface::class))];
}

public function testSmsMessageWithFrom()
{
$transport = $this->createTransport();

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The "Symfony\Component\Notifier\Bridge\AmazonSns\AmazonSnsTransport" transport does not support "from" in "Symfony\Component\Notifier\Message\SmsMessage".');

$transport->send(new SmsMessage('0600000000', 'test', 'foo'));
}

public function testSmsMessageOptions()
{
$response = $this->createMock(PublishResponse::class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.2
---

* Use `SmsMessage->from` when defined

5.3
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ protected function doSend(MessageInterface $message): SentMessage

$endpoint = sprintf('https://%s/rest/message', $this->getEndpoint());

$from = $message->getFrom() ?: $this->from;

$response = $this->client->request('POST', $endpoint, [
'headers' => [
'Accept' => 'application/json',
Expand All @@ -69,7 +71,7 @@ protected function doSend(MessageInterface $message): SentMessage
'X-Version' => 1,
],
'json' => [
'from' => $this->from ?? '',
'from' => $from ?? '',
'to' => [$message->getPhone()],
'text' => $message->getSubject(),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ CHANGELOG
---

* Add the bridge
* Throw exception when `SmsMessage->from` defined
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Notifier\Bridge\ContactEveryone;

use Symfony\Component\Notifier\Exception\InvalidArgumentException;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface;
Expand Down Expand Up @@ -67,6 +68,10 @@ protected function doSend(MessageInterface $message): SentMessage
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
}

if ('' !== $message->getFrom()) {
throw new InvalidArgumentException(sprintf('The "%s" transport does not support "from" in "%s".', __CLASS__, SmsMessage::class));
}

$endpoint = sprintf('https://%s/api/light/diffusions/sms', self::HOST);
$response = $this->client->request('POST', $endpoint, [
'query' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\ContactEveryone\ContactEveryoneTransport;
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
Expand Down Expand Up @@ -60,4 +61,14 @@ public function testSendSuccessfully()

$this->assertSame($messageId, $sentMessage->getMessageId());
}

public function testSmsMessageWithFrom()
{
$transport = $this->createTransport();

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The "Symfony\Component\Notifier\Bridge\ContactEveryone\ContactEveryoneTransport" transport does not support "from" in "Symfony\Component\Notifier\Message\SmsMessage".');

$transport->send(new SmsMessage('0600000000', 'test', 'foo'));
}
}
5 changes: 5 additions & 0 deletions src/Symfony/Component/Notifier/Bridge/Esendex/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.2
---

* Use `SmsMessage->from` when defined

5.4
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ protected function doSend(MessageInterface $message): SentMessage
'body' => $message->getSubject(),
];

if (null !== $this->from) {
if ('' !== $message->getFrom()) {
$messageData['from'] = $message->getFrom();
} elseif (null !== $this->from) {
$messageData['from'] = $this->from;
}

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Notifier/Bridge/FakeSms/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.2
---

* Use `SmsMessage->from` when defined

5.4
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ protected function doSend(MessageInterface $message): SentMessage
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
}

$from = $message->getFrom() ?: $this->from;

$email = (new Email())
->from($this->from)
->from($from)
->to($this->to)
->subject(sprintf('New SMS on phone number: %s', $message->getPhone()))
->html($message->getSubject())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.2
---

* Use `SmsMessage->from` when defined

6.1
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ protected function doSend(MessageInterface $message): SentMessage
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
}

$from = $message->getFrom() ?: $this->from;

$endpoint = sprintf('https://%s/a1/sms', self::HOST);
$response = $this->client->request('POST', $endpoint, [
'body' => [
'from' => $this->from,
'from' => $from,
'to' => $message->getPhone(),
'message' => $message->getSubject(),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.2
---

* Use `SmsMessage->from` when defined

5.3
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Notifier\Bridge\FreeMobile;

use Symfony\Component\Notifier\Exception\InvalidArgumentException;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
use Symfony\Component\Notifier\Message\MessageInterface;
Expand Down Expand Up @@ -57,6 +58,11 @@ protected function doSend(MessageInterface $message): SentMessage
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
}

/** @var SmsMessage $message */
if ('' !== $message->getFrom()) {
throw new InvalidArgumentException(sprintf('The "%s" transport does not support "from" in "%s".', __CLASS__, SmsMessage::class));
}

$endpoint = sprintf('https://%s', $this->getEndpoint());

$response = $this->client->request('POST', $endpoint, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Notifier\Bridge\FreeMobile\Tests;

use Symfony\Component\Notifier\Bridge\FreeMobile\FreeMobileTransport;
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\MessageInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
Expand Down Expand Up @@ -42,4 +43,14 @@ public function unsupportedMessagesProvider(): iterable
yield [new ChatMessage('Hello!')];
yield [$this->createMock(MessageInterface::class)];
}

public function testSmsMessageWithFrom()
{
$transport = $this->createTransport();

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The "Symfony\Component\Notifier\Bridge\FreeMobile\FreeMobileTransport" transport does not support "from" in "Symfony\Component\Notifier\Message\SmsMessage".');

$transport->send(new SmsMessage('+33611223344', 'test', 'foo'));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.2
---

* Use `SmsMessage->from` when defined

5.3
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ protected function doSend(MessageInterface $message): SentMessage
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
}

$from = $message->getFrom() ?: $this->from;

$endpoint = sprintf('https://%s/rest/mtsms', $this->getEndpoint());

$response = $this->client->request('POST', $endpoint, [
'auth_basic' => [$this->authToken, ''],
'json' => [
'sender' => $this->from,
'sender' => $from,
'recipients' => [['msisdn' => $message->getPhone()]],
'message' => $message->getSubject(),
],
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Notifier/Bridge/Infobip/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.2
---

* Use `SmsMessage->from` when defined

5.3
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ protected function doSend(MessageInterface $message): SentMessage
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
}

$from = $message->getFrom() ?: $this->from;

$endpoint = sprintf('https://%s/sms/2/text/advanced', $this->getEndpoint());

$response = $this->client->request('POST', $endpoint, [
Expand All @@ -63,7 +65,7 @@ protected function doSend(MessageInterface $message): SentMessage
'json' => [
'messages' => [
[
'from' => $this->from,
'from' => $from,
'destinations' => [
[
'to' => $message->getPhone(),
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Notifier/Bridge/Iqsms/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.2
---

* Use `SmsMessage->from` when defined

5.3
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ protected function doSend(MessageInterface $message): SentMessage
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
}

$from = $message->getFrom() ?: $this->from;

$response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/messages/v2/send.json', [
'json' => [
'messages' => [
[
'phone' => $message->getPhone(),
'text' => $message->getSubject(),
'sender' => $this->from,
'sender' => $from,
'clientId' => uniqid(),
],
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.2
---

* Use `SmsMessage->from` when defined

6.1
---

Expand Down
Loading