LOX24 SMS Notifier
==================

Provides [LOX24 SMS Gateway](https://doc.lox24.eu/#tag/sms/operation/api_sms_post_collection) integration for Symfony
Notifier.

DSN example
-----------

```
LOX24_DSN=lox24://USER:TOKEN@default?from=FROM&type=TYPE&voice_lang=VOICE_LANGUAGE&delete_text=DELETE_TEXT&callback_data=CALLBACK_DATA
```

where:

 - `USER` (required) is LOX24 user ID.
 - `TOKEN` (required) is LOX24 API v2 token.
 - `FROM` (required) is the sender of the message.
 - `TYPE` (optional) type of message: `sms` (by default) or `voice` (voice call).
 - `VOICE_LANGUAGE` (optional) if `type` is `voice`, then you can set the language of the voice message. Possible
  values: `de`, `en`, `es`, `fr`, `it` or `auto` (by default) per auto-detection.
 - `DELETE_TEXT` (optional) delete SMS text from LOX24 database after sending SMS. Allowed values: `1` (true) or `0` (
  false). Default value: `0`.
 - `CALLBACK_DATA` (optional) additional data for the callback payload.

See your account info at https://account.lox24.eu

Send a Message
--------------

```php
use Symfony\Component\Notifier\Message\SmsMessage;

$sms = new SmsMessage('+1411111111', 'My message');

$texter->send($sms);
```

Advanced Message options
------------------------

```php
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Bridge\Lox24\Lox24Options;

$sms = new SmsMessage('+1411111111', 'My message');

$options = (new Lox24Options())
    // set 'voice' per voice call (text-to-speech)
    ->type('voice')
    // set the language of the voice message.
    // If not set or set 'auto', the automatic language detection by message text will be used
    ->voiceLanguage('en')
    // Date of the SMS delivery. If null or not set, the message will be sent immediately
    ->deliveryAt(new DateTime('2024-03-21 12:17:00'))
    // set True to delete the message from the LOX24 database after delivery
    ->deleteTextAfterSending(true)
    // pass any string to the callback object
    ->callbackData('some_data_per_callback');
    
// Add the custom options to the sms message and send the message
$sms->options($options);

$texter->send($sms);
```

Usage in Combination with the Notifier Component
------------------------------------------------

The usage of the Webhook component when using a third-party transport in
the Notifier is very similar to the usage with the Mailer.

Currently, the LOX24 SMS transport supports webhooks. Parser service name ``notifier.webhook.request_parser.lox24``.

For SMS webhooks, react to the class:`Symfony\\Component\\RemoteEvent\\Event\\Sms\\SmsEvent` event.

Other LOX24 webhooks are also possible to handle as class:`Symfony\\Component\\RemoteEvent\\RemoteEvent` instances:

```
    use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
    use Symfony\Component\RemoteEvent\Consumer\ConsumerInterface;
    use Symfony\Component\RemoteEvent\Event\Sms\SmsEvent;
    use Symfony\Component\RemoteEvent\RemoteEvent;

    #[AsRemoteEventConsumer('notifier_lox24')]
    class WebhookListener implements ConsumerInterface
    {
        public function consume(RemoteEvent $event): void
        {
            if ($event instanceof SmsEvent) {
                $this->handleSmsEvent($event);
            } else {
                // Handle other LOX24 webhook events
                $this->handleRemoteEvent($event);
            }
        }

        private function handleSmsEvent(SmsEvent $event): void
        {
            // Handle the SMS event
        }

        private function handleRemoteEvent(RemoteEvent $event): void
        {
            // Handle other LOX24 webhook events
        }
    }
```

Resources
---------

 * [Contributing](https://symfony.com/doc/current/contributing/index.html)
 * [Report issues](https://github.com/symfony/symfony/issues) and 
   [send Pull Requests](https://github.com/symfony/symfony/pulls) 
   in the [main Symfony repository](https://github.com/symfony/symfony)
