Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit96dfc56

Browse files
author
alanzarli
committed
[Notifier][Webhook] Add Smsbox support
1 parent8c941de commit96dfc56

File tree

8 files changed

+122
-3
lines changed

8 files changed

+122
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,6 +3045,7 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
30453045
$loader->load('notifier_webhook.php');
30463046

30473047
$webhookRequestParsers = [
3048+
NotifierBridge\Smsbox\Webhook\SmsboxRequestParser::class =>'notifier.webhook.request_parser.smsbox',
30483049
NotifierBridge\Sweego\Webhook\SweegoRequestParser::class =>'notifier.webhook.request_parser.sweego',
30493050
NotifierBridge\Twilio\Webhook\TwilioRequestParser::class =>'notifier.webhook.request_parser.twilio',
30503051
NotifierBridge\Vonage\Webhook\VonageRequestParser::class =>'notifier.webhook.request_parser.vonage',

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111

1212
namespaceSymfony\Component\DependencyInjection\Loader\Configurator;
1313

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

1819
returnstaticfunction (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/Bundle/SecurityBundle/Tests/Functional/AccessTokenTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public function testCasSuccess()
425425
$this->assertSame(['message' =>'Welcome @dunglas!'],json_decode($response->getContent(),true));
426426
}
427427

428-
publicfunctionvalidAccessTokens():array
428+
publicstaticfunctionvalidAccessTokens():array
429429
{
430430
if (!\extension_loaded('openssl')) {
431431
return [];
@@ -440,8 +440,8 @@ public function validAccessTokens(): array
440440
'sub' =>'e21bf182-1538-406e-8ccb-e25a17aba39f',
441441
'username' =>'dunglas',
442442
];
443-
$jws =$this->createJws($claims);
444-
$jwe =$this->createJwe($jws);
443+
$jws =self::createJws($claims);
444+
$jwe =self::createJwe($jws);
445445

446446
return [
447447
[$jws],

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

Lines 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. 🚀
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
useSymfony\Component\RemoteEvent\Event\Sms\SmsEvent;
4+
5+
parse_str(trim(file_get_contents(str_replace('.php','.txt',__FILE__))),$payload);
6+
$wh =newSmsEvent(SmsEvent::DELIVERED,'250207960297',$payload);
7+
$wh->setRecipientPhone('33612346578');
8+
9+
return$wh;
Lines 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
Lines 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+
namespaceSymfony\Component\Notifier\Bridge\Smsbox\Tests\Webhook;
13+
14+
useSymfony\Component\HttpFoundation\Request;
15+
useSymfony\Component\Notifier\Bridge\Smsbox\Webhook\SmsboxRequestParser;
16+
useSymfony\Component\Webhook\Client\RequestParserInterface;
17+
useSymfony\Component\Webhook\Test\AbstractRequestParserTestCase;
18+
19+
class SmsboxRequestParserTestextends AbstractRequestParserTestCase
20+
{
21+
protectedfunctioncreateRequestParser():RequestParserInterface
22+
{
23+
returnnewSmsboxRequestParser();
24+
}
25+
26+
protectedfunctioncreateRequest(string$payload):Request
27+
{
28+
parse_str(trim($payload),$parameters);
29+
30+
return Request::create('/','GET',$parameters, [], [], []);
31+
}
32+
33+
protectedstaticfunctiongetFixtureExtension():string
34+
{
35+
return'txt';
36+
}
37+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
namespaceSymfony\Component\Notifier\Bridge\Smsbox\Webhook;
13+
14+
useSymfony\Component\HttpFoundation\Request;
15+
useSymfony\Component\HttpFoundation\RequestMatcher\MethodRequestMatcher;
16+
useSymfony\Component\HttpFoundation\RequestMatcherInterface;
17+
useSymfony\Component\HttpFoundation\ChainRequestMatcher;
18+
useSymfony\Component\RemoteEvent\Event\Sms\SmsEvent;
19+
useSymfony\Component\Webhook\Client\AbstractRequestParser;
20+
useSymfony\Component\Webhook\Exception\RejectWebhookException;
21+
22+
23+
finalclass SmsboxRequestParserextends AbstractRequestParser
24+
{
25+
protectedfunctiongetRequestMatcher():RequestMatcherInterface
26+
{
27+
returnnewMethodRequestMatcher(['GET']);
28+
}
29+
30+
protectedfunctiondoParse(Request$request, #[\SensitiveParameter]string$secret): ?SmsEvent
31+
{
32+
$payload =$request->query->all();
33+
34+
if (
35+
!isset($payload['numero'])
36+
|| !isset($payload['reference'])
37+
|| !isset($payload['accuse'])
38+
|| !isset($payload['ts'])
39+
) {
40+
thrownewRejectWebhookException(406,'Payload is malformed.');
41+
}
42+
43+
$name =match ($payload['accuse']) {
44+
// Documentation for SMSBOX dlr code https://www.smsbox.net/en/tools-development#doc-sms-accusees
45+
'-3' => SmsEvent::FAILED,
46+
'-1' =>null,
47+
'0' => SmsEvent::DELIVERED,
48+
'1' => SmsEvent::FAILED,
49+
'2' => SmsEvent::FAILED,
50+
'3' => SmsEvent::FAILED,
51+
'4' => SmsEvent::FAILED,
52+
'5' => SmsEvent::FAILED,
53+
'6' => SmsEvent::FAILED,
54+
'7' => SmsEvent::FAILED,
55+
'8' => SmsEvent::FAILED,
56+
'9' =>null,
57+
'10' =>null,
58+
default =>thrownewRejectWebhookException(406,\sprintf('Unknown status: %s',$payload['accuse'])),
59+
};
60+
61+
$event =newSmsEvent($name,$payload['reference'],$payload);
62+
$event->setRecipientPhone($payload['numero']);
63+
64+
return$event;
65+
}
66+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp