### Setup Queue Database and Start Worker Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Run these commands to set up the necessary database table for jobs and start the queue worker. ```bash php artisan queue:table php artisan migrate php artisan queue:work ``` -------------------------------- ### File Logging Example Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Example of a log entry when using the file driver, showing timestamp, log level, package name, and log details. ```log [2024-01-15 14:30:45] local.INFO: laravelbdsms { "provider": "Xenon\\LaravelBDSms\\Provider\\Ssl", "request_json": {...}, "response_json": {...} } ``` -------------------------------- ### Install Laravel BDSMS Package Source: https://github.com/arif98741/laravelbdsms/blob/master/readme.md Install the package using Composer. ```bash composer require xenon/laravelbdsms ``` -------------------------------- ### Custom Gateway with GET Request Method Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Utilize the GET method for sending SMS via a custom gateway. This example shows how to configure the URL and parameters for a GET request. ```php $sender->setProvider(CustomGateway::class) ->setUrl('https://api.yoursmsgateway.com/send') ->setMethod('get') // Use GET instead of POST ->setConfig([ 'apikey' => 'your_key', 'number' => '017XXXXXXXXX', 'text' => 'Message via GET', ]); $response = $sender->send(); ``` -------------------------------- ### Install Laravel BDSMS Package Source: https://github.com/arif98741/laravelbdsms/blob/master/readme.md Install the package using Composer. This command fetches and installs the latest version of the Laravel BDSMS package into your project. ```bash composer require "arif98741/laravelbdsms" ``` -------------------------------- ### Complete Custom Provider Example Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md A full implementation of a custom SMS provider, including API endpoint configuration, request building, and response handling. Ensure required configuration keys like 'api_key' and 'sender_id' are provided. ```php senderObject = $sender; } /** * Send the SMS request */ public function sendRequest() { // Get data from Sender $mobile = $this->senderObject->getMobile(); $text = $this->senderObject->getMessage(); $config = $this->senderObject->getConfig(); $queue = $this->senderObject->getQueue(); $queueName = $this->senderObject->getQueueName(); $tries = $this->senderObject->getTries(); $backoff = $this->senderObject->getBackoff(); // Build API query parameters $query = [ 'api_key' => $config['api_key'], 'sender_id' => $config['sender_id'], 'recipient' => $mobile, 'message' => $text, 'type' => $config['type'] ?? 'text', ]; // Create Request object $requestObject = new Request( $this->apiEndpoint, $query, $queue, [], // headers $queueName, $tries, $backoff ); // Set headers if needed $requestObject->setHeaders([ 'Content-Type' => 'application/json', 'Accept' => 'application/json', ])->setContentTypeJson(true); // Execute request $response = $requestObject->post(); // If queued, return immediately if ($queue) { return true; } // Process response $body = $response->getBody(); $smsResult = $body->getContents(); // Generate report $data['number'] = $mobile; $data['message'] = $text; return $this->generateReport($smsResult, $data)->getContent(); } /** * Validate required configuration */ public function errorException() { $config = $this->senderObject->getConfig(); if (!array_key_exists('api_key', $config)) { throw new RenderException('api_key is required for MyNewProvider'); } if (!array_key_exists('sender_id', $config)) { throw new RenderException('sender_id is required for MyNewProvider'); } if (empty($config['api_key'])) { throw new RenderException('api_key cannot be empty'); } } } ``` -------------------------------- ### Helper::ensureNumberStartsWith88 Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Ensures that a given phone number starts with the '88' country code prefix. If the number already has the prefix, it remains unchanged. ```APIDOC ## Helper::ensureNumberStartsWith88 ### Description Ensures that a given phone number starts with the '88' country code prefix. If the number already has the prefix, it remains unchanged. ### Method static public function ensureNumberStartsWith88(string $number) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```php use Xenon\LaravelBDSms\Helper\Helper; // Ensure 88 prefix for international format $formatted = Helper::ensureNumberStartsWith88('017XXXXXXXXX'); // Returns: '88017XXXXXXXXX' $formatted = Helper::ensureNumberStartsWith88('8801XXXXXXXXX'); // Returns: '8801XXXXXXXXX' (unchanged) ``` ### Response #### Success Response - **string**: The formatted phone number with the '88' prefix. #### Response Example ```json { "example": "88017XXXXXXXXX" } ``` ### Error Handling None explicitly documented. ``` -------------------------------- ### Start Queue Worker Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Run the Artisan queue worker to process pending SMS jobs. You can specify the queue to process and configure retry and backoff parameters directly. ```bash # Process default queue php artisan queue:work # Process specific queue php artisan queue:work --queue=sms_queue # With retry settings php artisan queue:work --queue=sms_queue --tries=3 --backoff=60 ``` -------------------------------- ### Publish Package Assets and Migrate Source: https://github.com/arif98741/laravelbdsms/blob/master/readme.md Publish the package's migrations and configuration files, then run database migrations. ```bash php artisan vendor:publish --provider=Xenon\LaravelBDSms\LaravelBDSmsServiceProvider --tag="migrations" php artisan vendor:publish --provider=Xenon\LaravelBDSms\LaravelBDSmsServiceProvider --tag="config" php artisan migrate ``` -------------------------------- ### Using the Logger Facade Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Demonstrates various methods available through the Logger facade for retrieving, filtering, and managing log entries. ```php use Xenon\LaravelBDSms\Facades\Logger; // Get last log entry $lastLog = Logger::viewLastLog(); // Get all logs $allLogs = Logger::viewAllLog(); // Get logs by provider $sslLogs = Logger::logByProvider(Ssl::class); // Get logs for default provider $defaultLogs = Logger::logByDefaultProvider(); // Get total log count $total = Logger::total(); // Clear all logs Logger::clearLog(); // Convert to array $array = Logger::toArray($lastLog); ``` -------------------------------- ### Using the SMS Facade Methods Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Demonstrates various ways to use the SMS facade for sending messages, including direct sending, specifying a provider, and queued sending. ```php use Xenon\LaravelBDSms\Facades\SMS; // Method 1: Direct shoot $response = SMS::shoot('017XXXXXXXXX', 'Your message here'); // Method 2: With provider selection $response = SMS::via(Ssl::class)->shoot('017XXXXXXXXX', 'Message'); // Method 3: Queued sending $response = SMS::shootWithQueue('017XXXXXXXXX', 'Message'); ``` -------------------------------- ### Cache Configuration and Migrate Source: https://github.com/arif98741/laravelbdsms/blob/master/readme.md Cache the application configuration and run migrations again. ```bash php artisan config:cache && php artisan migrate ``` -------------------------------- ### Run Database Migration Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Run the database migration to create the log table if SMS logging is enabled. ```bash php artisan migrate ``` -------------------------------- ### Request Class Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md The Request class is used to make HTTP requests to SMS gateway APIs, supporting GET and POST methods with configurable options. ```APIDOC ## Request Class ### Description Handles making HTTP requests to SMS gateway APIs with various configuration options. ### Methods #### `__construct(string $url, array $query, bool $queue = false, array $headers = [], string $queueName = 'default', int $tries = 3, int $backoff = 60)` - **Description**: Constructor for the Request class. - **Parameters**: - `url` (string): The URL of the SMS gateway. - `query` (array): An associative array of query parameters. - `queue` (bool, optional): Whether to queue the request. Defaults to `false`. - `headers` (array, optional): An associative array of request headers. Defaults to `[]`. - `queueName` (string, optional): The name of the queue if `queue` is `true`. Defaults to 'default'. - `tries` (int, optional): The number of retries for queued requests. Defaults to 3. - `backoff` (int, optional): The delay in seconds between retries for queued requests. Defaults to 60. #### `get(bool $verify = false, float $timeout = 10.0)` - **Description**: Perform an HTTP GET request. - **Parameters**: - `verify` (bool, optional): Whether to verify SSL certificate. Defaults to `false`. - `timeout` (float, optional): The request timeout in seconds. Defaults to 10.0. - **Returns**: `Response|void` #### `post(bool $verify = false, float $timeout = 20.0)` - **Description**: Perform an HTTP POST request. - **Parameters**: - `verify` (bool, optional): Whether to verify SSL certificate. Defaults to `false`. - `timeout` (float, optional): The request timeout in seconds. Defaults to 20.0. - **Returns**: `Response|void` #### `setHeaders(array $headers)` - **Description**: Set custom headers for the request. - **Parameters**: - `headers` (array): An associative array of headers. - **Returns**: `Request` (The Request instance for chaining). #### `setContentTypeJson(bool $json)` - **Description**: Set the Content-Type header to application/json. - **Parameters**: - `json` (bool): `true` to set JSON content type, `false` otherwise. - **Returns**: `Request` (The Request instance for chaining). #### `setFormParams(array $params)` - **Description**: Set form parameters for the request. - **Parameters**: - `params` (array): An associative array of form parameters. - **Returns**: `Request` (The Request instance for chaining). #### `getQueue()` - **Description**: Get the queue status of the request. - **Returns**: `bool` ``` -------------------------------- ### Helper::numberValidation Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Validates Bangladeshi mobile numbers against various formats including 11-digit numbers starting with 01, with or without the country code (880 or +880). ```APIDOC ## Helper::numberValidation ### Description Validates Bangladeshi mobile numbers against various formats including 11-digit numbers starting with 01, with or without the country code (880 or +880). ### Method static public function numberValidation(string $number) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```php use Xenon\LaravelBDSms\Helper\Helper; // Validate Bangladeshi mobile number $isValid = Helper::numberValidation('017XXXXXXXXX'); // Returns: true $isValid = Helper::numberValidation('12345'); // Returns: false ``` ### Response #### Success Response - **bool**: Returns `true` if the number is valid, `false` otherwise. #### Response Example ```json { "example": true } ``` ### Error Handling None explicitly documented. ``` -------------------------------- ### Publish Configuration and Migration Files Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Publish the package's configuration file and log table migration using the Artisan command. ```bash php artisan vendor:publish --provider="Xenon\LaravelBDSms\LaravelBDSmsServiceProvider" ``` -------------------------------- ### Format Number with 88 Prefix Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Ensures a Bangladeshi mobile number starts with the '88' country code prefix for international formatting. If the prefix already exists, the number remains unchanged. ```php // Ensure 88 prefix for international format $formatted = Helper::ensureNumberStartsWith88('017XXXXXXXXX'); // Returns: '88017XXXXXXXXX' $formatted = Helper::ensureNumberStartsWith88('8801XXXXXXXXX'); // Returns: '8801XXXXXXXXX' (unchanged) ``` -------------------------------- ### Throwing RenderException for Configuration Errors Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Demonstrates how to manually throw a RenderException for common provider or configuration issues. Use this when specific configuration keys are missing or a provider is not found. ```php use Xenon\LaravelBDSms\Handler\RenderException; // Missing config file throw new RenderException("missing config/sms.php..."); // Provider not found throw new RenderException("Sms Gateway Provider 'InvalidProvider' not found."); // Missing config key throw new RenderException("api_token key is absent in configuration"); ``` -------------------------------- ### Validate Bangladeshi Mobile Number Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Validates if a given string is a valid Bangladeshi mobile number. Supports various formats including 11 digits starting with 01, 13 digits with country code, and prefixed with '+'. ```php // Validate Bangladeshi mobile number $isValid = Helper::numberValidation('017XXXXXXXXX'); // Returns: true $isValid = Helper::numberValidation('12345'); // Returns: false // Valid patterns: // - 017XXXXXXXXX (11 digits starting with 01) // - 01XXXXXXXXX (11 digits) // - 8801XXXXXXXXX (13 digits with country code) // - +8801XXXXXXXXX (with + prefix) ``` -------------------------------- ### Publish and Clear Configuration Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Use these commands to publish the sms.php configuration file and clear the configuration cache when encountering missing config file errors. ```bash php artisan vendor:publish --provider="Xenon\LaravelBDSms\LaravelBDSmsServiceProvider" php artisan config:clear ``` -------------------------------- ### Import Logger Facade Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Import the Logger facade for managing SMS logs. ```php use Xenon\LaravelBDSms\Facades\Logger; ``` -------------------------------- ### Configure Default SMS Provider and SSL Credentials Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Set the default SMS provider and SSL Wireless credentials in the .env file. ```env SMS_DEFAULT_PROVIDER=Xenon\LaravelBDSms\Provider\Ssl SMS_SSL_API_TOKEN=your_api_token SMS_SSL_SID=your_sender_id SMS_SSL_CSMS_ID=your_csms_id ``` -------------------------------- ### Enable Logging Configuration Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Configure SMS logging by setting 'sms_log' to true and specifying the 'log_driver' in config/sms.php. ```php 'sms_log' => true, 'log_driver' => 'database', // or 'file' ``` -------------------------------- ### Import SMS Facade Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Import the SMS facade to use its methods for sending SMS. ```php use Xenon\LaravelBDSms\Facades\SMS; ``` -------------------------------- ### Queue Driver Configuration Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Ensure your queue driver is set to 'database' in the .env file to enable queue processing. ```env QUEUE_CONNECTION=database ``` -------------------------------- ### Import Helper Class Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Import the Helper class for use in your application. ```php use Xenon\LaravelBDSms\Helper\Helper; ``` -------------------------------- ### Configure Infobip SMS Provider Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Set up environment variables for Infobip, an international SMS provider. Includes base URL, username, password, and sender ID (FROM). ```env SMS_INFOBIP_BASE_URL=https://xxxxx.api.infobip.com SMS_INFOBIP_USER=your_username SMS_INFOBIP_PASSWORD=your_password SMS_INFOBIP_FROM=YourBrand ``` -------------------------------- ### Using the Sender Class Directly Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Instantiate and configure the Sender class directly for more granular control over SMS sending, including setting provider-specific configurations. ```php use Xenon\LaravelBDSms\Sender; use Xenon\LaravelBDSms\Provider\Ssl; $sender = Sender::getInstance(); $sender->setProvider(Ssl::class) ->setConfig([ 'api_token' => 'your_token', 'sid' => 'your_sid', 'csms_id' => 'your_csms_id', ]) ->setMobile('017XXXXXXXXX') ->setMessage('Hello World!'); $response = $sender->send(); ``` -------------------------------- ### Helper::ensurePrefix Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Ensures that a given provider name is returned with its full namespace. If the full namespace is already provided, it is returned unchanged. ```APIDOC ## Helper::ensurePrefix ### Description Ensures that a given provider name is returned with its full namespace. If the full namespace is already provided, it is returned unchanged. ### Method static public function ensurePrefix(string $provider) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```php use Xenon\LaravelBDSms\Helper\Helper; // Ensure full provider namespace $fullClass = Helper::ensurePrefix('Ssl'); // Returns: 'Xenon\LaravelBDSms\Provider\Ssl' $fullClass = Helper::ensurePrefix('Xenon\LaravelBDSms\Provider\Ssl'); // Returns: 'Xenon\LaravelBDSms\Provider\Ssl' (unchanged) ``` ### Response #### Success Response - **string**: The full namespace of the provider. #### Response Example ```json { "example": "Xenon\LaravelBDSms\Provider\Ssl" } ``` ### Error Handling None explicitly documented. ``` -------------------------------- ### Send SMS using Facade Source: https://github.com/arif98741/laravelbdsms/blob/master/readme.md Send a single or multiple SMS messages using the SMS facade. Ensure .env credentials and default provider are set. ```php use Xenon\LaravelBDSms\Facades\SMS; SMS::shoot('017XXYYZZAA', 'helloooooooo boss!'); SMS::shoot(['017XXYYZZAA','018XXYYZZAA'], 'helloooooooo boss!'); ``` -------------------------------- ### Using the Custom Provider Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Send SMS messages using your newly registered provider either directly via the SMS facade or by setting it as the default provider in your .env file. ```php use Xenon\LaravelBDSms\Facades\SMS; use Xenon\LaravelBDSms\Provider\MyNewProvider; // Via facade SMS::via(MyNewProvider::class)->shoot('017XXXXXXXXX', 'Hello!'); // Or set as default in .env SMS_DEFAULT_PROVIDER=Xenon\LaravelBDSms\Provider\MyNewProvider ``` -------------------------------- ### Publish Configuration File Source: https://github.com/arif98741/laravelbdsms/blob/master/readme.md Publish the package's configuration file to your Laravel project's config directory. This allows you to customize gateway settings. ```bash php artisan vendor:publish --provider="Arif98741\LaravelBDSms\LaravelBDSmsServiceProvider" ``` -------------------------------- ### Registering a Custom Provider Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Add your custom provider to the 'providers' array in the `config/sms.php` file, mapping the provider class to its configuration settings. ```php use Xenon\LaravelBDSms\Provider\MyNewProvider; 'providers' => [ // ... existing providers MyNewProvider::class => [ 'api_key' => env('SMS_MYNEW_API_KEY', ''), 'sender_id' => env('SMS_MYNEW_SENDER_ID', ''), 'type' => env('SMS_MYNEW_TYPE', 'text'), ], ] ``` -------------------------------- ### Custom Gateway with Queue Support Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Enable queueing for custom SMS messages to handle them asynchronously. Configure queue name, number of tries, and backoff time for retries. ```php $sender->setProvider(CustomGateway::class) ->setUrl('https://api.yoursmsgateway.com/send') ->setMethod('post') ->setQueue(true) ->setQueueName('custom_sms') ->setTries(5) ->setBackoff(120) ->setConfig([ 'phone' => '017XXXXXXXXX', 'msg' => 'Queued custom message', ]); $response = $sender->send(); ``` -------------------------------- ### View Failed Queue Jobs Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Use this command to inspect failed queue jobs. ```bash php artisan queue:failed ``` -------------------------------- ### Sender Class Singleton Implementation Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md This PHP code demonstrates the Singleton pattern implementation for the Sender class. It ensures only one instance of the Sender class is created throughout the request lifecycle, provided the sms.php configuration file exists. ```php class Sender { private static $instance = null; public static function getInstance(): Sender { if (!File::exists(config_path('sms.php'))) { throw new RenderException("missing config/sms.php..."); } if (!isset(self::$instance)) { self::$instance = new self; } return self::$instance; } } ``` -------------------------------- ### Import Sender Class Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Import the Sender class for managing SMS sending configurations and operations. ```php use Xenon\LaravelBDSms\Sender; ``` -------------------------------- ### Send SMS via Queue (Default) Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Use this to send an SMS message asynchronously using the default queue settings (3 retries, 60-second backoff). Ensure the SMS facade is imported. ```php use Xenon\LaravelBDSms\Facades\SMS; // Default: 3 retries, 60 second backoff SMS::shootWithQueue('017XXXXXXXXX', 'Message'); ``` -------------------------------- ### Send SMS via Queue (Advanced Configuration) Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Configure custom queue names, retry attempts, and backoff times for asynchronous SMS sending. This allows for fine-grained control over message delivery. ```php SMS::shootWithQueue( '017XXXXXXXXX', // Mobile number 'Message text', // Message 'high_priority', // Queue name (default: 'default') 10, // Max retry attempts (default: 3) 300 // Backoff in seconds (default: 60) ); ``` -------------------------------- ### Laravel BDSMS Package Structure Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Illustrates the directory layout and file organization for the Laravel BDSMS package, including configuration, database, facades, handlers, logging, models, and providers. ```tree packages/laravelbdsms/ ├── src/ │ ├── Config/ │ │ └── sms.php # Configuration file │ ├── Database/ │ │ └── migrations/ │ │ └── create_laravelbd_sms_table.php.stub │ ├── Facades/ │ │ ├── SMS.php # Main SMS facade │ │ ├── Logger.php # Logging facade │ │ └── Request.php # Request facade │ ├── Handler/ │ │ ├── RenderException.php # Provider/config exceptions │ │ ├── ParameterException.php # Parameter validation exceptions │ │ └── ValidationException.php # Data validation exceptions │ ├── Helper/ │ │ └── Helper.php # Utility functions │ ├── Job/ │ │ └── SendSmsJob.php # Queue job for async sending │ ├── Log/ │ │ └── Log.php # Logging manager │ ├── Models/ │ │ └── LaravelBDSmsLog.php # Eloquent model for logs │ ├── Provider/ │ │ ├── ProviderRoadmap.php # Provider interface │ │ ├── AbstractProvider.php # Base provider class │ │ ├── Ssl.php # SSL Wireless provider │ │ ├── CustomGateway.php # Custom gateway provider │ │ └── [48 more providers...] │ ├── LaravelBDSmsServiceProvider.php # Service provider │ ├── SMS.php # Main SMS handler class │ ├── Request.php # HTTP request handler │ └── Sender.php # Core sender (singleton) ├── composer.json └── DOCUMENTATION.md ``` -------------------------------- ### Dynamically Switch SMS Providers Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Switch between different SMS providers at runtime using the `via` method. This allows flexibility in choosing the best provider for specific needs. ```php use Xenon\LaravelBDSms\Provider\Ssl; use Xenon\LaravelBDSms\Provider\BoomCast; // Use SSL Wireless SMS::via(Ssl::class)->shoot('017XXXXXXXXX', 'Via SSL'); // Use BoomCast SMS::via(BoomCast::class)->shoot('017XXXXXXXXX', 'Via BoomCast'); ``` -------------------------------- ### Provider-Specific Validation for SSL Provider Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md This snippet demonstrates validation logic within a provider, specifically for the SSL provider, checking for required configuration keys like 'api_token', 'sid', and 'batch_csms_id' for bulk SMS. It throws RenderException if any required key is missing. ```php // SSL provider validation public function errorException() { if (!array_key_exists('api_token', $this->senderObject->getConfig())) { throw new RenderException('api_token key is absent in configuration'); } if (!array_key_exists('sid', $this->senderObject->getConfig())) { throw new RenderException('sid key is absent in configuration'); } // Bulk SMS requires batch_csms_id if (is_array($this->senderObject->getMobile()) && !array_key_exists('batch_csms_id', $this->senderObject->getConfig())) { throw new RenderException('batch_csms_id is required for bulk SMS'); } } ``` -------------------------------- ### Send SMS with Dynamic Provider Source: https://github.com/arif98741/laravelbdsms/blob/master/readme.md Send an SMS message using a specific provider by dynamically setting it. Ensure the provider class is imported. ```php use Xenon\LaravelBDSms\Facades\SMS; use Xenon\LaravelBDSms\Provider\Ssl; $response = SMS::via(Ssl::class)->shoot('017XXYYZZAA', 'helloooooooo boss!'); ``` -------------------------------- ### Ensure Full Provider Namespace Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Resolves and ensures a full provider namespace string. If a short name is provided, it prepends the base provider namespace. If a full namespace is given, it returns it unchanged. ```php // Ensure full provider namespace $fullClass = Helper::ensurePrefix('Ssl'); // Returns: 'Xenon\LaravelBDSms\Provider\Ssl' $fullClass = Helper::ensurePrefix('Xenon\LaravelBDSms\Provider\Ssl'); // Returns: 'Xenon\LaravelBDSms\Provider\Ssl' (unchanged) ``` -------------------------------- ### Throwing ParameterException for Input Errors Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Illustrates throwing a ParameterException for invalid input parameters such as empty mobile numbers or messages, or incorrect configuration types. This helps in validating user or system inputs before processing. ```php use Xenon\LaravelBDSms\Handler\ParameterException; // Invalid config type throw new ParameterException('config must be an array'); // Empty mobile throw new ParameterException('Mobile number should not be empty'); // Empty message throw new ParameterException('Message text should not be empty'); ``` -------------------------------- ### SMS Sending Flow Diagram Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md This diagram illustrates the complete SMS sending process, from the initial facade call to response processing and optional logging. ```text ┌────────────────────────────────────────────────────────────────┐ │ COMPLETE SMS FLOW │ └────────────────────────────────────────────────────────────────┘ Step 1: Facade Call ═══════════════════ SMS::shoot('017XXX', 'Hello') │ ▼ ┌─────────────────────────────────────┐ │ SMS Facade │ │ getFacadeAccessor() → 'LaravelBDSms' └─────────────────────────────────────┘ │ ▼ Step 2: Container Resolution ════════════════════════════ ┌─────────────────────────────────────┐ │ ServiceProvider.register() │ │ - Get default_provider from config │ │ - Create Sender::getInstance() │ │ - Set provider and config │ │ - Return new SMS($sender) │ └─────────────────────────────────────┘ │ ▼ Step 3: SMS Class Processing ════════════════════════════ ┌─────────────────────────────────────┐ │ SMS::shoot($number, $text) │ │ - $sender->setMobile($number) │ │ - $sender->setMessage($text) │ │ - return $sender->send() │ └─────────────────────────────────────┘ │ ▼ Step 4: Sender Validation ═════════════════════════ ┌─────────────────────────────────────┐ │ Sender::send() │ │ - Validate config is array │ │ - Validate mobile not empty │ │ - Validate message not empty │ │ - Call provider->errorException() │ └─────────────────────────────────────┘ │ ▼ Step 5: Provider Processing ═══════════════════════════ ┌─────────────────────────────────────┐ │ Provider::errorException() │ │ - Validate required config keys │ │ - Throw RenderException if missing │ └─────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────┐ │ Provider::sendRequest() │ │ - Build API query parameters │ │ - Create Request object │ │ - Set headers if needed │ └─────────────────────────────────────┘ │ ▼ Step 6: HTTP Request ════════════════════ ┌─────────────────────────────────────┐ │ Request::post() or Request::get() │ │ - Check if queue enabled │ │ - If queue: dispatch SendSmsJob │ │ - If not: execute GuzzleHTTP │ └─────────────────────────────────────┘ │ ┌────┴────┐ ▼ ▼ Queue Direct │ │ ▼ ▼ Step 7a: Step 7b: Job Guzzle Dispatch Request │ │ ▼ ▼ (later) API Response │ │ └────┬────┘ ▼ Step 8: Response Processing ═══════════════════════════ ┌─────────────────────────────────────┐ │ Provider::generateReport() │ │ - Format JSON response │ │ - Include status, provider, time │ │ - Include mobile and message │ └─────────────────────────────────────┘ │ ▼ Step 9: Logging (Optional) ══════════════════════════ ┌─────────────────────────────────────┐ │ Sender::logGenerate() │ │ - Check if sms_log enabled │ │ - Database: Logger::createLog() │ │ - File: LaravelLog::info() │ └─────────────────────────────────────┘ │ ▼ Step 10: Return Response ════════════════════════ ┌─────────────────────────────────────┐ │ JSON Response returned to caller │ │ { │ "status": "response", │ "response": "", │ "provider": "...", │ "send_time": "...", │ "mobile": "...", │ "message": "..." │ } └─────────────────────────────────────┘ ``` -------------------------------- ### Send SMS using Facade Alias Source: https://github.com/arif98741/laravelbdsms/blob/master/readme.md Send SMS messages using the facade alias. This method requires the facade alias to be set up. ```php use LaravelBDSms, SMS; LaravelBDSms::shoot('017XXYYZZAA', 'helloooooooo boss!'); SMS::shoot('017XXYYZZAA', 'helloooooooo boss!'); ``` -------------------------------- ### Send a Simple SMS Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Use the SMS facade to send a single SMS message. This is the most straightforward way to send a message. ```php use Xenon\LaravelBDSms\Facades\SMS; // Simple SMS SMS::shoot('017XXXXXXXXX', 'Hello from LaravelBDSMS!'); // Using alias LaravelBDSms::shoot('017XXXXXXXXX', 'Hello World!'); ``` -------------------------------- ### Import Request Class Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Import the Request class for making HTTP requests related to SMS services. ```php use Xenon\LaravelBDSms\Request; ``` -------------------------------- ### Set File Log Driver Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Configure the 'log_driver' to 'file' in your sms.php configuration to use file-based logging. ```php 'log_driver' => 'file', ``` -------------------------------- ### Abstract Provider Base Class Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Extend AbstractProvider to inherit common functionalities and implement abstract methods required by the ProviderRoadmap interface. ```php abstract class AbstractProvider implements ProviderRoadmap { protected $senderObject; abstract public function sendRequest(); abstract public function errorException(); public function generateReport($result, $data): JsonResponse { return response()->json([ 'status' => 'response', 'response' => $result, 'provider' => get_class($this), 'send_time' => date('Y-m-d H:i:s'), 'mobile' => $data['number'], 'message' => $data['message'] ]); } } ``` -------------------------------- ### Querying Logs with Eloquent Model Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Shows how to query log entries using the LaravelBDSmsLog Eloquent model, including filtering by provider and pagination. ```php use Xenon\LaravelBDSms\Models\LaravelBDSmsLog; // Query logs $logs = LaravelBDSmsLog::where('provider', 'like', '%Ssl%') ->orderBy('created_at', 'desc') ->paginate(20); ``` -------------------------------- ### Enable SMS Logging Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Set 'sms_log' to true in your sms.php configuration file to enable logging of SMS activities. ```php 'sms_log' => true, ``` -------------------------------- ### Laravel BDSMS Configuration File Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md The main configuration file for the Laravel BDSMS package, controlling logging, log driver, default provider, and provider-specific credentials. ```php false, /* |-------------------------------------------------------------------------- | Log Driver |-------------------------------------------------------------------------- | Where to store logs: 'database' (lbs_log table) or 'file' (laravel.log) */ 'log_driver' => 'database', // database, file /* |-------------------------------------------------------------------------- | Default Provider |-------------------------------------------------------------------------- | The default SMS provider used by the SMS facade. */ 'default_provider' => env('SMS_DEFAULT_PROVIDER', Ssl::class), /* |-------------------------------------------------------------------------- | Provider Credentials |-------------------------------------------------------------------------- | Configuration for each SMS provider. */ 'providers' => [ Ssl::class => [ 'api_token' => env('SMS_SSL_API_TOKEN', ''), 'sid' => env('SMS_SSL_SID', ''), 'csms_id' => env('SMS_SSL_CSMS_ID', ''), 'batch_csms_id' => env('SMS_SSL_BATCH_CSMS_ID', ''), ], // ... other providers ] ]; ``` -------------------------------- ### Handling SMS Exceptions in a Try-Catch Block Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Shows how to use a try-catch block to gracefully handle RenderException, ParameterException, and other general exceptions that may occur during SMS sending operations. This ensures your application remains stable. ```php use Xenon\LaravelBDSms\Facades\SMS; use Xenon\LaravelBDSms\Handler\RenderException; use Xenon\LaravelBDSms\Handler\ParameterException; try { $response = SMS::shoot('017XXXXXXXXX', 'Hello World!'); } catch (RenderException $e) { // Handle configuration errors Log::error('SMS Config Error: ' . $e->getMessage()); } catch (ParameterException $e) { // Handle parameter errors Log::error('SMS Parameter Error: ' . $e->getMessage()); } catch (\Exception $e) { // Handle other errors Log::error('SMS Error: ' . $e->getMessage()); } ``` -------------------------------- ### Infobip Environment Variables Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Environment variables required for configuring the Infobip SMS provider. ```env SMS_INFOBIP_BASE_URL=https://api.infobip.com SMS_INFOBIP_USER=your_username SMS_INFOBIP_PASSWORD=your_password SMS_INFOBIP_FROM=your_sender ``` -------------------------------- ### Debug SMS Sending with Logging Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Implement a try-catch block to send an SMS and log the response or any exceptions that occur. This helps in debugging issues with the SMS sending process. ```php try { $response = SMS::shoot('017XXXXXXXXX', 'Test'); Log::info('SMS Response', ['response' => $response]); } catch (\ Exception $e) { Log::error('SMS Error', [ 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); } ``` -------------------------------- ### Basic Custom Gateway Usage Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Use this snippet to send a basic SMS via a custom gateway using the POST method. Ensure the provider, URL, method, and configuration are correctly set. ```php use Xenon\LaravelBDSms\Sender; use Xenon\LaravelBDSms\Provider\CustomGateway; $sender = Sender::getInstance(); $sender->setProvider(CustomGateway::class) ->setUrl('https://api.yoursmsgateway.com/send') ->setMethod('post') ->setConfig([ 'api_key' => 'your_api_key', 'sender_id' => 'YourBrand', 'to' => '017XXXXXXXXX', 'message' => 'Hello World!', ]); $response = $sender->send(); ``` -------------------------------- ### Generate Log File Source: https://github.com/arif98741/laravelbdsms/blob/master/readme.md Generate a log file for SMS activities. This is useful for debugging and tracking sent messages. ```bash php artisan bdsms:log ``` -------------------------------- ### Send SMS using Custom Gateway Source: https://github.com/arif98741/laravelbdsms/blob/master/readme.md This snippet shows how to send an SMS using a custom gateway provider. You need to specify the provider class, URL, HTTP method, headers, mobile number, message, and gateway-specific configuration parameters. The `setQueue(false)` indicates synchronous sending. ```php use Xenon\LaravelBDSms\Provider\CustomGateway; use Xenon\LaravelBDSms\Sender; $sender = Sender::getInstance(); $sender->setProvider(CustomGateway::class); $sender->setUrl('https://your_cusom_gateway_provider_url_here') ->setMethod('post') ->setHeaders([ 'Content-Type: application/json', 'Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', ], false); $sender->setMobile('017XXYYZZAA'); $sender->setMessage('text message goes here'); $sender->setQueue(false); //use required parameters based on your sms gateway. This will be changed according to need $sender->setConfig( [ 'MsgType' => 'TEXT', 'masking' => 'sample', 'userName' => 'test_user', 'message' => 'test message', 'receiver' => '017xxxxxxxxxx', ] ); echo $status = $sender->send(); ``` -------------------------------- ### Send SMS via Queue with Provider Selection Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Send an SMS message asynchronously using a specific provider and custom queue settings. This is useful for prioritizing or routing messages through particular services. ```php use Xenon\LaravelBDSms\Provider\BoomCast; SMS::via(BoomCast::class)->shootWithQueue( '017XXXXXXXXX', 'Urgent message', 'urgent_sms', 5, 30 ); ``` -------------------------------- ### Configure SSL Wireless SMS Provider Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Set environment variables for SSL Wireless SMS API token, SID, and CSMS IDs. Use this for default SMS sending in Bangladesh. ```env SMS_SSL_API_TOKEN=your_token SMS_SSL_SID=your_sid SMS_SSL_CSMS_ID=unique_csms_id SMS_SSL_BATCH_CSMS_ID=batch_id_for_bulk ``` -------------------------------- ### SMS Facade Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md The SMS Facade provides a convenient way to send SMS messages immediately or via a queue, and to switch between different SMS providers. ```APIDOC ## SMS Facade ### Description Provides methods to send SMS messages directly or through a queue, and to manage SMS providers. ### Methods #### `shoot(string $mobile, string $text)` - **Description**: Send SMS immediately. - **Parameters**: - `mobile` (string): The recipient's mobile number. - `text` (string): The SMS message content. - **Returns**: `mixed` #### `via(string $provider)` - **Description**: Switch SMS provider. - **Parameters**: - `provider` (string): The name of the provider to switch to. - **Returns**: `SMS` (The SMS Facade instance for chaining). #### `shootWithQueue(string $number, string $text, string $queueName = 'default', int $tries = 3, int $backoff = 60)` - **Description**: Queue SMS for sending. - **Parameters**: - `number` (string): The recipient's mobile number. - `text` (string): The SMS message content. - `queueName` (string, optional): The name of the queue. Defaults to 'default'. - `tries` (int, optional): The number of retry attempts. Defaults to 3. - `backoff` (int, optional): The delay in seconds between retries. Defaults to 60. - **Returns**: `mixed` ``` -------------------------------- ### Use Laravel BDSMS with Facade Alias Source: https://github.com/arif98741/laravelbdsms/blob/master/readme.md Send SMS messages using the configured facade alias. Ensure the alias is correctly set in your app.php configuration file. ```php use Illuminate\Support\Facades\Facade; return [ // ... 'aliases' => Facade::getAliases( // ... 'BDSms' => Arif98741\LaravelBDSms\Facades\BDSms::class, ), ]; BDSms::send("01700000000", "Hello World"); ``` -------------------------------- ### SSL Wireless Environment Variables Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Environment variables required for configuring the SSL Wireless SMS provider. ```env SMS_SSL_API_TOKEN=your_api_token SMS_SSL_SID=your_sender_id SMS_SSL_CSMS_ID=your_csms_id SMS_SSL_BATCH_CSMS_ID=your_batch_id ``` -------------------------------- ### Send SMS using SSLCommerz Provider Source: https://github.com/arif98741/laravelbdsms/blob/master/readme.md This snippet demonstrates how to send an SMS using the SSLCommerz provider. Ensure you have set the provider, mobile number, message, and configuration details including API token, SID, and CSMS ID. The `setQueue(false)` indicates synchronous sending. ```php use Xenon\LaravelBDSms\Provider\Ssl; use Xenon\LaravelBDSms\Sender; $sender = Sender::getInstance(); $sender->setProvider(Ssl::class); //change this provider class according to need $sender->setMobile('017XXYYZZAA'); //$sender->setMobile(['017XXYYZZAA','018XXYYZZAA']); $sender->setMessage('helloooooooo boss!'); $sender->setQueue(false); //set true if you want to sent sms from queue $sender->setConfig( [ 'api_token' => 'api token goes here', 'sid' => 'text', 'csms_id' => 'sender_id' ] ); $status = $sender->send(); ----------Demo Response Using SSL------------- array:6 [▼ "status" => "response" "response" => "{"status":"FAILED","status_code":4003,"error_message":"IP Blacklisted"}" "provider" => "Xenon\LaravelBDSms\Provider\Ssl" "send_time" => "2021-07-06 08:03:23" "mobile" => "017XXYYZZAA" "message" => "helloooooooo boss!" ] -------------------------------------------------- ``` -------------------------------- ### Send SMS with Queue Source: https://github.com/arif98741/laravelbdsms/blob/master/readme.md Send SMS messages using Laravel's queue system. This improves performance by sending messages in the background and adds them to your jobs table. ```php use Arif98741\LaravelBDSms\Facades\BDSms; BDSms::queue("01700000000", "Hello World"); ``` -------------------------------- ### Send SMS using SSL Wireless Provider Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md Use the SMS facade to send a message via the SSL Wireless provider. Ensure the provider is configured in your environment variables. ```php use Xenon\LaravelBDSms\Provider\Ssl; SMS::via(Ssl::class)->shoot('017XXXXXXXXX', 'Message'); ``` -------------------------------- ### Send SMS Using Custom Gateway Source: https://github.com/arif98741/laravelbdsms/blob/master/readme.md Send SMS messages using a custom gateway. This requires defining your custom gateway logic and integrating it with the package. ```php use Arif98741\LaravelBDSms\Facades\BDSms; BDSms::custom("01700000000", "Hello World", "custom_gateway_name"); ``` -------------------------------- ### Provider Interface Definition Source: https://github.com/arif98741/laravelbdsms/blob/master/DOCUMENTATION.md All custom providers must implement the ProviderRoadmap interface, defining the essential methods for SMS operations. ```php interface ProviderRoadmap { public function getData(); public function setData(); public function sendRequest(); public function generateReport($result, $data); public function errorException(); } ``` -------------------------------- ### Send SMS with Queue Source: https://github.com/arif98741/laravelbdsms/blob/master/readme.md Send SMS messages via a queue. This adds a job to your jobs table, and the message will be sent when the job is processed. Ensure the jobs table and related functionalities are enabled. ```php use Xenon\LaravelBDSms\Facades\SMS; use Xenon\LaravelBDSms\Provider\Ssl; SMS::shootWithQueue("01XXXXXXXXX",'test sms'); SMS::via(Ssl::class)->shootWithQueue("01XXXXXXXXX",'test sms'); ```