1. Go to this page and download the library: Download imamnc/efihub-client 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 Efihub\Facades\Efihub;
use Illuminate\Http\Request;
// Text generation with optional file attachment(s)
$text = Efihub::ai()->text(
model: 'gpt-4o',
prompt: 'Ringkas dokumen berikut dalam 5 poin.',
instructions: 'Gunakan bahasa Indonesia yang singkat dan jelas.',
attachments: $request->file('document')
);
// Image generation with optional attachments
$image = Efihub::ai()->image(
model: 'flux',
prompt: 'Buat ilustrasi landing page untuk brand furniture modern',
instructions: 'Gunakan palet netral premium.',
attachments: [
$request->file('reference1'),
$request->file('reference2'),
],
options: [
'ratio' => 'landscape',
'quality' => 'high',
]
);
// Single uploaded file
Efihub::ai()->text('gpt-4o', 'Review this file', null, $request->file('file'));
// Multiple uploaded files
Efihub::ai()->image('flux', 'Generate based on these inputs', null, [
$request->file('img1'),
$request->file('img2'),
]);
// File path and raw content specs are also accepted by the underlying multipart client
Efihub::ai()->text('gpt-4o', 'Analyze this PDF', null, [
'file' => storage_path('app/docs/report.pdf'),
]);
use Efihub\Facades\Efihub;
// List all registered agents
$agents = Efihub::whatsapp()->agents();
// returns: [ ['code' => 'AGENT1', ...], ... ]
// Get QR code image (base64 PNG) to display for scanning
$qr = Efihub::whatsapp()->agentQR('AGENT1');
// returns: 'data:image/png;base64,...' or null
// Check connection status
$status = Efihub::whatsapp()->agentStatus('AGENT1');
// returns: 'connected' | 'disconnected' | null
// Start a WhatsApp agent session
$started = Efihub::whatsapp()->agentStart('AGENT1');
if ($started) {
// session started successfully
}
// Restart a WhatsApp agent session
$restarted = Efihub::whatsapp()->agentRestart('AGENT1');
if ($restarted) {
// session restarted successfully
}
// Terminate a WhatsApp agent session
$terminated = Efihub::whatsapp()->agentTerminate('AGENT1');
if ($terminated) {
// session terminated successfully
}
// Validate a phone number before sending
$valid = Efihub::whatsapp()->checkPhoneNumber('AGENT1', '628109998877');
if (!$valid) {
// number is not on WhatsApp
}
use Efihub\Facades\Efihub;
// Send to a single recipient
$ok = Efihub::whatsapp()->sendMessage(
sender: 'AGENT1',
to: '+628109998877',
message: 'Halo! Tes WhatsApp.'
);
// Send to a group
$ok = Efihub::whatsapp()->sendGroupMessage(
sender: 'AGENT1',
to: 'group-abc123', // group identifier
message: 'Hello World!'
);
if (!$ok) {
// log or retry
}
// Single file by path
$ok = Efihub::whatsapp()->sendAttachment(
sender: 'AGENT1',
to: '+628109998877',
message: 'Berikut invoice kamu',
attachment: storage_path('app/invoices/jan.pdf'),
);
// Raw contents with custom filename & MIME type
$ok = Efihub::whatsapp()->sendAttachment(
sender: 'AGENT1',
to: '+628109998877',
message: 'Report CSV',
attachment: [
'contents' => file_get_contents(storage_path('app/tmp/report.csv')),
'filename' => 'report.csv',
'headers' => ['Content-Type' => 'text/csv'],
],
);
// Multiple files to a group
$ok = Efihub::whatsapp()->sendGroupAttachment(
sender: 'AGENT1',
to: 'group-abc123',
message: 'Semua dokumen',
attachment: [
storage_path('app/docs/a.pdf'),
storage_path('app/docs/b.pdf'),
],
);
// Text message
Efihub::whatsapp()->sendMessage(
sender: 'AGENT1',
to: '+628109998877',
message: 'Your order has been shipped.',
ref_id: 'order-9988',
ref_url: 'https://yourapp.com/orders/9988',
);
// Text message to a group
Efihub::whatsapp()->sendGroupMessage(
sender: 'AGENT1',
to: 'group-abc123',
message: 'Bulk shipment processed.',
ref_id: 'batch-42',
ref_url: 'https://yourapp.com/batches/42',
);
// Attachment to a single recipient
Efihub::whatsapp()->sendAttachment(
sender: 'AGENT1',
to: '+628109998877',
message: 'Berikut invoice kamu.',
attachment: storage_path('app/invoices/jan.pdf'),
ref_id: 'invoice-101',
ref_url: 'https://yourapp.com/invoices/101',
);
// Attachment to a group
Efihub::whatsapp()->sendGroupAttachment(
sender: 'AGENT1',
to: 'group-abc123',
message: 'Laporan bulanan.',
attachment: storage_path('app/reports/jan.pdf'),
ref_id: 'report-jan',
ref_url: 'https://yourapp.com/reports/jan',
);
use Efihub\Facades\Efihub;
// Retrieve recent messages for an agent and phone number
$messages = Efihub::whatsapp()->getMessages(
agentCode: 'AGENT1',
phone: '+628109998877',
limit: 10 // optional, defaults to 10
);
if (!empty($messages)) {
foreach ($messages as $msg) {
echo "From: {$msg['from']}, Message: {$msg['message']}";
}
} else {
// No messages or request failed
}
// Download media attachment from a specific message
$media = Efihub::whatsapp()->downloadMedia(
agentCode: 'AGENT1',
phone: '+628109998877',
messageId: 'msg_abc123'
);
if ($media) {
// $media contains media URL and metadata
echo "Media URL: {$media->url}";
} else {
// Media download failed
}