Skip to content

Commit 5ab0106

Browse files
authored
docs(readme): rearrange section for config
1 parent 28ee9b2 commit 5ab0106

1 file changed

Lines changed: 46 additions & 31 deletions

File tree

README.md

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ This is a **PHP Client** for [Msg91 APIs](https://docs.msg91.com/collection/msg9
2828
## Table of Contents
2929

3030
- [Installation](#installation)
31-
- [Configuration](#configuration)
3231
- [Usage](#usage)
3332
- [Create a Client](#create-a-client)
33+
- [Configuration](#configuration)
3434
- [OTP and SMS Services](#otp-and-sms-services)
3535
- [Examples](#examples)
3636
- [Managing OTPs](#managing-otps)
@@ -52,34 +52,6 @@ The packages is available on [Packagist](https://packagist.org/packages/craftsys
5252
composer require craftsys/msg91-php
5353
```
5454

55-
## Configuration
56-
57-
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.
58-
59-
An example configuration might look something like this:
60-
61-
```php
62-
$config = [
63-
'key' => "123456789012345678901234",
64-
'otp_message' => "G: ##OTP## is your verification code".
65-
];
66-
```
67-
68-
Following configuration options are available:
69-
70-
| Option | Type | Description | Default Value |
71-
| :---------------- | :--------------------- | :--------------------------------------------------------------------------------------------------------------------------------------- | :------------------ |
72-
| key | string | The authentication key for Msg91 apis (**required**) | null |
73-
| otp_message | ?string | Message template used when an OTP is sent. The **##OTP##** placeholder is required | Your OTP is ##OTP## |
74-
| 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 |
75-
| from | ?string | The default name for sender. This is used the **From** in messaging applications. It's value can only contain alphanumeric values. | null |
76-
| 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 |
77-
| otp_expiry | ?number | Duration (in minutes) for which the OTP is valid. | 5 |
78-
| route | ?number | [Route](https://help.msg91.com/article/64-what-is-the-difference-between-transactional-promotional-and-sendotp-route) for SMS | null |
79-
| unicode | ?number | Set to this 1 if all your message contains unicode characters | 0 |
80-
81-
**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](https://docs.msg91.com/collection/msg91-api-integration/5/send-otp-message/TZ6HN0YI)
82-
8355
## Usage
8456

8557
If you're using Composer, make sure the autoloader is included in your project's bootstrap file:
@@ -88,7 +60,7 @@ If you're using Composer, make sure the autoloader is included in your project's
8860
require_once "vendor/autoload.php";
8961
```
9062

91-
Once you have [Configured](#configuration), client can be initialised by passing a configuration object to the constructor. The configuration in the constructor is optional.
63+
Now the client can be initialised by passing a [configured](#configuration) object to the constructor.
9264

9365
```php
9466
$config = [
@@ -105,8 +77,19 @@ The package in distributed under `Craftsys\Msg91` namespace which can used if yo
10577
use Craftsys\Msg91\Client;
10678

10779
// somewhere in this source file where you need the client
108-
$client = new Client();
80+
$client = new Client($config);
81+
82+
// send OTP using the otp service on client
83+
$client->otp()->to(919999999999)->send();
84+
85+
// verify an OTP (1234)
86+
$client->otp(1234)->to(919999999999)->verify();
87+
88+
// send SMS using the sms service on client
89+
$client->sms()->to(919999999999)->flow("<flow_id>")->send();
10990
```
91+
Continue reading to learn more about configuration and available method on `opt` and `sms` services with examples.
92+
11093

11194
### Create a Client
11295

@@ -128,6 +111,38 @@ You can also pass a custom `GuzzleHttp\Client` as the second argument on the Cli
128111
```php
129112
$client = new Craftsys\Msg91\Client($config, new GuzzleHttp\Client());
130113
```
114+
115+
116+
### Configuration
117+
118+
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.
119+
120+
An example configuration might look something like this:
121+
122+
```php
123+
$config = [
124+
'key' => "123456789012345678901234",
125+
'otp_message' => "G: ##OTP## is your verification code".
126+
];
127+
```
128+
129+
Following configuration options are available:
130+
131+
| Option | Type | Description | Default Value |
132+
| :---------------- | :--------------------- | :--------------------------------------------------------------------------------------------------------------------------------------- | :------------------ |
133+
| key | string | The authentication key for Msg91 apis (**required**) | null |
134+
| otp_message | ?string | Message template used when an OTP is sent. The **##OTP##** placeholder is required | Your OTP is ##OTP## |
135+
| 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 |
136+
| from | ?string | The default name for sender. This is used the **From** in messaging applications. It's value can only contain alphanumeric values. | null |
137+
| 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 |
138+
| otp_expiry | ?number | Duration (in minutes) for which the OTP is valid. | 5 |
139+
| route | ?number | [Route](https://help.msg91.com/article/64-what-is-the-difference-between-transactional-promotional-and-sendotp-route) for SMS | null |
140+
| unicode | ?number | Set to this 1 if all your message contains unicode characters | 0 |
141+
142+
**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](https://docs.msg91.com/collection/msg91-api-integration/5/send-otp-message/TZ6HN0YI)
143+
144+
145+
131146
### OTP and SMS Services
132147

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

0 commit comments

Comments
 (0)