PHP code example of emiliopuljiz / api-whatsapp-business
1. Go to this page and download the library: Download emiliopuljiz/api-whatsapp-business 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/ */
emiliopuljiz / api-whatsapp-business example snippets
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use EmilioPuljiz\ApiWhatsappBusiness\Traits\SendWhatsapp;
class SendWhatsAppJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, SendWhatsapp;
protected $phoneNumber;
protected $templateName;
protected $variables;
/**
* Create a new job instance.
*
* @param string $phoneNumber
* @param string $templateName
* @param array $variables
* @return void
*/
public function __construct($phoneNumber, $templateName, $variables)
{
$this->phoneNumber = $phoneNumber;
$this->templateName = $templateName;
$this->variables = $variables;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
// Call the SendWhatsappNotification method from the trait
$this->SendWhatsappNotification(
$this->phoneNumber,
$this->templateName,
$this->variables
);
}
}
use App\Jobs\SendWhatsAppJob;
// Somewhere in your code...
$phoneNumber = '5493624380272';
$templateName = 'new_user';
$variables = ['Emilio', '[email protected]', 'Emilio*1234', 'myapp.com'];
// Call Job to send WhatsApp message
SendWhatsAppJob::dispatch($phoneNumber, $templateName, $variables);