PHP code example of mcbankske / filament-sms-notifier

1. Go to this page and download the library: Download mcbankske/filament-sms-notifier 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/ */

    

mcbankske / filament-sms-notifier example snippets


return [
    'default' => env('SMSNOTIFIER_DRIVER', 'textsms'),
    
    'drivers' => [
        'textsms' => [
            'api_key' => env('SMSNOTIFIER_API_KEY'),
            'partner_id' => env('SMSNOTIFIER_PARTNER_ID'),
            'shortcode' => env('SMSNOTIFIER_SHORTCODE', 'TextSMS'),
        ],
        // Add your custom drivers here
    ],
];

use MCBANKSKE\FilamentSmsNotifier\Facades\SmsNotifier;

// Send an SMS
$response = SmsNotifier::send('254700000000', 'Hello from Filament SMS Notifier!');

if ($response['success']) {
    // SMS sent successfully
} else {
    // Handle error
    logger()->error('Failed to send SMS: ' . $response['message']);
}

// Send an SMS using the helper function
$response = sms('254700000000', 'Hello from the helper function!');

if ($response['success']) {
    // SMS sent successfully
} else {
    // Handle error
    logger()->error('Failed to send SMS: ' . $response['message']);
}

use MCBANKSKE\FilamentSmsNotifier\Services\SmsService;

public function sendWelcomeSms(SmsService $smsService)
{
    $phoneNumber = '254700000000'; // E.164 format
    $message = 'Welcome to our service!';
    
    $response = $smsService->send($phoneNumber, $message);
    
    if ($response['success']) {
        // SMS sent successfully
    } else {
        // Handle error
        logger()->error('Failed to send SMS: ' . $response['message']);
    }
}

use MCBANKSKE\FilamentSmsNotifier\Filament\Widgets\SendTestSmsWidget;

protected function getHeaderWidgets(): array
{
    return [
        SendTestSmsWidget::class,
    ];
}

namespace App\SmsDrivers;

use MCBANKSKE\FilamentSmsNotifier\Contracts\SmsGatewayDriver;

class MyCustomDriver implements SmsGatewayDriver
{
    public function send(string $to, string $message): array
    {
        // Your implementation here
        
        return [
            'success' => true,
            'message' => 'SMS sent successfully',
            'data' => [/* response data */]
        ];
    }
}

'drivers' => [
    'textsms' => [
        // ... existing config
    ],
    'mycustom' => [
        'driver' => 'mycustom',
        // Add any custom configuration
    ],
],

use App\SmsDrivers\MyCustomDriver;
use MCBANKSKE\FilamentSmsNotifier\Services\SmsService;

public function boot()
{
    app()->when(MyCustomDriver::class)
        ->needs('$config')
        ->giveConfig('smsnotifier.drivers.my-custom');
        
    app(SmsService::class)->extend('my-custom', function ($app) {
        return new MyCustomDriver(config('smsnotifier.drivers.my-custom'));
    });
}
bash
php artisan vendor:publish --tag=filament-sms-notifier-config