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

Commit 35202a2

Browse filesBrowse files
committed
feature #59570 [Notifier][Webhook] Add Smsbox support (alanzarli)
This PR was merged into the 7.3 branch. Discussion ---------- [Notifier][Webhook] Add Smsbox support | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | License | MIT |Doc | [#20590](symfony/symfony-docs#20590) Add support for Webhook to Smsbox Notifier Event statuses come from Smsbox [documentation](https://en.smsbox.net/docs/doc-APIReceive-SMSBOX-EN.pdf). Commits ------- 08062e8 [Notifier][Webhook] Add Smsbox support
2 parents 329920d + 08062e8 commit 35202a2
Copy full SHA for 35202a2

File tree

8 files changed

+132
-0
lines changed
Filter options

8 files changed

+132
-0
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,6 +3116,7 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
31163116
$loader->load('notifier_webhook.php');
31173117

31183118
$webhookRequestParsers = [
3119+
NotifierBridge\Smsbox\Webhook\SmsboxRequestParser::class => 'notifier.webhook.request_parser.smsbox',
31193120
NotifierBridge\Sweego\Webhook\SweegoRequestParser::class => 'notifier.webhook.request_parser.sweego',
31203121
NotifierBridge\Twilio\Webhook\TwilioRequestParser::class => 'notifier.webhook.request_parser.twilio',
31213122
NotifierBridge\Vonage\Webhook\VonageRequestParser::class => 'notifier.webhook.request_parser.vonage',

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_webhook.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_webhook.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

14+
use Symfony\Component\Notifier\Bridge\Smsbox\Webhook\SmsboxRequestParser;
1415
use Symfony\Component\Notifier\Bridge\Sweego\Webhook\SweegoRequestParser;
1516
use Symfony\Component\Notifier\Bridge\Twilio\Webhook\TwilioRequestParser;
1617
use Symfony\Component\Notifier\Bridge\Vonage\Webhook\VonageRequestParser;
1718

1819
return static function (ContainerConfigurator $container) {
1920
$container->services()
21+
->set('notifier.webhook.request_parser.smsbox', SmsboxRequestParser::class)
22+
->alias(SmsboxRequestParser::class, 'notifier.webhook.request_parser.smsbox')
23+
2024
->set('notifier.webhook.request_parser.sweego', SweegoRequestParser::class)
2125
->alias(SweegoRequestParser::class, 'notifier.webhook.request_parser.sweego')
2226

‎src/Symfony/Component/Notifier/Bridge/Smsbox/README.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Smsbox/README.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ $options = (new SmsboxOptions())
5454
$sms->options($options);
5555
$texter->send($sms);
5656
```
57+
## Smsbox notifier also provides Webhooks support. 🚀
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
use Symfony\Component\RemoteEvent\Event\Sms\SmsEvent;
4+
5+
parse_str(trim(file_get_contents(str_replace('.php', '.txt', __FILE__))), $payload);
6+
$wh = new SmsEvent(SmsEvent::DELIVERED, '250207960297', $payload);
7+
$wh->setRecipientPhone('33612346578');
8+
9+
return $wh;
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
numero=33612346578&reference=250207960297&accuse=0&ts=1737368770
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Smsbox\Tests\Webhook;
13+
14+
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\Notifier\Bridge\Smsbox\Webhook\SmsboxRequestParser;
16+
use Symfony\Component\Webhook\Client\RequestParserInterface;
17+
use Symfony\Component\Webhook\Test\AbstractRequestParserTestCase;
18+
19+
class SmsboxRequestParserTest extends AbstractRequestParserTestCase
20+
{
21+
protected function createRequestParser(): RequestParserInterface
22+
{
23+
return new SmsboxRequestParser();
24+
}
25+
26+
protected function createRequest(string $payload): Request
27+
{
28+
parse_str(trim($payload), $parameters);
29+
30+
return Request::create('/', 'GET', $parameters, [], [], ['REMOTE_ADDR' => '37.59.198.135']);
31+
}
32+
33+
protected static function getFixtureExtension(): string
34+
{
35+
return 'txt';
36+
}
37+
}
+76Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Smsbox\Webhook;
13+
14+
use Symfony\Component\HttpFoundation\ChainRequestMatcher;
15+
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\HttpFoundation\RequestMatcher\IpsRequestMatcher;
17+
use Symfony\Component\HttpFoundation\RequestMatcher\MethodRequestMatcher;
18+
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
19+
use Symfony\Component\RemoteEvent\Event\Sms\SmsEvent;
20+
use Symfony\Component\Webhook\Client\AbstractRequestParser;
21+
use Symfony\Component\Webhook\Exception\RejectWebhookException;
22+
23+
final class SmsboxRequestParser extends AbstractRequestParser
24+
{
25+
protected function getRequestMatcher(): RequestMatcherInterface
26+
{
27+
return new ChainRequestMatcher([
28+
new MethodRequestMatcher(['GET']),
29+
new IpsRequestMatcher([
30+
'37.59.198.135',
31+
'178.33.185.51',
32+
'54.36.93.79',
33+
'54.36.93.80',
34+
'62.4.31.47',
35+
'62.4.31.48',
36+
]),
37+
]);
38+
}
39+
40+
protected function doParse(Request $request, #[\SensitiveParameter] string $secret): ?SmsEvent
41+
{
42+
$payload = $request->query->all();
43+
44+
if (
45+
!isset($payload['numero'])
46+
|| !isset($payload['reference'])
47+
|| !isset($payload['accuse'])
48+
|| !isset($payload['ts'])
49+
) {
50+
throw new RejectWebhookException(406, 'Payload is malformed.');
51+
}
52+
53+
$name = match ($payload['accuse']) {
54+
// Documentation for SMSBOX dlr code https://www.smsbox.net/en/tools-development#doc-sms-accusees
55+
'-3' => SmsEvent::FAILED,
56+
'-1' => null,
57+
'0' => SmsEvent::DELIVERED,
58+
'1' => SmsEvent::FAILED,
59+
'2' => SmsEvent::FAILED,
60+
'3' => SmsEvent::FAILED,
61+
'4' => SmsEvent::FAILED,
62+
'5' => SmsEvent::FAILED,
63+
'6' => SmsEvent::FAILED,
64+
'7' => SmsEvent::FAILED,
65+
'8' => SmsEvent::FAILED,
66+
'9' => null,
67+
'10' => null,
68+
default => throw new RejectWebhookException(406, \sprintf('Unknown status: %s', $payload['accuse'])),
69+
};
70+
71+
$event = new SmsEvent($name, $payload['reference'], $payload);
72+
$event->setRecipientPhone($payload['numero']);
73+
74+
return $event;
75+
}
76+
}

‎src/Symfony/Component/Notifier/Bridge/Smsbox/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Smsbox/composer.json
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
"symfony/notifier": "^7.2",
3131
"symfony/polyfill-php83": "^1.28"
3232
},
33+
"require-dev": {
34+
"symfony/webhook": "^6.4|^7.0|^7.2"
35+
},
3336
"autoload": {
3437
"psr-4": {
3538
"Symfony\\Component\\Notifier\\Bridge\\Smsbox\\": ""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.