How can i send OTP to users phone number in Laravel

579 Views Asked by At

I have gupshup account. i want to create api in laravel which will send otp to phone using gupshup account.i am new at laravel

1

There are 1 best solutions below

0
On

As per GupShup API docs for Outbound Messages you will need to make a post request to their server with your API key and information.

Laravel uses Guzzle HTTP client to make requests. You can make post requests using the HTTP facade. An untested example is below:

use Illuminate\Support\Facades\Http; // To be added to the top of your file where you add the code below

// Put the following code in the function which sends out the OTP.
$response = Http::withHeaders([
                  "Content-Type" => "application/x-www-form-urlencoded",
                  "apikey": "{{Your API Key}}" // replace with your API key
                   ])
                  ->post('https://api.gupshup.io/sm/api/v1/msg',
                       [
                       "channel" => "whatsapp",
                       "source" => "1111111111", // your business number
                       "destination" => "9999999999", // clients number
                       "src.name" => "Your App" // Your App Name
                       "message" => [
                             "isHSM" => "false",
                             "type" => "text",
                             "text" => "{{Your OTP is XXXXX}}" // replace with text you want to send
                         ] 
                       ]
                      );