PHP code example of norialabs / send

1. Go to this page and download the library: Download norialabs/send library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

norialabs / send example snippets


// config/mail.php
'mailers' => [
    'noria' => ['transport' => 'noria'],
],

use Illuminate\Notifications\Notification;
use NoriaLabs\Send\Notifications\SmsMessage;

class OtpIssued extends Notification
{
    public function __construct(private string $code) {}

    public function via($notifiable): array
    {
        return ['send-sms'];
    }

    public function toSendSms($notifiable): SmsMessage
    {
        return SmsMessage::make("Your code is {$this->code}")
            ->sender('NORIA')
            ->tags(['kind' => 'otp'])
            ->idempotencyKey("otp-{$this->code}");
    }
}

public function routeNotificationForSendSms(): string
{
    return $this->phone;
}

use NoriaLabs\Send\Facades\Send;

Send::sms()->send(['from' => 'NORIA', 'to' => '0712345678', 'text' => 'Your code is 482913']);
Send::domains()->create('norialabs.com');       // returns the DNS records to publish
Send::senders()->create('NORIA');               // registered pending approval
Send::templates()->upsert(['slug' => 'otp', 'channel' => 'sms', 'text' => 'Code {{code}}']);
Send::suppressions()->add('0712345678', 'sms', 'unsubscribe');
Send::suppressions()->has('0712345678', 'sms');
Send::messages()->list(['channel' => 'sms', 'status' => 'failed']);
Send::messages()->events($messageId);
Send::messages()->requeue($messageId);

use NoriaLabs\Send\SendTransport;

Mail::html($body, function ($message) {
    $message->to($user->email)->subject('Your sign-in link');

    $headers = $message->getHeaders();
    $headers->addTextHeader(SendTransport::TAG_HEADER.'-product', 'zana');
    $headers->addTextHeader(SendTransport::IDEMPOTENCY_HEADER, "signin-{$token->id}");
    $headers->addTextHeader(SendTransport::SCHEDULE_HEADER, now()->addHour()->toIso8601String());
});

use NoriaLabs\Send\WebhookVerifier;

Route::post('/webhooks/send', function (Request $request, WebhookVerifier $verifier) {
    $event = $verifier->verify($request->getContent(), $request->header('Noria-Signature', ''));

    // $event['data']['channel'] is email or sms
    // $event['type'] is delivered, bounced, complained, opened, clicked, failed, …
});
bash
NORIA_SEND_LIVE_KEY=nm_live_… vendor/bin/pest tests/LiveTest.php