/Msegat

Notification Channel For Msegate msegat.com

Primary LanguagePHPMIT LicenseMIT

Notification Channel For Msegate msegat.com

Latest Version on Packagist GitHub Code Style Action Status Total Downloads

Laravel Msegat Notification Channel

This package provides a Laravel notification channel for sending SMS messages using the msegat.com SMS provider.

Installation

  1. Install the package:
composer require bitcodesa/msegat
  1. Publish the config file:
php artisan vendor:publish --tag="msegat-config"
  1. 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"),
];
  1. Configure Msegat service:
  • Get your credentials:
    1. Create an account at msegat.com.
    2. Go to your dashboard.
    3. Obtain your API Key, Username, and Sender ID.
  • Set environment variables:
    1. Open your .env file.
    2. Add the following lines, replacing the placeholder values with your credentials:
# Msegat credentials
MSEGAT_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxx"
MSEGAT_USERNAME="BITCODE"
MSEGAT_SENDER="BITCODE"

Usage

  1. 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"
  1. Send the sms notification:
$user = User::find(1);
$user->notify(new Reservation($reservation));
  1. 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.