Dans .env de votre projet Laravel :
WA_GATEWAY_URL=https://gateway.example.com
WA_GATEWAY_API_KEY=votre_api_key
Dans config/services.php :
'whatsapp_gateway' => [
'url' => env('WA_GATEWAY_URL'),
'api_key' => env('WA_GATEWAY_API_KEY'),
],
Envoi d'un message :
use Illuminate\Support\Facades\Http;
$gateway = config('services.whatsapp_gateway');
Http::withHeaders(['X-API-Key' => $gateway['api_key']])
->post($gateway['url'] . '/api/messages/text', [
'to' => '+237612345678',
'message' => 'Votre commande est confirmée !',
]);
// Boutons
Http::withHeaders(['X-API-Key' => $gateway['api_key']])
->post($gateway['url'] . '/api/messages/interactive/buttons', [
'to' => '+237612345678',
'body' => 'Que souhaitez-vous faire ?',
'buttons' => [
['id' => 'order', 'title' => 'Commander'],
['id' => 'status', 'title' => 'Mon statut'],
],
]);