PHPackages                             andrejro2/yeastar-gsm-laravel - 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. [API Development](/categories/api)
4. /
5. andrejro2/yeastar-gsm-laravel

ActiveLibrary[API Development](/categories/api)

andrejro2/yeastar-gsm-laravel
=============================

Laravel package for sending SMS via Yeastar Gateway using API

1.0.1(10mo ago)03MITPHPPHP ^8.1|^8.2|^8.3

Since Sep 1Pushed 10mo agoCompare

[ Source](https://github.com/andrejro2/yeastar-gsm-laravel)[ Packagist](https://packagist.org/packages/andrejro2/yeastar-gsm-laravel)[ RSS](/packages/andrejro2-yeastar-gsm-laravel/feed)WikiDiscussions main Synced today

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

Laravel Yeastar SMS
===================

[](#laravel-yeastar-sms)

A Laravel package for sending SMS messages via Yeastar Gateway using the Asterisk Manager Interface (AMI) protocol. This package provides a clean, Laravel-friendly interface to interact with Yeastar GSM gateways.

Features
--------

[](#features)

- 🚀 **Simple Integration** - Easy-to-use Laravel facade and service container integration
- 🔒 **Secure Connection** - Uses AMI protocol for secure communication with Yeastar gateways
- ⚙️ **Configurable** - Multiple gateway support with environment-based configuration
- 🧪 **Well Tested** - Comprehensive test suite included
- 📝 **Detailed Logging** - Built-in logging support for debugging and monitoring
- 🎯 **Type Safe** - Full PHP 8.1+ type declarations and PHPDoc annotations
- 🔄 **Multiple Gateways** - Support for multiple gateway configurations
- ⏱️ **Timeout Control** - Configurable connection and read timeouts

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Laravel 9.0, 10.0, or 11.0
- Yeastar Gateway with AMI enabled
- Network connectivity to the Yeastar gateway

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

[](#installation)

You can install the package via Composer:

```
composer require andrejro2/yeastar-gsm-laravel
```

The package will automatically register its service provider and facade.

### Publishing Configuration

[](#publishing-configuration)

Publish the configuration file to customize the package settings:

```
php artisan vendor:publish --tag="yeastar-sms-config"
```

This will create a `config/yeastar-sms.php` file where you can configure your gateway settings.

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

[](#configuration)

### Environment Variables

[](#environment-variables)

Add the following environment variables to your `.env` file:

```
# Default Yeastar Gateway Configuration
YEASTAR_HOST=192.168.1.1:5038
YEASTAR_USERNAME=admin
YEASTAR_SECRET=your_ami_secret

# Connection Timeouts (optional)
YEASTAR_CONNECTION_TIMEOUT=30
YEASTAR_READ_TIMEOUT=5

# Logging (optional)
YEASTAR_LOGGING_ENABLED=true
YEASTAR_LOG_CHANNEL=default
```

### Multiple Gateway Support

[](#multiple-gateway-support)

You can configure multiple gateways for different environments:

```
# Production Gateway
YEASTAR_PROD_HOST=192.168.1.100:5038
YEASTAR_PROD_USERNAME=prod_user
YEASTAR_PROD_SECRET=prod_secret

# Staging Gateway
YEASTAR_STAGING_HOST=192.168.1.200:5038
YEASTAR_STAGING_USERNAME=staging_user
YEASTAR_STAGING_SECRET=staging_secret
```

### AMI Configuration on Yeastar

[](#ami-configuration-on-yeastar)

Ensure that AMI is enabled on your Yeastar gateway:

1. Log into your Yeastar web interface
2. Go to **Settings** → **System** → **AMI**
3. Enable AMI and configure a user with SMS sending permissions
4. Note the port number (default is 5038)

Usage
-----

[](#usage)

### Basic Usage with Facade

[](#basic-usage-with-facade)

```
use AndrejRo2\LaravelYeastarSms\Facades\YeastarSms;
use AndrejRo2\LaravelYeastarSms\Exceptions\YeastarSmsException;

try {
    // Send SMS (connection configured via config/env)
    $success = YeastarSms::sendSms(
        port: 0,                        // GSM port (0-based)
        destination: '+1234567890',     // Phone number with country code
        message: 'Hello from Laravel!', // Message content
        id: 'SMS001'                   // Optional SMS ID for tracking
    );

    if ($success) {
        echo 'SMS sent successfully!';
    }
} catch (YeastarSmsException $e) {
    echo 'Error: ' . $e->getMessage();
}
```

### Manual Connection Configuration

[](#manual-connection-configuration)

```
use AndrejRo2\LaravelYeastarSms\Facades\YeastarSms;

// Configure connection manually
YeastarSms::setConnection('192.168.1.1:5038', 'admin', 'secret');

// Send SMS
$success = YeastarSms::sendSms(0, '+1234567890', 'Hello World!');
```

### Dependency Injection

[](#dependency-injection)

```
use AndrejRo2\LaravelYeastarSms\Contracts\YeastarSmsInterface;

class SmsController extends Controller
{
    public function sendSms(YeastarSmsInterface $yeastarSms)
    {
        try {
            $success = $yeastarSms->sendSms(0, '+1234567890', 'Hello via DI!');

            return response()->json(['success' => $success]);
        } catch (YeastarSmsException $e) {
            return response()->json(['error' => $e->getMessage()], 500);
        }
    }
}
```

### Using Different Gateway Configurations

[](#using-different-gateway-configurations)

```
// Use a specific gateway configuration
$gatewayConfig = config('yeastar-sms.gateways.production');

YeastarSms::setConnection(
    $gatewayConfig['host'],
    $gatewayConfig['username'],
    $gatewayConfig['secret']
);

$success = YeastarSms::sendSms(0, '+1234567890', 'Production SMS');
```

### Bulk SMS Sending

[](#bulk-sms-sending)

```
$phones = ['+1234567890', '+0987654321', '+1122334455'];
$message = 'Bulk SMS message';

foreach ($phones as $index => $phone) {
    try {
        $smsId = 'BULK_' . time() . '_' . $index;
        $success = YeastarSms::sendSms(0, $phone, $message, $smsId);

        if ($success) {
            echo "SMS sent to {$phone}\n";
        }

        // Add delay to prevent overwhelming the gateway
        usleep(500000); // 0.5 second delay

    } catch (YeastarSmsException $e) {
        echo "Failed to send SMS to {$phone}: " . $e->getMessage() . "\n";
    }
}
```

Artisan Command
---------------

[](#artisan-command)

The package includes an example Artisan command for sending SMS from the command line:

```
# Basic usage
php artisan sms:send "+1234567890" "Hello from command line!"

# With options
php artisan sms:send "+1234567890" "Hello!" --port=0 --gateway=production --id=CMD001
```

To use this command, copy the example from `examples/ArtisanCommand.php` to your `app/Console/Commands/` directory.

API Reference
-------------

[](#api-reference)

### YeastarSms Methods

[](#yeastarsms-methods)

#### `setConnection(string $host, string $username, string $secret): void`

[](#setconnectionstring-host-string-username-string-secret-void)

Configure the gateway connection parameters.

- `$host` - Gateway hostname and port (e.g., "192.168.1.1:5038")
- `$username` - AMI username
- `$secret` - AMI secret/password

#### `sendSms(int $port, string $destination, string $message, ?string $id = null): bool`

[](#sendsmsint-port-string-destination-string-message-string-id--null-bool)

Send an SMS message via the gateway.

- `$port` - GSM port number (0-based, will be converted to 1-based for gateway)
- `$destination` - Phone number in E.164 format (e.g., "+1234567890")
- `$message` - SMS message content (max 160 characters recommended)
- `$id` - Optional SMS ID for tracking (auto-generated if not provided)

Returns `true` on success, throws `YeastarSmsException` on failure.

#### `getConnection(): ?array`

[](#getconnection-array)

Get the current connection configuration (with secret hidden).

#### `setTimeout(int $timeout): self`

[](#settimeoutint-timeout-self)

Set connection timeout in seconds (default: 30).

#### `setReadTimeout(int $readTimeout): self`

[](#setreadtimeoutint-readtimeout-self)

Set read timeout in seconds (default: 5).

Exception Handling
------------------

[](#exception-handling)

The package throws `YeastarSmsException` for various error conditions:

```
try {
    YeastarSms::sendSms(0, '+1234567890', 'Test message');
} catch (YeastarSmsException $e) {
    // Handle specific error types
    $message = $e->getMessage();

    if (str_contains($message, 'connection')) {
        // Connection failed - check network/hostname
    } elseif (str_contains($message, 'authentication')) {
        // Authentication failed - check credentials
    } elseif (str_contains($message, 'SMS command failed')) {
        // SMS sending failed - check gateway/SIM status
    }
}
```

Configuration Reference
-----------------------

[](#configuration-reference)

The package configuration file (`config/yeastar-sms.php`) includes:

```
return [
    // Default gateway configuration
    'default' => [
        'host' => env('YEASTAR_HOST', '192.168.1.1:5038'),
        'username' => env('YEASTAR_USERNAME', 'admin'),
        'secret' => env('YEASTAR_SECRET', 'admin'),
    ],

    // Connection timeouts
    'timeouts' => [
        'connection' => env('YEASTAR_CONNECTION_TIMEOUT', 30),
        'read' => env('YEASTAR_READ_TIMEOUT', 5),
    ],

    // Logging configuration
    'logging' => [
        'enabled' => env('YEASTAR_LOGGING_ENABLED', true),
        'channel' => env('YEASTAR_LOG_CHANNEL', 'default'),
    ],

    // Multiple gateway configurations
    'gateways' => [
        'production' => [...],
        'staging' => [...],
        'development' => [...],
    ],
];
```

Testing
-------

[](#testing)

Run the package tests:

```
composer test
```

Run tests with coverage:

```
composer test-coverage
```

Troubleshooting
---------------

[](#troubleshooting)

### Common Issues

[](#common-issues)

1. **Connection Failed**

    - Verify gateway hostname and port
    - Check network connectivity
    - Ensure firewall allows connection to AMI port (default 5038)
2. **Authentication Failed**

    - Verify username and secret
    - Check if AMI is enabled on the gateway
    - Ensure user has proper permissions
3. **SMS Command Failed**

    - Check if GSM module is properly configured
    - Verify SIM card balance and network registration
    - Ensure correct port number
4. **Timeout Errors**

    - Increase timeout values in configuration
    - Check network latency
    - Verify gateway is responsive

### Debugging

[](#debugging)

Enable logging to see detailed information about SMS sending:

```
YEASTAR_LOGGING_ENABLED=true
LOG_LEVEL=debug
```

This will log connection attempts, authentication, and SMS sending details.

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

[](#contributing)

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

### Security Vulnerabilities

[](#security-vulnerabilities)

If you discover a security vulnerability, please send an e-mail to the package maintainer. All security vulnerabilities will be promptly addressed.

Credits
-------

[](#credits)

- [Andrej Ro](https://github.com/andrejro2)
- [All Contributors](../../contributors)

This package is based on the Go implementation at [yeastartgsms](https://github.com/andrejro2/yeastartgsms).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Changelog
---------

[](#changelog)

Please see [CHANGELOG.md](CHANGELOG.md) for more information on what has changed recently.

---

Related Projects
----------------

[](#related-projects)

- [yeastartgsms](https://github.com/andrejro2/yeastartgsms) - Original Go implementation
- [Laravel SMS](https://github.com/simplesoftwareio/simple-sms) - Multi-provider SMS package for Laravel

Support
-------

[](#support)

- 📖 [Documentation](README.md)
- 🐛 [Issue Tracker](../../issues)
- 💬 [Discussions](../../discussions)

---

**Made with ❤️ for the Laravel community**

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance54

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~0 days

Total

2

Last Release

307d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15248232?v=4)[Andrew Kozoriz](/maintainers/andrejro2)[@andrejro2](https://github.com/andrejro2)

---

Top Contributors

[![AndrewMeant4](https://avatars.githubusercontent.com/u/254471170?v=4)](https://github.com/AndrewMeant4 "AndrewMeant4 (3 commits)")

---

Tags

laravelsmsgsmasteriskamiyeastar

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/andrejro2-yeastar-gsm-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/andrejro2-yeastar-gsm-laravel/health.svg)](https://phpackages.com/packages/andrejro2-yeastar-gsm-laravel)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k95.4M307](/packages/laravel-horizon)[illuminate/database

The Illuminate Database package.

2.8k54.9M11.7k](/packages/illuminate-database)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M203](/packages/laravel-ai)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816334.1k3](/packages/defstudio-telegraph)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)

PHPackages © 2026

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