PHP code example of joemunapo / whatsapp-php

1. Go to this page and download the library: Download joemunapo/whatsapp-php 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/ */

    

joemunapo / whatsapp-php example snippets


return [
    'account_model' => \App\Models\Business::class,
    'fields' => [
        'number_id' => 'number_id',
        'token' => 'whatsapp_token',
        'catalog_id' => 'catalog_id',
    ],
];

use Joemunapo\Whatsapp\Whatsapp;

$whatsapp = Whatsapp::useNumberId('your_whatsapp_number_id');

$to = '1234567890';
$content = (object) [
    'type' => 'text',
    'text' => [
        'body' => 'Hello, World!'
    ]
];

$messageId = $whatsapp->sendMessage($to, $content);

$content = (object) [
    'type' => 'interactive',
    'text' => 'Please choose an option:',
    'buttons' => ['Option 1', 'Option 2', 'Option 3']
];

$whatsapp->sendMessage($to, $content);

$mediaType = 'image';
$mediaUrl = 'https://example.com/image.jpg';
$caption = 'Check out this image!';

$whatsapp->sendMedia($to, $mediaType, $mediaUrl, $caption);

$templateName = 'hello_world';
$languageCode = 'en_US';
$components = [
    [
        'type' => 'body',
        'parameters' => [
            ['type' => 'text', 'text' => 'John Doe']
        ]
    ]
];

$whatsapp->sendTemplate($to, $templateName, $languageCode, $components);

$payload = // ... webhook payload from WhatsApp
$message = Whatsapp::handleWebhook($payload);

if ($message) {
    // Process the message
    $message->reply('Thank you for your message!');
}

$mediaId = 'media_id_from_webhook_payload';
$mediaInfo = $whatsapp->getMedia($mediaId);

// The $mediaInfo will contain details about the media, including the URL to download it
$mediaUrl = $mediaInfo['url'];

// You can then download and process the media as needed
bash
composer 
bash
php artisan vendor:publish --provider="Joemunapo\Whatsapp\WhatsappServiceProvider"