1. Go to this page and download the library: Download chandachewe/whatsapp 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/ */
chandachewe / whatsapp example snippets
use Chandachewe\Whatsapp\Messages\TemplateMessage;
$templateMessage = new TemplateMessage(
'v19.0',
'BUSINESS PHONE NUMBER ID',
'RECIPIENT PHONE NUMBER',
'TOKEN'
);
$response = $templateMessage->template(
'template_name',
'language_code (optional)'
);
echo $response;
Chandachewe\Whatsapp\Messages\TextMessage;
$textMessage = new TextMessage(
'v19.0',
'BUSINESS PHONE NUMBER ID',
'RECIPIENT PHONE NUMBER',
'TOKEN'
);
$response = $textMessage->text(
'You have to check out this amazing messaging package at https://github.com/chandachewe10/whatsapp-api'
);
echo $response;
Chandachewe\Whatsapp\Messages\ListMessage;
$listMessage = new ListMessage(
'v19.0',
'BUSINESS PHONE NUMBER ID',
'RECIPIENT PHONE NUMBER',
'TOKEN'
);
$response = $listMessage->list(
'Header',
'Body Message',
'Footer (Optional)',
[
'button' => 'title on drop down button',
'sections' => [
[
'title' => 'first row title',
'rows' => [
[
'id' => '100993900202',
'title' => 'Your heading',
'description' => 'Your description'
]
],
// You can add another title and row here
...
]
]
]
);
echo $response;
Chandachewe\Whatsapp\Messages\ButtonMessage;
$buttonMessage = new ButtonMessage(
'v19.0',
'BUSINESS PHONE NUMBER ID',
'RECIPIENT PHONE NUMBER',
'TOKEN'
);
$response = $buttonMessage->button(
'Header',
'Body Message',
'Footer (Optional)',
[
'buttons' => [
[
'type' => 'reply',
'reply' => [
'id' => 'unique-postback-id',
'title' => 'your button title'
]
],
// You can add another type and reply here
...
]
],
'text',
''
);
echo $response;
Chandachewe\Whatsapp\Messages\ButtonMessage;
$buttonMessage = new ButtonMessage(
'v19.0',
'BUSINESS PHONE NUMBER ID',
'RECIPIENT PHONE NUMBER',
'TOKEN'
);
$response = $buttonMessage->button(
'Header',
'Body Message',
'Footer (Optional)',
[
'buttons' => [
[
'type' => 'reply',
'reply' => [
'id' => 'unique-postback-id',
'title' => 'your button title'
]
],
// You can add another type and reply here
...
]
],
'image', // note that we have replaced text with image
'https://path_to_your_image' // note that we have added the image link
);
echo $response;
Chandachewe\Whatsapp\Messages\ButtonMessage;
$buttonMessage = new ButtonMessage(
'v19.0',
'BUSINESS PHONE NUMBER ID',
'RECIPIENT PHONE NUMBER',
'TOKEN'
);
$response = $buttonMessage->button(
'Header',
'Body Message',
'Footer (Optional)',
[
'buttons' => [
[
'type' => 'reply',
'reply' => [
'id' => 'unique-postback-id',
'title' => 'your button title'
]
],
// You can add another type and reply here
...
]
],
'document', // note that we have replaced text with document
'https://path_to_your_document' // note that we have added the document link
);
echo $response;
Chandachewe\Whatsapp\Messages\ButtonMessage;
$buttonMessage = new ButtonMessage(
'v19.0',
'BUSINESS PHONE NUMBER ID',
'RECIPIENT PHONE NUMBER',
'TOKEN'
);
$response = $buttonMessage->button(
'Header',
'Body Message',
'Footer (Optional)',
[
'buttons' => [
[
'type' => 'reply',
'reply' => [
'id' => 'unique-postback-id',
'title' => 'your button title'
]
],
// You can add another type and reply here
...
]
],
'video', // note that we have replaced text with video
'https://path_to_your_video' // note that we have added the video link
);
echo $response;