PHP code example of asim-altayb / whatsapp-api-laravel
1. Go to this page and download the library: Download asim-altayb/whatsapp-api-laravel 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/ */
asim-altayb / whatsapp-api-laravel example snippets
use AsimAltayb\WhatsAppCloudApi\WhatsAppCloudApi;
// Instantiate the WhatsAppCloudApi super class.
$whatsapp_cloud_api = new WhatsAppCloudApi([
'from_phone_number_id' => 'your-configured-from-phone-number-id',
'access_token' => 'your-facebook-whatsapp-application-token',
]);
$whatsapp_cloud_api->sendTextMessage('96651234567', 'Hey there! I\'m using WhatsApp Cloud API. Visit https://www.AsimAltayb.es');
use AsimAltayb\WhatsAppCloudApi\Message\Media\LinkID;
use AsimAltayb\WhatsAppCloudApi\Message\Media\MediaObjectID;
$document_id = '341476474779872';
$document_name = 'whatsapp-cloud-api-from-id.pdf';
$document_caption = 'WhastApp API Cloud Guide';
// With the Media Object ID of some document upload on the WhatsApp Cloud servers
$media_id = new MediaObjectID($document_id);
$whatsapp_cloud_api->sendDocument('96651234567', $media_id, $document_name, $document_caption);
// Or
$document_link = 'https://link.com/image.png';
$link_id = new LinkID($document_link);
$whatsapp_cloud_api->sendDocument('96651234567', $link_id, $document_name, $document_caption);
$whatsapp_cloud_api->sendTemplate('96651234567', 'hello_world', 'en_US'); // Language is optional
use AsimAltayb\WhatsAppCloudApi\Message\Media\LinkID;
$audio_link = 'https://link.com/file.ogg';
$link_id = new LinkID($audio_link);
$whatsapp_cloud_api->sendAudio('96651234567', $link_id);
use AsimAltayb\WhatsAppCloudApi\Message\Media\LinkID;
use AsimAltayb\WhatsAppCloudApi\Message\Media\MediaObjectID;
$link_id = new LinkID('http(s)://image-url');
$whatsapp_cloud_api->sendImage('<destination-phone-number>', $link_id);
//or
$media_id = new MediaObjectID('<image-object-id>');
$whatsapp_cloud_api->sendImage('<destination-phone-number>', $media_id);
use AsimAltayb\WhatsAppCloudApi\Message\Media\LinkID;
use AsimAltayb\WhatsAppCloudApi\Message\Media\MediaObjectID;
$link_id = new LinkID('http(s)://video-url');
$whatsapp_cloud_api->sendVideo('<destination-phone-number>', $link_id, '<video-caption>');
//or
$media_id = new MediaObjectID('<image-object-id>');
$whatsapp_cloud_api->sendVideo('<destination-phone-number>', $media_id, '<video-caption>');
use AsimAltayb\WhatsAppCloudApi\Message\Media\LinkID;
use AsimAltayb\WhatsAppCloudApi\Message\Media\MediaObjectID;
$link_id = new LinkID('http(s)://sticker-url');
$whatsapp_cloud_api->sendSticker('<destination-phone-number>', $link_id);
//or
$media_id = new MediaObjectID('<sticker-object-id>');
$whatsapp_cloud_api->sendSticker('<destination-phone-number>', $media_id);
use AsimAltayb\WhatsAppCloudApi\Message\Contact\ContactName;
use AsimAltayb\WhatsAppCloudApi\Message\Contact\Phone;
use AsimAltayb\WhatsAppCloudApi\Message\Contact\PhoneType;
$name = new ContactName('Adams', 'Smith');
$phone = new Phone('34676204577', PhoneType::CELL());
$whatsapp_cloud_api->sendContact('<destination-phone-number>', $name, $phone);
use AsimAltayb\WhatsAppCloudApi\Message\OptionsList\Row;
use AsimAltayb\WhatsAppCloudApi\Message\OptionsList\Section;
use AsimAltayb\WhatsAppCloudApi\Message\OptionsList\Action;
$rows = [
new Row('1', '⭐️', "Experience wasn't good enough"),
new Row('2', '⭐⭐️', "Experience could be better"),
new Row('3', '⭐⭐⭐️', "Experience was ok"),
new Row('4', '⭐⭐️⭐⭐', "Experience was good"),
new Row('5', '⭐⭐️⭐⭐⭐️', "Experience was excellent"),
];
$sections = [new Section('Stars', $rows)];
$action = new Action('Submit', $sections);
$whatsapp_cloud_api->sendList(
'<destination-phone-number>',
'Rate your experience',
'Please consider rating your shopping experience in our website',
'Thanks for your time',
$action
);
composer unit-test
composer integration-test
composer dump-autoload
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.