SmsEvent example

<?php
use Symfony\Component\RemoteEvent\Event\Sms\SmsEvent;

$wh = new SmsEvent(SmsEvent::FAILED, 'aaaaaaaa-bbbb-cccc-dddd-0123456789ab', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: \JSON_THROW_ON_ERROR));
$wh->setRecipientPhone('447700900000');

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Sms\SmsEvent;

$wh = new SmsEvent(SmsEvent::DELIVERED, 'aaaaaaaa-bbbb-cccc-dddd-0123456789ab', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: \JSON_THROW_ON_ERROR));
$wh->setRecipientPhone('447700900000');

return $wh;
<?php
use Symfony\Component\RemoteEvent\Event\Sms\SmsEvent;

$wh = new SmsEvent(SmsEvent::FAILED, 'aaaaaaaa-bbbb-cccc-dddd-0123456789ab', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true, flags: \JSON_THROW_ON_ERROR));
$wh->setRecipientPhone('447700900000');

return $wh;
$name = match ($payload['status']) {
            'delivered' => SmsEvent::DELIVERED,
            'rejected' => SmsEvent::FAILED,
            'submitted' => null,
            'undeliverable' => SmsEvent::FAILED,
            default => throw new RejectWebhookException(406, sprintf('Unsupported event "%s".', $payload['status'])),
        };
        if (!$name) {
            return null;
        }

        $event = new SmsEvent($name$payload['message_uuid']$payload);
        $event->setRecipientPhone($payload['to']);

        return $event;
    }

    private function validateSignature(string $jwt, string $secret): void
    {
        $tokenParts = explode('.', $jwt);
        if (3 !== \count($tokenParts)) {
            throw new RejectWebhookException(406, 'Signature is wrong.');
        }

        [
'sending' => null,
            'sent' => null,
            'canceled' => null,
            'receiving' => null,
            'received' => null,
            'scheduled' => null,
            default => throw new RejectWebhookException(406, sprintf('Unsupported event "%s".', $payload['event'])),
        };
        if (!$name) {
            return null;
        }
        $event = new SmsEvent($name$payload['MessageSid']$payload);
        $event->setRecipientPhone($payload['To']);

        return $event;
    }
}
<?php
use Symfony\Component\RemoteEvent\Event\Sms\SmsEvent;

parse_str(trim(file_get_contents(str_replace('.php', '.txt', __FILE__)))$payload);
$wh = new SmsEvent(SmsEvent::DELIVERED, 'SM4262411b90e5464b98a4f66a49c57a97', $payload);
$wh->setRecipientPhone('+15622089096');

return $wh;


namespace Symfony\Component\RemoteEvent\Tests\Event\Sms;

use PHPUnit\Framework\TestCase;
use Symfony\Component\RemoteEvent\Event\Sms\SmsEvent;

class SmsEventTest extends TestCase
{
    public function testPhone()
    {
        $event = new SmsEvent('name', 'id', []);
        $event->setRecipientPhone($phone = '0102030405');
        $this->assertSame($phone$event->getRecipientPhone());
    }
}
Home | Imprint | This part of the site doesn't use cookies.