bitcodesa / msegat
Notification Channel For Msegate msegat.com
Requires
- php: ^8.2|^8.1
- guzzlehttp/guzzle: ^7.2
- illuminate/contracts: ^11.0|^10.0|^9.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- larastan/larastan: ^2.0.1
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- orchestra/testbench: ^8.8
- pestphp/pest: ^2.20
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
README
Laravel Msegat Notification Channel
This package provides a Laravel notification channel for sending SMS messages using the msegat.com SMS provider.
Installation
- Install the package:
composer require bitcodesa/msegat
- Publish the config file:
php artisan vendor:publish --tag="msegat-config"
- Configure the package:
Edit the published config file (config/msegat.php
) with your Msegat credentials:
return [ "api_url" => env("MSEGAT_API_URL", "https://www.msegat.com/gw/sendsms.php"), "api_key" => env("MSEGAT_API_KEY", ""), "username" => env("MSEGAT_USERNAME", ""), "sender" => env("MSEGAT_SENDER", ""), "unicode" => env("MSEGAT_UNICODE", "UTF8"), ];
- Configure Msegat service:
- Get your credentials:
- Create an account at msegat.com.
- Go to your dashboard.
- Obtain your API Key, Username, and Sender ID.
- Set environment variables:
- Open your
.env
file. - Add the following lines, replacing the placeholder values with your credentials:
- Open your
# Msegat credentials MSEGAT_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxx" MSEGAT_USERNAME="BITCODE" MSEGAT_SENDER="BITCODE"
- Use Messages Log:
if you went to use messages log that create recorde for
Message
model, you have to publish the table:
php artisan vendor:publish --tag="msegat-migrations"
make sure that you allow the creation through:
MSEGAT_MESSAGES_LOG=true
you can use Messageable
trait to get any register that linked to any notifiable model:
class User extends Authenticatable { use \BitcodeSa\Msegat\Messageable; }
then you can get messages through:
$user->messages
Usage
- Add the Msegat channel to your notification class:
<?php namespace App\Notifications\ReservationNotifications; use App\Models\Reservation; use BitcodeSa\Msegat\MsegatMessage; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use BitcodeSa\Msegat\MsegatChannel; class Reservation extends Notification { use Queueable; protected Reservation $reservation; public function __construct(Reservation $reservation) { $this->reservation = $reservation; } public function via(object $notifiable): array { return [ MsegatChannel::class, // Other notification channels ]; } public function toMsegat() { return new MsegatMessage($this->reservation->title); } // Other notification methods }
Available Method for MsegatMessage
object:
timeToExec("YYYY-MM-DD HH:i:SS")
allow you to specify the time that the message should be sent.unicode("UTF8")
specify unicode for the message by default it is "UTF8".type("TYPE_SMS")
specify message type you can choose between SMS or OTP.sender($sender)
specify sender name.lang("ar")
specify OTP language by defualt it is "ar"
- Send the sms notification:
$user = User::find(1); $user->notify(new Reservation($reservation));
- Send otp notification:
NOTE:This feature not working from the source msegat.com
$user = User::find(1); $user->notify(new SendOtp($reservation));
SendOtp
Class:
class SendOtp extends Notification { use Queueable; public function __construct() { // } public function via(object $notifiable): array { return [MsegatChannel::class]; } public function toMsegat() { return (new MsegatMessage()) ->type(MsegatMessage::TYPE_OTP) ->lang("en"); } }
NOTE:This feature not working from the source msegat.com
Validate OTP:
$user = \App\Models\User::first(); $otp = new \BitcodeSa\Msegat\MsegatVerifyOtp(); $otp->validate($user, $code);
NOTE:This feature not working from the source msegat.com
Notifiable Identifier
By default, the Msegat notification channel uses the phone
property on the notifiable model to identify the recipient.
If your model uses a different attribute for phone numbers, you can override the default behavior by implementing
the routeNotificationForMsegat()
method on your notifiable model:
class User extends Authenticatable { use Notifiable; public function routeNotificationForMsegat() { return $this->mobile; } }
This instructs the package to use the mobile
attribute instead of phone
to find the recipient's phone number.
Additional Notes
- The package supports unicode messages.
- The package allows you to customize the sender name displayed on the recipient's phone.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.