Download the PHP package aghfatehi/laravel-msegat without Composer
On this page you can find all versions of the php package aghfatehi/laravel-msegat. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aghfatehi/laravel-msegat
More information about aghfatehi/laravel-msegat
Files in aghfatehi/laravel-msegat
Package laravel-msegat
Short Description A professional Laravel package for integrating with Msegat SMS, OTP, and WhatsApp APIs. Production-ready for SaaS, enterprise, and open-source projects.
License MIT
Informations about the package laravel-msegat
Laravel Msegat
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
Installation
Laravel auto-discovery registers the service provider and facade automatically.
Publish Configuration
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:
| Table | Purpose |
|---|---|
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:
Option B — Publish then migrate (if you need to modify the migrations):
Configuration
Add to your .env (required variables marked with REQUIRED):
Config Options
| Variable | Default | Required | Description |
|---|---|---|---|
MSEGAT_USERNAME |
— | Yes | Msegat account username |
MSEGAT_API_KEY |
— | Yes | Msegat API key |
MSEGAT_SENDER |
'' |
No | Default sender name |
MSEGAT_BASE_URL |
https://www.msegat.com/gw/ |
No | API base URL |
MSEGAT_TIMEOUT |
30 |
No | HTTP request timeout (seconds) |
MSEGAT_RETRIES |
3 |
No | Max retry attempts on failure |
MSEGAT_VERIFY_SSL |
true |
No | Verify SSL certificate |
MSEGAT_QUEUE_ENABLED |
false |
No | Enable async webhook processing |
MSEGAT_LOGGING_ENABLED |
true |
No | Enable request/response logging |
MSEGAT_WEBHOOK_SECRET |
'' |
No | Secret for webhook signature verification |
MSEGAT_WHATSAPP_EMAIL |
— | No | T2 Communicate WhatsApp login email |
MSEGAT_WHATSAPP_PASSWORD |
— | No | T2 Communicate WhatsApp login password |
MSEGAT_WHATSAPP_BASE_URL |
https://communicateapi.t2.sa/api |
No | T2 WhatsApp API base URL |
MSEGAT_WHATSAPP_TOKEN_CACHE_TTL |
3300 |
No | JWT token cache TTL (seconds) |
Usage
SMS
Personalized Messages
OTP
WhatsApp (T2 Communicate API)
WhatsApp messages are sent via the T2 Communicate WhatsApp Business API — a separate gateway from Msegat SMS. Requires its own credentials.
Text Message
Template Message
Response Object
| Field | Type | Description |
|---|---|---|
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 |
string|null |
Contact display name |
Balance
Message Cost Calculation
Sender Management
Retrieve Messages
Test Message
Queue Support
The SendSmsJob retries up to 3 times with a 5-second backoff.
Events
| Event | Payload | Description |
|---|---|---|
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 received |
Example listener registration in EventServiceProvider:
Webhooks
The package registers four webhook routes under the /webhook/msegat/ prefix:
| Route | Purpose |
|---|---|
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
Set MSEGAT_WEBHOOK_SECRET in .env and each webhook request must include:
X-Msegat-Signature: HMAC-SHA256 oftimestamp.payloadX-Msegat-Timestamp: Unix timestamp
Requests outside a 5-minute tolerance window are rejected.
Notification Channel
Add routeNotificationForMsegat() to your notifiable model:
Artisan Commands
Testing
With 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)
Database Migrations
| Table | Purpose |
|---|---|
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
Success
| Code | Message |
|---|---|
M0000 |
Success |
Errors
| Code | Message |
|---|---|
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
See CHANGELOG for recent changes.
Security
If you discover any security-related issues, please email instead of using the issue tracker.
Contributing
Contributions are welcome! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature/new-feature). - Commit your changes (
git commit -am 'Add new feature'). - Push to the branch (
git push origin feature/new-feature). - Create a new Pull Request.
Support
If you have any questions or issues, feel free to open an issue on the GitHub repository or contact the author AL-AGHBARI Fatehi.
License
The MIT License (MIT). See LICENSE for details.
All versions of laravel-msegat with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.0
illuminate/notifications Version ^10.0|^11.0|^12.0
illuminate/queue Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/events Version ^10.0|^11.0|^12.0
ext-json Version *
ext-mbstring Version *