Download the PHP package multiwa/multiwa-php without Composer
On this page you can find all versions of the php package multiwa/multiwa-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download multiwa/multiwa-php
More information about multiwa/multiwa-php
Files in multiwa/multiwa-php
Package multiwa-php
Short Description Official PHP SDK for MultiWA, the self-hosted WhatsApp API gateway with a built-in team inbox.
License MIT
Homepage https://github.com/ribato22/MultiWA/tree/main/packages/sdk-php#readme
Informations about the package multiwa-php
MultiWA PHP SDK
Official PHP SDK for MultiWA, the self-hosted WhatsApp API gateway with a built-in team inbox.
Requirements
- PHP 8.1 or higher
- Guzzle 7.5 or higher (installed with the SDK)
Installation
To try a change that is not released yet, install from a clone of the MultiWA
repository with a Composer path repository:
Quick start
The constructor also takes timeout (seconds, default 30) and handler, a
Guzzle handler for tests (see Testing your code).
Messages
to is a phone number with country code (6281234567890; +, spaces and
dashes are fine) or a WhatsApp JID (…@s.whatsapp.net, …@c.us, a group
…@g.us). Media goes by public url or by base64.
Every send returns a MultiWA\Models\MessageResult:
| Property | |
|---|---|
success |
false when sending failed; error says why |
messageId |
MultiWA's id of the stored message, the one sendReaction() takes |
conversationId |
|
status |
sent, queued (a worker sends it) or failed |
waMessageId |
WhatsApp's id of the message once WhatsApp accepted it (null while queued); WebSocket message:ack events use this id |
error |
Contacts
Broadcasts
A broadcast is created as a draft and sends only when you start or schedule it. The profile's send limits pace it.
- message: a string is sent as text. For media pass an array:
['type' => 'image', 'url' => 'https://…', 'text' => 'caption', 'mimetype' => 'image/jpeg']; the types aretext,image,video,audioanddocument(a document also takesfilename). - recipients:
['type' => 'tags', 'value' => [tag, …]](contacts with any of the tags),['type' => 'contacts', 'value' => [contact id or phone, …]], or['type' => 'all']. - settings:
delayMinanddelayMax(ms between messages),batchSize,retryFailedandretryAttempts. - A
Broadcasthasid,profileId,name,status(draft,scheduled,running,paused,completed,failed),message,recipients,settings,stats(total,pending,sent,delivered,read,failed) and thescheduledAt,startedAt,completedAt,createdAtandupdatedAtdates.
Profiles
A profile is one WhatsApp number.
Linking a number (QR code)
The QR code is not part of the REST API: it is pushed as the qr:update event of
the WebSocket API.
A Socket.IO client connects to https://your-multiwa-instance.com/ws with the API
key, emits join with the profile id, and shows each event's qrCode (a
data:image/png;base64,… URL) until it is scanned. The event reaches owners and
admins only: a dashboard sign-in of one qualifies, and so does an API key of one
with profiles:write (or no scope list). You can also scan it in the admin
dashboard. Afterwards status() reports connected. A profile that is
already linked answers ['status' => 'already_connected', …].
Webhooks
create() and update() also take headers, extra headers sent with every
delivery (['X-Tenant' => 'acme']).
Calls
$client->calls()is in SDK 1.4.0 and later.
Incoming WhatsApp calls: the follow-up queue, the readiness of answering them in the dashboard, the recordings and the announcement (Calls answered in the dashboard).
Every calls method is in the PHP SDK guide.
An API key acts with its user's role, and a key with a scope list needs the
scopes in API keys.
With Guzzle's cURL handler, the default, the client's timeout covers a whole
download: a long recording may need a larger one. A refused setting throws an
ApiException (409); getResponseBody()['reasons'] says why. Answering is for
people signed in to the dashboard: follow calls with the call.* webhooks, or
the WebSocket call:update event.
Other routes
request() calls any route of the REST API
with the same authentication and error handling, and returns the decoded JSON:
Errors
Everything the SDK throws extends MultiWA\Exceptions\MultiWAException:
| Exception | Thrown for | Adds |
|---|---|---|
MultiWAException |
No response (connection failed, timeout) or a success that is not JSON | |
ApiException |
Any 4xx or 5xx, e.g. 409 PROFILE_DISCONNECTED (sent while the profile is offline) |
getStatusCode(), getErrorCode(), getResponseBody() |
ValidationException |
400, 422 | getErrors(): the validation messages |
AuthenticationException |
401 (bad or missing API key), 403 (not allowed, or not in your organization) | |
NotFoundException |
404 | |
RateLimitException |
429 | getRetryAt() |
The four specific ones extend ApiException. getErrorCode() returns the API's
machine-readable code when it sends one (PROFILE_DISCONNECTED,
DAILY_LIMIT_REACHED, OTP_DELIVERY_FAILED, …), else null. A resource of
another organization, or one that does not exist, usually answers 403: the API
does not reveal which.
A 429 is the send gate protecting the number. Its code says which limit:
getErrorCode() |
Meaning | getRetryAt() |
|---|---|---|
DAILY_LIMIT_REACHED |
The profile's daily cap | When the counter resets |
COLD_DAILY_LIMIT_REACHED |
The cap for messages to chats that have not written to the number within the service window (24 hours by default) | When the counter resets |
COLD_CIRCUIT_OPEN |
Those messages are paused after repeated failed deliveries | When they resume |
REPEAT_SUPPRESSED |
The same text to the same chat moments ago | When it may be sent again |
null |
Too many API requests per minute | null |
Testing your code
Pass a Guzzle handler as the last constructor argument to answer requests without a server:
Development
The tests check every call against the API's route list
(scripts/api-routes.snapshot.json), so run them inside the
MultiWA repository; elsewhere that check is skipped.
License
MIT, see LICENSE.