ringlesoft/jasmin-client

A laravel package for interacting with Jasmin SMS Gateway

1.0.0-beta.3 2024-09-30 14:35 UTC

This package is auto-updated.

Last update: 2024-10-30 14:52:13 UTC


README

Latest Version on Packagist Total Downloads PHP Version Require Dependents

A Laravel package for seamless integration with Jasmin SMS Gateway, supporting HTTP, REST API, and SMPP connections.

Features

  • Easy-to-use interface for sending and receiving SMS
  • Support for HTTP and REST API jasmin options
  • SMPP support is coming soon
  • Delivery report handling

Installation

You can install the package via composer:

composer require ringlesoft/jasmin-client

Configuration

Publish the configuration file:

php artisan vendor:publish --provider="RingleSoft\JasminClient\JasminClientServiceProvider"

Then, edit the config/jasmin_client.php file with your Jasmin SMS Gateway credentials and preferred settings.

Available configurations

The following are available configurations. Most of these are just defaults and can be overridden in your code

  • url : The base url of the jasmin server (include the port if different from 80 or 443/446)
  • username : The username for your jasmin account
  • password : The password for your jasmin account
  • dlr_callback_url : The default sms delivery callback url
  • batch_callback_url : the default batch callback url
  • batch_errback_url : the default batch errback url
  • default_dlr_method : the default dlr method (GET/POST)
  • default_dlr_level : The default DLR level (1, 2, or 3)
  • batch_chunk_size : The default Chunk size for batches

Usage

Sending an SMS

Sending a single message (Http & Rest)

$sms = JasminClient::message()
    ->content('Hello there! Have a nice day')
    ->to("255711000000")
    ->from('INFO')
    ->via('rest') // 'rest' or 'http'
    ->send();
  • Returns RingleSoft\JasminClient\Models\Jasmin\SentMessage

Sending multiple messages as a batch (Rest only)

    $message = JasminClient::message(to: "255711000000", content: "Hello There. Have a nice day");
    $message2 = JasminClient::message(to: "255711000002", content: "Hello There. Have a nice day");
    $batch = JasminClient::batch()
    ->addMessage($message)
    ->addMessage($message2)
    ->from("INFO")
    ->send();
  • Returns RingleSoft\JasminClient\Models\Jasmin\SentBatch

Handling Delivery Statuses

This package provides a streamlined way to handle delivery statuses.

Class DlrController extends Controller
{
    public function handleDlr(Request $request)
    {
        return JasminClient::receiveDlrCallback($request, function(DeliveryCallback $dlr) {
            // do something with the dlr and return true for success or false for failure
            // For example, you can dispatch a job to process the Delivery Report
            return true;
        });
    }
}

Handling Batch Callback Requests

When messages are sent in a batch, Jasmin responds with the ID of the batch created (batchId) and enqueue the messages. When each message is sent to SMC, jasmin fires a callback (batch callback) with messageId of each message within the batch.

To handle batch callbacks, you can use the receiveBatchCallback method.

Class DlrController extends Controller
{
    public function handleDlr(Request $request)
    {
        return JasminClient::receiveDlrCallback($request, function(DeliveryCallback $dlr) {
            // do something with the dlr and return true for success or false for failure
            // For example, you can dispatch a job to process Batch Callback
            return true;
        });
    }
}

Checking rates (Http & Rest)

    $route = JasminClient::rest()->checkRoute("255711000000");

Checking account balance (Http & Rest)

    $balance = JasminClient::rest()->checkBalance();

Monitoring Metrics (Http)

    $metrics = JasminClient::http()->getMetrics();

Contributing

I'll soon let you know when you can contribute to this project.

License

This package is open-sourced software licensed under the MIT license.

Support

Contacts

Follow me on X: @ringunger
Email me: ringunger@gmail.com
Website: https://ringlesoft.com

Note: This package is still under development. Please report any issues you encounter.