1. Go to this page and download the library: Download vntrungld/zalo-bot-php-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/ */
use ZaloBot\Enum\ParseMode;
use ZaloBot\Enum\ChatAction;
use ZaloBot\Model\TextStyle;
// Plain text
$bot->sendMessage($chatId, 'Hello!');
// Markdown / HTML
$bot->sendMessage($chatId, '**bold**', ParseMode::Markdown);
// Inline styles: bold + colour over the first 7 characters
$bot->sendMessage($chatId, 'Xin chào bạn', null, [
new TextStyle(start: 0, len: 7, styles: ['b', 'c_db342e']),
]);
// Photo with a caption
$bot->sendPhoto($chatId, 'https://example.com/image.jpg', 'A caption');
// Sticker (IDs from https://stickers.zaloapp.com/)
$bot->sendSticker($chatId, 'sticker_id');
// Voice — 1-on-1 only, must be a public .aac URL
$bot->sendVoice($userId, 'https://example.com/audio.aac');
// Typing indicator
$bot->sendChatAction($chatId, ChatAction::Typing);
foreach ($bot->getUpdates(timeout: 30) as $update) {
if ($update->message->text !== null) {
$bot->sendMessage($update->message->chat->id, 'You said: ' . $update->message->text);
}
}