{"id":27143460,"url":"https://github.com/craftsys/msg91-laravel","last_synced_at":"2025-07-19T19:37:17.224Z","repository":{"id":35170712,"uuid":"216199060","full_name":"craftsys/msg91-laravel","owner":"craftsys","description":"Send SMS, OTP in Laravel using Msg91 Apis","archived":false,"fork":false,"pushed_at":"2024-04-25T11:47:23.000Z","size":66,"stargazers_count":11,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-25T12:46:52.347Z","etag":null,"topics":["laravel","msg91","otp","php-client","sms"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/craftsys.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-19T11:57:25.000Z","updated_at":"2024-06-18T22:55:05.568Z","dependencies_parsed_at":"2024-04-25T12:55:21.479Z","dependency_job_id":null,"html_url":"https://github.com/craftsys/msg91-laravel","commit_stats":{"total_commits":74,"total_committers":3,"mean_commits":"24.666666666666668","dds":0.5405405405405406,"last_synced_commit":"a170ca61c1bf0f2c9076ced83ab57a0dbf146cce"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craftsys%2Fmsg91-laravel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craftsys%2Fmsg91-laravel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craftsys%2Fmsg91-laravel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craftsys%2Fmsg91-laravel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/craftsys","download_url":"https://codeload.github.com/craftsys/msg91-laravel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247806262,"owners_count":20999308,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","msg91","otp","php-client","sms"],"created_at":"2025-04-08T08:40:41.798Z","updated_at":"2025-04-08T08:40:43.206Z","avatar_url":"https://github.com/craftsys.png","language":"PHP","readme":"# Laravel service provider for Msg91\n\n\n\u003cp\u003e\n\u003ca href=\"https://packagist.org/packages/craftsys/msg91-laravel\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dt/craftsys/msg91-laravel\" alt=\"Total Downloads\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/craftsys/msg91-laravel\"\u003e\u003cimg src=\"https://img.shields.io/packagist/v/craftsys/msg91-laravel?label=version\" alt=\"Latest Stable Version\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/craftsys/msg91-laravel\"\u003e\u003cimg src=\"https://img.shields.io/packagist/l/craftsys/msg91-laravel\" alt=\"License\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/craftsys/msg91-laravel/actions/workflows/test.yml\"\u003e\u003cimg src=\"https://github.com/craftsys/msg91-laravel/actions/workflows/test.yml/badge.svg\" alt=\"Status\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\n\nThis is a **[laravel](https://laravel.com) service provider** for [Msg91 APIs](https://docs.msg91.com/collection/msg91-api-integration/5/pages/139). It wraps the [msg91-php][client] client and provides the same functionality for Laravel applications by exposing a Service Provider and Facade.\n\n\n## Table of Contents\n\n-   [Installation](#installation)\n-   [Configuration](#configuration)\n-   [Usage](#usage)\n-   [Examples](#examples)\n    -   [Managing OTPs](#managing-otps)\n        -   [Send OTP](#send-otp)\n        -   [Verify OTP](#verify-otp)\n        -   [Resend OTP](#resend-otp)\n    -   [Sending SMS](#sending-sms)\n        - [Bulk SMS](#bulk-sms)\n        - [Message Variables](#message-variables)\n    -   [Handling Responses](#handling-responses)\n-   [Related](#related)\n-   [Acknowledgements](#acknowledgements)\n\n## Installation\n\nThe packages is available on [Packagist](https://packagist.org/packages/craftsys/msg91-laravel) and can be installed via [Composer](https://getcomposer.org/) by executing following command in shell.\n\n```bash\ncomposer require craftsys/msg91-laravel\n```\n\n**prerequisite**\n\n-   php^7.1\n-   laravel^5|^6|^7|^8|^9|^10\n\nThe package is tested for 5.8+,^6.0,^7.0,^8.0,^9.0,^10.0 only. If you find any bugs for laravel (5.0\u003c \u003e5.8), please file an issue.\n\n### Laravel 5.5+\n\nIf you're using Laravel 5.5 or above, the package will automatically register the `Craftsys\\Msg91\\Msg91LaravelServiceProvider` provider and aliases `Craftsys\\Msg91\\Facade\\Msg91` facade to `Msg91`.\n\n### Laravel 5.4 and below\n\nAdd `Craftsys\\Msg91\\Msg91LaravelServiceProvider` to the `providers` array in your `config/app.php`:\n\n```php\n'providers' =\u003e [\n     // Other service providers...\n     Craftsys\\Msg91\\Msg91LaravelServiceProvider::class,\n],\n```\n\nIf you want to use the facade interface, you can `use` the facade class when needed:\n\n```php\nuse Craftsys\\Msg91\\Facade\\Msg91;\n```\n\nOr add an alias in your `config/app.php`\n\n```php\n'aliases' =\u003e [\n    // other aliases here\n    'Msg91' =\u003e Craftsys\\Msg91\\Facade\\Msg91::class,\n],\n```\n\nTo verify that everything is working as expected, excecute the following php code somewhere in your application, either\nin an example route or in `php artisan tinker` if you are in Laravel.\n\n```php\n// this should print the `\\Craftsys\\Msg91\\OTP\\OTPService` of some default configuration values\necho Msg91::otp()::class\n```\n\nIf there is an issue, please check the steps again or open an issue for support.\n\n## Configuration\n\nAs the [msg91-php][client] offers configuration that are similar to Laravel's configuration, this package simply ports the Laravel's configuration to the msg91-php client.\n\nThe package can be configured by providing a `msg91` key inside your `config/services.php` configuration file.\n\n```php\n\u003c?php\n\nreturn [\n  // along with other services\n  \"msg91\" =\u003e [\n    'key' =\u003e env(\"Msg91_KEY\"),\n  ],\n];\n```\n\nand update the `.env` file to get the desired values e.g. `Msg91_KEY`.\n\nPlease visit [msg91-php configuration][client-configuration] for a detailed description about the available options and their default values.\n\n## Usage\n\nOnce you have [Configured](#configuration) the Laravel/Lumen application to use the service provider and have aliased the facade to `Msg91`, you will have a [msg91-php][client] client (Craftsys\\Msg91\\Client) instance.\n\n```php\n// send otp\nMsg91::otp()-\u003eto(919999999999)-\u003esend();\n\n// resend otp\nMsg91::otp()-\u003eto(919999999999)-\u003eviaVoice()-\u003eresend();\n\n// verify otp\nMsg91::otp(678612)-\u003eto(919999999999)-\u003everify();\n\n// send sms\nMsg91::sms()-\u003eto(919999999999)-\u003eflow('\u003cflow_id\u003e')-\u003esend();\n\n// in bulk\nMsg91::sms()-\u003eto([919999999999, 918899898990])-\u003eflow('\u003cflow_id\u003e')-\u003esend();\n\n// with variables in your flow template\nMsg91::sms()-\u003eto([919999999999, 918899898990])-\u003eflow('\u003cflow_id\u003e')-\u003evariable('variable_name', 'value')-\u003esend();\n\n// with variables per recipient\nMsg91::sms()-\u003erecipients([\n  ['mobiles' =\u003e 919999999999, 'name' =\u003e 'Sudhir M'],\n  ['mobiles' =\u003e 918899898990, 'name' =\u003e 'Craft Sys']\n])\n  -\u003eflow('\u003cflow_id\u003e')\n  -\u003esend();\n```\n\nFollow along with [examples](#examples) to learn more\n\n## Examples\n\n### Managing OTPs\n\nOTP services like sending, verifying, and resending etc, can be accessed via `otp` method on the client instance e.g. `Msg91::otp()`.\n\n\u003e For a detailed usage, please visit [msg91-php's documentation][client-managing-otps] on managing OTPs.\n\n#### Send OTP\n\n```php\nMsg91::otp()\n    -\u003eto(912343434312) // phone number with country code\n    -\u003etemplate('your_template_id') // set the otp template\n    -\u003esend(); // send the otp\n```\n\n### Verify OTP\n\n```php\nMsg91::otp(1234) // OTP to be verified\n    -\u003eto(912343434312) // phone number with country code\n    -\u003everify(); // Verify\n```\n\n### Resend OTP\n\n```php\nMsg91::otp()\n    -\u003eto(912343434312) // set the mobile with country code\n    -\u003eviaVoice() // set the otp sending method (can be \"viaText\" as well)\n    -\u003eresend(); // resend otp\n```\n\n## Sending SMS\n\n```php\nMsg91::sms()\n    -\u003eto(912343434312) // set the mobile with country code\n    -\u003eflow(\"your_flow_id_here\") // set the flow id\n    -\u003esend(); // send\n```\n\n### Bulk SMS\n\n```php\nMsg91::sms()\n    -\u003eto([912343434312, 919898889892]) // set the mobiles with country code\n    -\u003eflow(\"your_flow_id_here\") // set the flow id\n    -\u003esend(); // send\n```\n\n### Message Variables\n\n```php\n// send in bulk with variables    \nMsg91::sms()\n    -\u003eto([912343434312, 919898889892]) // set the mobiles with country code\n    -\u003eflow(\"your_flow_id_here\") // set the flow id\n    -\u003evariable('date', \"Sunday\") // the the value for variable \"date\" in your flow message template\n    -\u003esend(); // send\n    \n// send in bulk with variables per recipient\nMsg91::sms()\n    -\u003eto([912343434312, 919898889892]) // set the mobiles with country code\n    -\u003eflow(\"your_flow_id_here\") // set the flow id\n    -\u003erecipients([\n      ['mobiles' =\u003e 919999223345, 'name' =\u003e 'Sudhir M'],\n      ['mobiles' =\u003e 912929223345, 'name' =\u003e 'Craft Sys']\n    ])\n    // (optionally) set a \"date\" variable for all the recipients\n    -\u003evariable('date', \"Sunday\")\n    -\u003esend(); // send\n```\n\n\u003e For a detailed usage and options, please visit [msg91-php's documentation][client-sending-sms] on sending SMSs. \n\n## Handling Responses\n\nAll the services will return `\\Craftsys\\Msg91\\Support\\Response` instance for all successfully responses or will throw exceptions if request validation failed (`\\Craftsys\\Msg91\\Exceptions\\ValidationException`)or there was an error in the response (`\\Craftsys\\Msg91\\Exceptions\\ResponseErrorException`).\n\n```php\ntry {\n    $response = $client-\u003eotp()-\u003eto(919999999999)-\u003esend();\n} catch (\\Craftsys\\Msg91\\Exceptions\\ValidationException $e) {\n    // issue with the request e.g. token not provided\n} catch (\\Craftsys\\Msg91\\Exceptions\\ResponseErrorException $e) {\n    // error thrown by msg91 apis or by http client\n} catch (\\Exception $e) {\n    // something else went wrong\n    // plese report if this happens :)\n}\n```\n\n\u003e For all the examples and options, please consult [msg91-php examples section][client-examples]\n\n[client]: https://github.com/craftsys/msg91-php\n[client-configuration]: https://github.com/craftsys/msg91-php#configuration\n[client-examples]: https://github.com/craftsys/msg91-php#examples\n[client-managing-otps]: https://github.com/craftsys/msg91-php#managing-otps\n[client-sending-sms]: https://github.com/craftsys/msg91-php#sending-sms\n\n\n# Related\n\n- [Msg91 Laravel Notification Channel](https://github.com/craftsys/msg91-laravel-notification-channel)\n- [Msg91 Php Client](https://github.com/craftsys/msg91-php)\n- [Msg91 Api Docs](https://docs.msg91.com/collection/msg91-api-integration/5/pages/139)\n\n# Acknowledgements\n\nWe are grateful to the authors of existing related projects for their ideas and collaboration:\n\n- [Laravel Nexmo](https://github.com/Nexmo/nexmo-laravel)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcraftsys%2Fmsg91-laravel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcraftsys%2Fmsg91-laravel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcraftsys%2Fmsg91-laravel/lists"}