PHP code example of sevenspan / laravel-whatsapp

1. Go to this page and download the library: Download sevenspan/laravel-whatsapp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sevenspan / laravel-whatsapp example snippets




return [
    /*
    |--------------------------------------------------------------------------
    | Whatsapp API URI
    |--------------------------------------------------------------------------
    |
    | The Whatsapp Message API URI.
    |
    */

    'api_uri' => env('WHATSAPP_API_URI', 'https://graph.facebook.com/v14.0/'),

    /*
    |--------------------------------------------------------------------------
    | WHATSAPP BUSINESS ACCOUNT ID
    |--------------------------------------------------------------------------
    |
    | The Whatsapp business account id (waba_id).
    |
    */

    'whatsapp_business_account_id' => env('WHATSAPP_BUSINESS_ACCOUNT_ID', ''),

    /*
    |--------------------------------------------------------------------------
    | ACCESS TOKEN
    |--------------------------------------------------------------------------
    |
    | The Whatsapp business account user access token.
    |
    */
    'access_token' => env('ACCESS_TOKEN', ''),

    /*
    |--------------------------------------------------------------------------
    | SEPARATOR
    |--------------------------------------------------------------------------
    |
    | The Whatsapp separator is used for the separat your string message.
    | For example: $message = 'Hello,123'; then set your .env file variable (SEPARATO=,).
    */
    'separator' => env('SEPARATOR', '~'),

    /*
    |--------------------------------------------------------------------------
    | FROM PHONE NUMBER ID
    |--------------------------------------------------------------------------
    |
    | The Whatsapp register phome number Id.
    | You have to get from phone number id using getPhoneNumbers() function.
    */
    'from_phone_number_id' => env('FROM_PHONE_NUMBER_ID', ''),
];



$response = WhatsApp::sendTemplateMessage(string $to, string $templateName, string $languageCode, string $accessToken = '', string $fromPhoneNumberId = '', array $components = [], string $messages = '');

# A successful response id.HBgMOTE3ODc4OTE4MDXSDQIAERgSOUIwQzlGREQ5NUZBQjQ1OTkzAA=="
    ]
  ]
]

bash
php artisan vendor:publish --provider="SevenSpan\WhatsApp\Providers\WhatsAppServiceProvider" --tag="config"
 php
use WhatsApp;

$whatsAppBussnessAccountId = "111111111111111"; // Your bussness account id (waba_id)(Required)
$accessToken = ""; // Access Token of the user (Required)

$response = WhatsApp::getPhoneNumbers(string $WhatsAppBusinessAccountId = '', string $accessToken = '')

#You will get output like this:
array:2 [
  "data" => array:1 [
    0 => array:5 [
      "verified_name" => "Test"
      "code_verification_status" => "NOT_VERIFIED"
      "display_phone_number" => "+1 123-123-1234"
      "quality_rating" => "GREEN"
      "id" => "123456789012345"
    ]
  ]
  "paging" => array:1 [
    "cursors" => array:2 [
      "before" => "QVFIUlpVY3FxaW5ZAncElreTlWM0VqU0xIcUZADYTNac2ppUXpFeDEzbmNPMXVfYlZABSVJVaTZAmM0FDWWVYeEFlUW9BTHlSZAFBYbGUyZAVhXZAVBReDF1OENn"
      "after" => "QVFIUlpVY3FxaW5PZAncElreTlWM0VqU0xIcUZADYTNac2ppUXpFeDEzbmNPMXVfYlZABSVJVaTZAmM0FDWWVYeEFlUW9BTHlSZAFBYbGUyZAVhXZAVBReDF1OENn"
    ]
  ]
]