PHPackages                             aghfatehi/laravel-msegat - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. aghfatehi/laravel-msegat

ActiveLibrary[Queues &amp; Workers](/categories/queues)

aghfatehi/laravel-msegat
========================

A professional Laravel package for integrating with Msegat SMS, OTP, and WhatsApp APIs. Production-ready for SaaS, enterprise, and open-source projects.

v1.1.0(1mo ago)01MITPHPPHP ^8.2CI passing

Since Jun 5Pushed 1mo agoCompare

[ Source](https://github.com/aghfatehi/laravel-msegat)[ Packagist](https://packagist.org/packages/aghfatehi/laravel-msegat)[ RSS](/packages/aghfatehi-laravel-msegat/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (27)Versions (3)Used By (0)

 [![PHP Version](https://camo.githubusercontent.com/0cc753e54c9971bf2a317ce2a0d4e9cbe7564268478c95d8c84fca6eecae95a2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e327c382e337c382e342d3838393242462e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d706870)](https://www.php.net/) [![Laravel Version](https://camo.githubusercontent.com/758511b03ab64563b74aac3fdfbf0df190d6a289ec1be6953a178b6f5e60f93f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31307c31317c31322d4646324432302e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c)](https://laravel.com) [![Msegat](https://camo.githubusercontent.com/1f6fdedc4a65b72b91241b8c16d754f126d8501ec65dcb8f3733150dd8a692a4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d73656761742d534d535f4f54505f57686174734170702d3030413835392e7376673f7374796c653d666f722d7468652d6261646765)](https://msegat.com) [![License](https://camo.githubusercontent.com/31e62e0eff03ce9ddfdf69d8476340d4f541990bfb152cb02a0f342965252997/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/aghfatehi/laravel-msegat/blob/main/LICENSE) [![CI](https://camo.githubusercontent.com/346da6d86a908c39c8be7150b20fd4c563729242002a55ee1788abdbc5893255/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6167686661746568692f6c61726176656c2d6d73656761742f63692e796d6c3f7374796c653d666f722d7468652d6261646765266c6162656c3d4349266c6f676f3d676974687562)](https://github.com/aghfatehi/laravel-msegat/actions/workflows/ci.yml) [![Packagist](https://camo.githubusercontent.com/1d68175ed740afea43936053e3bfd246cb1a4d7cb5ed686dc66db9197e005ca4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6167686661746568692f6c61726176656c2d6d73656761742e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d7061636b6167697374)](https://packagist.org/packages/aghfatehi/laravel-msegat) [![Downloads](https://camo.githubusercontent.com/781d7d0fd047a2aadc321cba94970c4625acd32a344b9650bc6cb994a695e024/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6167686661746568692f6c61726176656c2d6d73656761742e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/aghfatehi/laravel-msegat)

Laravel Msegat
==============

[](#laravel-msegat)

### SMS, OTP, and WhatsApp integration for the Msegat gateway

[](#sms-otp-and-whatsapp-integration-for-the-msegat-gateway)

 **Production-ready for SaaS, enterprise, and open-source projects. Supports Laravel 10, 11, and 12 with PHP 8.2+.**
 Created by [AL-AGHBARI Fatehi](https://github.com/aghfatehi)

---

Installation
------------

[](#installation)

```
composer require aghfatehi/laravel-msegat
```

Laravel auto-discovery registers the service provider and facade automatically.

### Publish Configuration

[](#publish-configuration)

```
php artisan vendor:publish --provider="Aghfatehi\Msegat\MsegatServiceProvider" --tag=msegat-config
```

### Publish Migrations (Optional)

[](#publish-migrations-optional)

Track sent messages, OTP requests, delivery reports, and webhooks in your database. If you publish and run the migrations, five tables will be created:

TablePurpose`msegat_sms_logs`History of all sent SMS messages`msegat_otp_requests`OTP request tracking`msegat_delivery_reports`Delivery report storage from Msegat`msegat_webhook_logs`Webhook event log`msegat_failed_requests`Failed request records> This step is **optional**. The package works fully without migrations — skip this section if you don't need database logging.

**Option A — Run migrations directly from the package (recommended):**

Runs only the package's migrations without publishing:

```
php artisan migrate --path=/vendor/aghfatehi/laravel-msegat/database/migrations
```

**Option B — Publish then migrate (if you need to modify the migrations):**

```
php artisan vendor:publish --provider="Aghfatehi\Msegat\MsegatServiceProvider" --tag=msegat-migrations
php artisan migrate
```

Configuration
-------------

[](#configuration)

Add to your `.env` (required variables marked with **REQUIRED**):

```
# ─── REQUIRED ───────────────────────────────────────
MSEGAT_USERNAME=your_username
MSEGAT_API_KEY=your_api_key

# ─── OPTIONAL ───────────────────────────────────────
MSEGAT_SENDER=YourSender
MSEGAT_BASE_URL=https://www.msegat.com/gw/
MSEGAT_TIMEOUT=30
MSEGAT_RETRIES=3
MSEGAT_VERIFY_SSL=true
MSEGAT_QUEUE_ENABLED=false
MSEGAT_LOGGING_ENABLED=true
MSEGAT_WEBHOOK_SECRET=your_webhook_secret
MSEGAT_WHATSAPP_EMAIL=your_t2_email
MSEGAT_WHATSAPP_PASSWORD=your_t2_password
```

### Config Options

[](#config-options)

VariableDefaultRequiredDescription`MSEGAT_USERNAME`—**Yes**Msegat account username`MSEGAT_API_KEY`—**Yes**Msegat API key`MSEGAT_SENDER``''`NoDefault sender name`MSEGAT_BASE_URL``https://www.msegat.com/gw/`NoAPI base URL`MSEGAT_TIMEOUT``30`NoHTTP request timeout (seconds)`MSEGAT_RETRIES``3`NoMax retry attempts on failure`MSEGAT_VERIFY_SSL``true`NoVerify SSL certificate`MSEGAT_QUEUE_ENABLED``false`NoEnable async webhook processing`MSEGAT_LOGGING_ENABLED``true`NoEnable request/response logging`MSEGAT_WEBHOOK_SECRET``''`NoSecret for webhook signature verification`MSEGAT_WHATSAPP_EMAIL`—NoT2 Communicate WhatsApp login email`MSEGAT_WHATSAPP_PASSWORD`—NoT2 Communicate WhatsApp login password`MSEGAT_WHATSAPP_BASE_URL``https://communicateapi.t2.sa/api`NoT2 WhatsApp API base URL`MSEGAT_WHATSAPP_TOKEN_CACHE_TTL``3300`NoJWT token cache TTL (seconds)---

Usage
-----

[](#usage)

### SMS

[](#sms)

```
use Aghfatehi\Msegat\Facades\Msegat;

// Single recipient
$response = Msegat::sms()
    ->to('966512345678')
    ->message('Hello World')
    ->send();

// Multiple recipients
$response = Msegat::sms()
    ->to(['966512345678', '966598765432'])
    ->message('Bulk message')
    ->send();

// Custom sender
$response = Msegat::sms()
    ->sender('CustomAD')
    ->to('966512345678')
    ->message('Custom sender test')
    ->send();

// Scheduled message
$response = Msegat::sms()
    ->to('966512345678')
    ->message('Scheduled message')
    ->at('2026-12-01 10:00:00')
    ->send();

// Get bulk ID
$response = Msegat::sms()
    ->to(['966512345678', '966598765432'])
    ->message('Get bulk ID')
    ->options(['reqBulkId' => true])
    ->send();

$bulkId = $response->bulkId;
```

### Personalized Messages

[](#personalized-messages)

```
$response = Msegat::sms()
    ->to(['966512345678', '966598765432'])
    ->message('Hello {name}, your order {order} is ready')
    ->sendPersonalized([
        ['name' => 'Ahmed', 'order' => '1001'],
        ['name' => 'Mohammed', 'order' => '1002'],
    ]);
```

### OTP

[](#otp)

```
// Send OTP
$otpResponse = Msegat::otp()
    ->to('966512345678')
    ->sendOtp();

$otpId = $otpResponse->otpId;

// Verify OTP
$verification = Msegat::otp()
    ->to('966512345678')
    ->verifyOtp('123456');

if ($verification->successful) {
    // OTP verified
}
```

### WhatsApp (T2 Communicate API)

[](#whatsapp-t2-communicate-api)

WhatsApp messages are sent via the [T2 Communicate](https://t2.sa) WhatsApp Business API — a separate gateway from Msegat SMS. Requires its own credentials.

#### Text Message

[](#text-message)

```
$response = Msegat::whatsapp()
    ->to('966512345678')
    ->message('Hello from WhatsApp!')
    ->send();

$messageId = $response->messageId;
```

#### Template Message

[](#template-message)

```
$response = Msegat::whatsapp()
    ->to('966512345678')
    ->template('welcome')
    ->variables(['John', 'Support'])
    ->send();

if ($response->successful) {
    echo "Sent: {$response->messageId}";
}
```

#### Response Object

[](#response-object)

FieldTypeDescription`successful``bool`Whether the API accepted the message`messageId``string`Unique message ID for tracking`conversationId``string`WhatsApp conversation ID`contactNumber``string`Recipient phone number`status``string``Sent`, `Delivered`, `Read`, `Failed`, etc.`contactName``stringnull`### Balance

[](#balance)

```
$balance = Msegat::getBalance();
$credits = $balance->balance; // float
```

### Message Cost Calculation

[](#message-cost-calculation)

```
$cost = Msegat::sms()
    ->to(['966512345678', '966598765432'])
    ->message('Test message')
    ->calculateCost();
// Returns float
```

### Sender Management

[](#sender-management)

```
// List senders
$senders = Msegat::getSenders();

// Add sender
// (available via direct API call - endpoint: addSender.php)
```

### Retrieve Messages

[](#retrieve-messages)

```
$messages = Msegat::forBulkId('BULK123')
    ->getMessages();

$messages = Msegat::forBulkId('BULK123')
    ->page(2)
    ->limit(10)
    ->getMessages();
```

### Test Message

[](#test-message)

```
Msegat::sms()
    ->to('966512345678')
    ->sendTestMessage();
```

---

Queue Support
-------------

[](#queue-support)

```
// Dispatch to default queue
Msegat::sms()
    ->to('966512345678')
    ->message('Queued message')
    ->queue();

// Custom queue connection
Msegat::sms()
    ->to('966512345678')
    ->message('Queued message')
    ->queue('redis', 'high');
```

The `SendSmsJob` retries up to 3 times with a 5-second backoff.

---

Events
------

[](#events)

EventPayloadDescription`MessageSending``$data` (array)Before sending SMS`MessageSent``$response` (SmsResponse)After SMS or WhatsApp sent`OtpGenerated``$number`, `$response` (OtpResponse)After OTP sent`OtpVerified``$number`, `$code`, `$response` (OtpResponse)After OTP verified`WebhookReceived``$type`, `$payload` (array)When webhook is receivedExample listener registration in `EventServiceProvider`:

```
protected $listen = [
    \Aghfatehi\Msegat\Events\MessageSent::class => [
        \App\Listeners\LogMsegatMessage::class,
    ],
];
```

---

Webhooks
--------

[](#webhooks)

The package registers four webhook routes under the `/webhook/msegat/` prefix:

RoutePurpose`POST /webhook/msegat/delivery`Delivery reports`POST /webhook/msegat/status`Message status updates`POST /webhook/msegat/incoming`Incoming messages`POST /webhook/msegat/failed`Failed messages### Signature Verification

[](#signature-verification)

Set `MSEGAT_WEBHOOK_SECRET` in `.env` and each webhook request must include:

- `X-Msegat-Signature`: HMAC-SHA256 of `timestamp.payload`
- `X-Msegat-Timestamp`: Unix timestamp

Requests outside a 5-minute tolerance window are rejected.

---

Notification Channel
--------------------

[](#notification-channel)

```
namespace App\Notifications;

use Illuminate\Notifications\Notification;

class WelcomeSms extends Notification
{
    public function via($notifiable): array
    {
        return ['msegat'];
    }

    public function toMsegat($notifiable): string
    {
        return "Welcome {$notifiable->name} to our platform!";
    }
}
```

Add `routeNotificationForMsegat()` to your notifiable model:

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

---

Artisan Commands
----------------

[](#artisan-commands)

```
# Check account balance
php artisan msegat:balance

# List registered senders
php artisan msegat:senders
```

---

Testing
-------

[](#testing)

```
composer test
```

With coverage:

```
composer test-coverage
```

The test suite includes:

- **Unit Tests**: DTOs, enums, exceptions, phone formatter, WhatsApp response
- **Feature Tests**: SMS sending, OTP, balance, webhooks, config, WhatsApp text/template
- **Integration Tests**: Events, queues

---

Code Quality (For Contributors)
-------------------------------

[](#code-quality-for-contributors)

```
# Laravel Pint (PSR-12)
composer lint

# Auto-fix
composer lint-fix

# PHPStan (level 6)
composer analyse

# Rector
composer rector
```

---

Database Migrations
-------------------

[](#database-migrations)

TablePurpose`msegat_sms_logs`SMS send history`msegat_otp_requests`OTP request tracking`msegat_delivery_reports`Delivery report storage`msegat_webhook_logs`Webhook event log`msegat_failed_requests`Failed request records---

Status Codes and Messages
-------------------------

[](#status-codes-and-messages)

### Success

[](#success)

CodeMessage`M0000`Success### Errors

[](#errors)

CodeMessage`M0001`Variables missing`M0002`Invalid login info`M0022`Exceed number of senders allowed`M0023`Sender Name is active or under activation or refused`M0024`Sender Name should be in English or number`M0025`Invalid Sender Name Length`M0026`Sender Name is already activated or not found`M0027`Activation Code is not Correct`1010`Variables missing`1020`Invalid login info`1050`MSG body is empty`1060`Balance is not enough`1061`MSG duplicated`1064`Free OTP, Invalid MSG content you should use "Pin Code is: xxxx", "Verification Code: xxxx" or upgrade your account and activate your sender to send any content`1110`Sender name is missing or incorrect`1120`Mobile numbers is not correct`1140`MSG length is too long`M0029`Invalid Sender Name - Sender Name should contain only letters, numbers and the maximum length should be 11 characters`M0030`Sender Name should ended with AD`M0031`Maximum allowed size of uploaded file is 5 MB`M0032`Only pdf, png, jpg and jpeg files are allowed!`M0033`Sender Type should be normal or whitelist only`M0034`Please Use POST Method`M0036`There is no any sender---

Changelog
---------

[](#changelog)

See [CHANGELOG](CHANGELOG.md) for recent changes.

---

Security
--------

[](#security)

If you discover any security-related issues, please email instead of using the issue tracker.

---

Contributing
------------

[](#contributing)

Contributions are welcome! Please follow these steps to contribute:

1. Fork the repository.
2. Create a new branch (`git checkout -b feature/new-feature`).
3. Commit your changes (`git commit -am 'Add new feature'`).
4. Push to the branch (`git push origin feature/new-feature`).
5. Create a new Pull Request.

---

Support
-------

[](#support)

If you have any questions or issues, feel free to open an issue on the [GitHub repository](https://github.com/aghfatehi/laravel-msegat/issues) or contact the author [AL-AGHBARI Fatehi](mailto:fathi.a.n2002@gmail.com).

---

License
-------

[](#license)

The MIT License (MIT). See [LICENSE](LICENSE) for details.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance90

Actively maintained with recent releases

Popularity1

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

2

Last Release

46d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c0d20683d29aa61fca6b1f9a47a754b2d3e177750f1e8d66975979f2ae8813f?d=identicon)[aghfatehi](/maintainers/aghfatehi)

---

Tags

bulk-smslaravellaravel-packagemsegatnotification-channelotpphpsaudi-arabiasmssms-gatewaywhatsappmessagelaravelotpsmswhatsappbulk-smssms-gatewaynotification-channelsaudi-arabiamsegat

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/aghfatehi-laravel-msegat/health.svg)

```
[![Health](https://phpackages.com/badges/aghfatehi-laravel-msegat/health.svg)](https://phpackages.com/packages/aghfatehi-laravel-msegat)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M136](/packages/laravel-pulse)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M133](/packages/roots-acorn)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45444.2k1](/packages/pressbooks-pressbooks)[api-platform/laravel

API Platform support for Laravel

58174.6k17](/packages/api-platform-laravel)[flat3/lodata

OData v4.01 Producer for Laravel

99351.7k](/packages/flat3-lodata)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
