ayles-software / laravel-sms-messagemedia
ClickSend Notifications channel for Laravel 10
Installs: 1 000
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- illuminate/events: ^10.0||^11.0
- illuminate/http: ^10.0||^11.0
- illuminate/notifications: ^10.0||^11.0
- illuminate/support: ^10.0||^11.0
Requires (Dev)
README
This package makes it easy to send notifications using messagemedia.com with Laravel 10.
Installation
Install the package via composer:
composer require ayles-software/laravel-sms-messagemedia
When generating an API key in Message Media make sure to use the Basic Authentication type. HMAC Auth is not supported
Add your MessageMedia api key, secret and optional default sender sms_from to your config/services.php
:
'message_media' => [ 'key' => env('MESSAGE_MEDIA_KEY'), 'secret' => env('MESSAGE_MEDIA_SECRET'), 'from' => env('MESSAGE_MEDIA_FROM'), ],
Usage
Use MessageMediaChannel in via()
method inside your notification classes. Example:
namespace App\Notifications; use Illuminate\Notifications\Notification; use AylesSoftware\MessageMedia\MessageMediaChannel; use AylesSoftware\MessageMedia\MessageMediaMessage; class SmsTest extends Notification { public function __construct(public string $token) { } public function via($notifiable) { return [MessageMediaChannel::class]; } public function toMessageMedia($notifiable) { return (new MessageMediaMessage) ->message("SMS test to user #{$notifiable->id} with token {$this->token} by MessageMedia") ->from('Dory'); // setting a delay when the sms should be sent return (new MessageMediaMessage) ->message("SMS test to user #{$notifiable->id} with token {$this->token} by MessageMedia") ->from('Dory') ->delay(now()->addHours(6)); } }
In notifiable model (User), include method routeNotificationForMessageMedia()
that returns recipient mobile number:
public function routeNotificationForMessageMedia() { return $this->phone; }
Then send a notification the standard way:
$user = User::find(1); $user->notify(new SmsTest);
Events
Following events are triggered by Notification. By default:
- Illuminate\Notifications\Events\NotificationSending
- Illuminate\Notifications\Events\NotificationSent
NotificationFailed will trigger if something goes wrong
- Illuminate\Notifications\Events\NotificationFailed
Testing
Yes
License
The MIT License (MIT). Please see License File for more information.