Download the PHP package anburocky3/msg91-php without Composer

On this page you can find all versions of the php package anburocky3/msg91-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package msg91-php

Send SMS Seemlessy with MSG91

This library requires a minimum PHP version of 7.4

Latest Version on Packagist GitHub Code Style Action Status Total Downloads Follow Anbuselvan Rocky

Msg91 API integration

This is a PHP Client for Msg91 APIs. Before using it, please make sure you have an account on Msg91 and have an Authkey (Msg91 Dashboard > API > Configure).

NOTE: The project is under active development and so, some apis are subjected to change.

Table of Contents

Installation

The packages is available on Packagist and can be installed via Composer by executing following command in shell.

Usage

If you're using Composer, make sure the autoloader is included in your project's bootstrap file:

Now the client can be initialised by passing a configured object to the constructor.

The package in distributed under Anburocky3\Msg91 namespace which can used if your are working in a namespace environment.

Continue reading to learn more about configuration and available method on opt and sms services with examples.

Create a Client

The client is responsible for interacting with Msg91 apis.

Client can also be initialised without a configuration which can be set by calling setConfig($config) method on the client instance.

You can also pass a custom GuzzleHttp\Client as the second argument on the Client's constructor.

Configuration

The module is configurable to your specific needs where you need to set default options for APIs like the default OTP message format, retry method etc.

An example configuration might look something like this:

Following configuration options are available:

Option Type Description Default Value
key string The authentication key for Msg91 apis (required) null
otp_message ?string Message template used when an OTP is sent. The ##OTP## placeholder is required Your OTP is ##OTP##
resend_otp_method ?enum("text", "voice") Default method when resending an OTP when previous attempt of OTP send/verification failed. It can take one of "text" or "voice" values. text
from ?string The default name for sender. This is used the From in messaging applications. It's value can only contain alphanumeric values. null
otp_length ?number Length of the generated OTP by Msg91 api when you are not generating OTPs on our end.. This can be between [4, 9] 4
otp_expiry ?number Duration (in minutes) for which the OTP is valid. 5
route ?number Route for SMS null
unicode ?number Set to this 1 if all your message contains unicode characters 0

NOTE: Setting any if these values as null will override the default values to null too. And so, the default values from Msg91 APIs will be used. For example, setting the otp_message to null will let use "Your verification code is ##OTP##" which the default from APIS

OTP and SMS Services

After a client has been created, you can access otp and sms services to send OTPs and SMSs respectivily.

NOTE: Configuration must be set before using any other services on the client.

Next, follow along with examples to learn more

Examples

Managing OTPs

OTP services like sending, verifying, and resending etc, can be accessed via otp method on the client instance e.g. $client->otp(). All the parameters which are available for the Msg91 API, have a corresponding intuitive method name e.g. to set the digits in otp for the send OTP request, you call the digits method on the service. You can create there via \Anburocky3\Msg91\Options class. See following examples to learn more.

Send OTP

Basic Usage

Advanced Usage

Instead of relying on defaults from the Msg91 or the client, you can pass all the custom options that are accepted by Msg91 APIs using the options helper on the service. This method accepts a close which will be called with underline \Anburocky3\Msg91\OTP\Options instance and gives your the full flexibility to add any options that is required.

NOTE: If you are generating the OTP at your side, and passing it to the service, along with a custom message, you MUST include the ##OTP## or actual value of OTP inside the message. Failing to do so will result in error

Verify OTP

As the verification does not send any messages, you just need to provide the required fields to verify the OTP e.g. the sent OTP and Phone Number only.

Resend OTP

To resend an OTP, access to otp service and call the resend with to resend the OTP. Method of communication can be changed by calling viaVoice or viaText before sending the OTP. The default values can be set into the configuration

Sending SMS

To send SMS, access the SMSService by calling ->sms() method on the client instance

To add any more options to the message, you can call the options method before sending the message. The options method accepts a call which will receive a \Anburocky3\Msg91\SMS\Options instance. Using it, you can modify any desired option.

Message Variables

To send SMS, you create Flow where you can provide a template for your SMS. This template may contain some variables which you use as placeholder for per message data. You can use recipients method to set the values for these variables per recipient while sending SMS as follows.

Let's assume that you have create a Flow with following message template

We will to update the name and date variables per recipient.

The mobiles key in the recipients array comes from the receiver field's value which we set when creating a new Flow. It defaults to mobiles. If you have provided a different receiver key, please update the recipients key accordingly.

If you want to put same value for a variable for all recipients, you can use variable method as follows

Note: You should call the variable method only after you have set the recipients.

Receiver Key

When creating a Flow on MSG91, you can create a custom receiver key which default to ##mobiles##. This default is being used in this package as well. If you have configured your flow with a different receiver key, you can set it via receiverKey method as follows:

Assuming you have set the receiver field to ##contact##,

Handling Responses

All the services will return \Anburocky3\Msg91\Support\Response instance for all successfully responses and will throw exceptions if

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

Major source code references have been taken from the following

License

The MIT License (MIT). Please see License File for more information.

Related


All versions of msg91-php with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
guzzlehttp/guzzle Version ^7.0.1
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package anburocky3/msg91-php contains the following files

Loading the files please wait ....