1. Go to this page and download the library: Download 42dx/whatsapp-laravel-sdk 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/ */
// Get only context payload items for reply messages
$replyContext = $message->getPayloadType(ContextType::REPLY);
// Get all payload items except reaction data
$withoutReactions = $message->getPayloadWithoutType(MessageType::REACTION);
// config/whatsapp.php
'database' => [
'messageable_phone_column' => 'phone', // column name for the phone number
'skip_migrations' => false, // set true to disable package-loaded migrations
'table_name' => 'whatsapp_messages',
'users_table' => 'users', // table to alter
'users_table_pk' => 'id', // primary key of the users table
'messageable_id_column' => 'user_id', // FK column on whatsapp_messages
'user_model' => App\Models\User::class, // model used for lookups
],
use The42dx\Whatsapp\Enums\{MessageComponent, MessageType};
use The42dx\Whatsapp\Models\Traits\CanSendWhatsappMsg;
class User extends Authenticatable
{
use CanSendWhatsappMsg;
}
$phoneColumn = config('whatsapp.database.messageable_phone_column', 'phone');
$user = User::where($phoneColumn, '+1234567890')->first();
// Send a text message
$user->sendWhatsappMsg(MessageType::TEXT, 'Hello from the SDK!');
// Send a template message
$user->sendWhatsappMsg(MessageType::TEMPLATE, [
'name' => 'hello_world',
'lang' => 'en_US',
]);
// React to a message
$user->sendWhatsappMsg(MessageType::REACTION, '👍', $originalMessage);
use The42dx\Whatsapp\Factories\WhatsappApiMessage;
use The42dx\Whatsapp\Services\WhatsappService;
public function __construct(
protected WhatsappService $whatsapp,
) {}
public function send(): void
{
$message = WhatsappApiMessage::compose('+1234567890')
->with(text: 'Hello from the SDK!');
$response = $this->whatsapp->send($message);
}
$whatsapp = app(WhatsappService::class);
$message = WhatsappApiMessage::make('+1234567890')
->withText('Hello from the SDK!');
$response = $whatsapp->send($message, $user);