Download the PHP package imamnc/efihub-client without Composer
On this page you can find all versions of the php package imamnc/efihub-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package efihub-client
EFIHUB PHP/Laravel Client
A modern SDK to integrate with the EFIHUB platform using the OAuth 2.0 Client Credentials flow.
Introduction
EFIHUB client for Laravel/PHP that authenticates using OAuth 2.0 Client Credentials and exposes:
- A lightweight HTTP client (GET/POST/PUT/DELETE) with automatic token caching and retry on 401
- Storage module to upload files and get public URLs
- AI module to generate text and image responses with optional file attachments
- Websocket module to dispatch real-time events to channels
- WhatsApp module to manage agents (list, QR code, status, phone validation) and send messages (single/group) and file attachments
- SSO module to generate authorization URL and fetch user profile after callback
Designed for server-side apps only—do not expose your client secret to browsers.
Table of Contents
- Getting Started
- Installation
- Framework Setup
- Environment Variables
- Authentication
- HTTP Client
- Basic Usage
- Dependency Injection
- Modules
- Storage
- AI
- WebSocket
- SSO
- License & Author
Getting Started
Installation
Install the package via Composer:
Framework Setup
Laravel
Supports Laravel 7 through 13.
Auto-discovery is enabled. Optionally publish the config file:
Lumen 7 (Illuminate 7.30.4)
Register the service provider in bootstrap/app.php:
Enable and load the package config:
Copy the config file manually to config/efihub.php (Lumen does not support vendor:publish).
To use the Facade, enable facades and add an alias:
Environment Variables
Add the following to your .env file:
These map to config/efihub.php keys: client_id, client_secret, token_url, api_base_url.
Authentication
The client uses the OAuth 2.0 Client Credentials flow automatically:
- An access token is fetched from
EFIHUB_TOKEN_URLusing your client credentials. - The token is cached for ~55 minutes; on a
401response, the cache is cleared and the request is retried once. - No manual token management is needed—simply use the Facade or inject the client.
HTTP Client
The base client handles authentication and exposes standard HTTP verbs. Use it directly for any EFIHUB API endpoint, or use the higher-level Modules for specific services.
Basic Usage
Dependency Injection
Modules
All modules are accessed via the Efihub Facade (e.g. Efihub::storage(), Efihub::whatsapp()).
Storage module
Upload files and manage them on the EFIHUB storage service.
Methods
Efihub::storage() returns Efihub\Modules\StorageClient with:
upload(mixed $file, string $path): string|false– uploads a file; returns the public URL orfalseon failure.exists(string $path): bool– checks whether a file exists.size(string $path): int|null– returns file size in bytes, ornullon failure.delete(string $path): bool– deletes a file; returnstrueon success.
upload() accepts a Laravel/Symfony UploadedFile, a string path, or raw file contents. End $path with / to let the server auto-generate the filename.
Usage
Other helpers:
Endpoints
POST /storage/uploadGET /storage/urlGET /storage/sizeGET /storage/existsDELETE /storage/delete
AI module
Generate text or images using EFIHUB AI endpoints with optional file attachments.
Methods
Efihub::ai() returns Efihub\Modules\AIClient with:
text(string $model, string $prompt, ?string $instructions = null, mixed $attachments = []): ?string– generate text with optional attachments.image(string $model, string $prompt, ?string $instructions = null, mixed $attachments = [], ?array $options = []): string|array|null– generate one or more images, optionally with attachments.
Supported attachment formats:
- single
Illuminate\Http\UploadedFileor SymfonyUploadedFile - array of uploaded files for the same field
- existing multipart specs such as string path,
['path' => ...], or['contents' => ...]
Usage
Attachment examples
Endpoints
POST /ai/generate/textPOST /ai/generate/image
WebSocket module
Dispatch real-time events to channels from a server-side listener or job.
Methods
Efihub::socket() returns Efihub\Modules\WebsocketClient with:
dispatch(string $channel, string $event, array $data): bool– broadcasts an event; returnstrueon success.
Usage
Endpoint
POST /websocket/dispatch— payload:{ channel, event, data }
SSO module
Centralized login flow: generate an authorization URL, redirect the user, then exchange the redirect_token for user data.
Methods
Efihub::sso() returns Efihub\Modules\SSOClient with:
login(): string|false– returns the authorization URL orfalseon failure.userData(string $redirectToken): array|false– exchanges the token for user info; returns an array orfalseon failure.
Usage
Step 1 — Redirect the user to EFIHUB login:
Step 2 — Handle the callback and fetch user data:
Endpoints
POST /sso/authorizeGET /sso/user
Security enhancements like
state/noncecan be layered externally; ensure you bind the session before redirecting.
WhatsApp module
Manage WhatsApp agents and send messages (text or with attachments) to individual recipients or groups.
Methods
Efihub::whatsapp() returns Efihub\Modules\WhatsappClient with:
Agent management
| Method | Returns | Description |
|---|---|---|
agents() |
array |
List all registered agents/sessions. Empty array on failure. |
agentQR(string $agentCode) |
string\|null |
QR code as image/png;base64, or null on failure. |
agentStatus(string $agentCode) |
string\|null |
'connected' or 'disconnected', or null on failure. |
agentStart(string $agentCode) |
bool |
Start a WhatsApp agent session. Returns true on success. |
agentRestart(string $agentCode) |
bool |
Restart a WhatsApp agent session. Returns true on success. |
agentTerminate(string $agentCode) |
bool |
Terminate a WhatsApp agent session. Returns true on success. |
checkPhoneNumber(string $agentCode, string $number) |
bool |
true if the number is a valid WhatsApp user. |
Messaging
| Method | Returns | Description |
|---|---|---|
sendMessage(string $sender, string $to, string $message, ?string $ref_id, ?string $ref_url, ?bool $delay = true) |
bool |
Send a text message to a single recipient. |
sendGroupMessage(string $sender, string $to, string $message, ?string $ref_id, ?string $ref_url, ?bool $delay = true) |
bool |
Send a text message to a group. |
sendAttachment(string $sender, string $to, string $message, mixed $attachment, ?string $ref_id, ?string $ref_url, ?bool $delay = true) |
bool |
Send a message with a file attachment to a single recipient. |
sendGroupAttachment(string $sender, string $to, string $message, mixed $attachment, ?string $ref_id, ?string $ref_url, ?bool $delay = true) |
bool |
Send a message with a file attachment to a group. |
getMessages(string $agentCode, string $phone, int $limit = 10) |
array |
Retrieve recent messages for an agent and phone number. |
downloadMedia(string $agentCode, string $phone, string $messageId) |
object\|null |
Download media attachment from a specific message. |
All message methods return true on HTTP success (2xx), false otherwise. The getMessages() method returns an array of messages or empty array on failure.
The WhatsApp client also normalizes phone numbers for phone-based methods such as checkPhoneNumber(), getMessages(), and downloadMedia().
Agent management
Sending messages
Attachments
Supported file spec formats:
| Format | Example |
|---|---|
| Path string | '/path/to/file.pdf' |
| Path array with custom name | ['path' => '/path/to/file.pdf', 'filename' => 'custom.pdf', 'headers' => [...]] |
| Raw contents | ['contents' => $binary, 'filename' => 'name.ext', 'headers' => [...]] |
| Multiple files (array of specs) | ['/path/a.jpg', '/path/b.jpg'] |
Reference metadata
All four send methods accept optional $ref_id and $ref_url parameters to correlate outbound messages with internal entities (orders, tickets, etc.):
Retrieving messages
Error inspection
The helpers only return bool. For full error details, use the base HTTP client directly:
Phone number normalization
All phone-based methods (checkPhoneNumber, sendMessage, sendGroupMessage, sendAttachment, sendGroupAttachment, getMessages, downloadMedia) automatically normalize phone numbers to the international format (62xxxxxxxxxx for Indonesia). You may pass numbers in any common format:
+628109998877→62810999887708109998877→628109998877628109998877→628109998877(unchanged)
Endpoints
| Method | Endpoint |
|---|---|
agents() |
GET /whatsapp/sessions |
agentQR() |
GET /whatsapp/session/qrcode/{agentCode} |
agentStatus() |
GET /whatsapp/session/status/{agentCode} |
agentStart() |
POST /whatsapp/session/start/{agentCode} |
agentRestart() |
POST /whatsapp/session/restart/{agentCode} |
agentTerminate() |
POST /whatsapp/session/terminate/{agentCode} |
checkPhoneNumber() |
GET /whatsapp/user/exists/{agentCode}/{number} |
sendMessage() |
POST /whatsapp/message |
sendGroupMessage() |
POST /whatsapp/message/group |
sendAttachment() |
POST /whatsapp/message/attachment |
sendGroupAttachment() |
POST /whatsapp/message/group/attachment |
getMessages() |
GET /whatsapp/messages/{agentCode}/{phone}/{limit} |
downloadMedia() |
GET /whatsapp/message/download/{agentCode}/{phone}/{messageId} |
Adjust paths if your EFIHUB deployment customizes routing.
License & Author
MIT © Imam Nurcholis. See LICENSE.
- Author: https://github.com/imamnc
- EFIHUB: https://efihub.morefurniture.id
All versions of efihub-client with dependencies
illuminate/support Version ^7.30.4|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/cache Version ^7.30.4|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/http Version ^7.30.4|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
guzzlehttp/guzzle Version ^6.5|^7.0