Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Notifier] Add Esendex message ID to SentMessage object #42748

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
Aug 26, 2021
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
[Notifier] Add Esendex message ID to SentMessage object
The Esendex API request returns a unique message ID for each SMS sent.
This commit simply extracts the message ID and adds it to the
returned SentMessage object.
  • Loading branch information
benr77 committed Aug 26, 2021
commit 3489e448bb2e3dee71cc9692b61a4d6e1d72ba13
2 changes: 2 additions & 0 deletions 2 src/Symfony/Component/Notifier/Bridge/Esendex/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
CHANGELOG
=========

* Add returned message ID to `SentMessage`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Add returned message ID to `SentMessage`
5.4
---
* Add returned message ID to `SentMessage`


5.3
---

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

$response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/v1.0/messagedispatcher', [
'auth_basic' => sprintf('%s:%s', $this->email, $this->password),
'headers' => [
fabpot marked this conversation as resolved.
Show resolved Hide resolved
'Accept' => 'application/json',
],
'json' => [
'accountreference' => $this->accountReference,
'messages' => [$messageData],
Expand All @@ -82,7 +85,15 @@ protected function doSend(MessageInterface $message): SentMessage
}

if (200 === $statusCode) {
return new SentMessage($message, (string) $this);
$result = $response->toArray();
$sentMessage = new SentMessage($message, (string) $this);

$messageId = $result['batch']['messageheaders'][0]['id'] ?? null;
if ($messageId) {
$sentMessage->setMessageId($messageId);
}

return $sentMessage;
}

$message = sprintf('Unable to send the SMS: error %d.', $statusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Test\TransportTestCase;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;

Expand Down Expand Up @@ -88,4 +89,26 @@ public function testSendWithErrorResponseContainingDetailsThrowsTransportExcepti

$transport->send(new SmsMessage('phone', 'testMessage'));
}

public function testSendWithSuccessfulResponseDispatchesMessageEvent()
{
$messageId = Uuid::v4()->toRfc4122();
$response = $this->createMock(ResponseInterface::class);
$response->expects($this->exactly(2))
->method('getStatusCode')
->willReturn(200);
$response->expects($this->once())
->method('getContent')
->willReturn(json_encode(['batch' => ['messageheaders' => [['id' => $messageId]]]]));

$client = new MockHttpClient(static function () use ($response): ResponseInterface {
return $response;
});

$transport = $this->createTransport($client);

$sentMessage = $transport->send(new SmsMessage('phone', 'testMessage'));

$this->assertSame($messageId, $sentMessage->getMessageId());
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.