PHPackages                             dzly/dzly-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. dzly/dzly-api

ActiveLibrary[API Development](/categories/api)

dzly/dzly-api
=============

Laravel package for Dzly API integration - Contacts, Contact Groups, and Messaging

v1.2.0(1mo ago)014↓100%MITPHPPHP ^8.0

Since Dec 25Pushed 1mo agoCompare

[ Source](https://github.com/tocaan/dzly-api)[ Packagist](https://packagist.org/packages/dzly/dzly-api)[ RSS](/packages/dzly-dzly-api/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (5)Versions (5)Used By (0)

Dzly API SDK for PHP
====================

[](#dzly-api-sdk-for-php)

 [![Latest Version](https://camo.githubusercontent.com/47b3e811c2e9db503cb8ed381296cb4309f679a038742202ba598c1b6867dfb4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f647a6c792f647a6c792d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dzly/dzly-api) [![Total Downloads](https://camo.githubusercontent.com/097de534afd2779d56271b86c6683cc7f67023510592426b2587077edc9692a1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f647a6c792f647a6c792d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dzly/dzly-api) [![Build Status](https://camo.githubusercontent.com/17af4350e0e8f4574016854b041265cb4fa35f2878d02f258715d21b988bad5c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f647a6c792f647a6c792d7061636b6167652f74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/dzly/dzly-package/actions) [![License](https://camo.githubusercontent.com/2e738661a247364146769019544ae2b5075f83e286bf448f1ccd89ad6572a7dd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f647a6c792f647a6c792d6170692e7376673f7374796c653d666c61742d737175617265)](LICENSE)

A modern, type-safe PHP SDK for the Dzly WhatsApp Business API. Build powerful messaging integrations with clean, expressive syntax.

✨ Features
----------

[](#-features)

FeatureDescription**Contacts**Create and manage your contact database**Contact Groups**Organize contacts into groups**Messaging**Send text and media messages**Templates**Use pre-approved WhatsApp templates**Canned Replies**Automate responses with triggers**Type Safety**Full DTO support for all operations**Error Handling**Structured `ApiResponse` for all requests**Laravel Ready**Service provider, facade, and config included📋 Requirements
--------------

[](#-requirements)

- PHP 8.1+
- Laravel 10.x / 11.x (optional)
- Guzzle HTTP 7.x

📦 Installation
--------------

[](#-installation)

```
composer require dzly/dzly-api
```

### Laravel Setup

[](#laravel-setup)

Publish the configuration:

```
php artisan vendor:publish --tag=dzly-config
```

Add credentials to `.env`:

```
DZLY_BASE_URL=https://app.dzly.ai
DZLY_API_TOKEN=your-bearer-token
```

🚀 Quick Start
-------------

[](#-quick-start)

### Standalone PHP

[](#standalone-php)

```
use Dzly\Dzly;

$dzly = new Dzly('https://app.dzly.ai', 'your-token');

// List contacts
$response = $dzly->contacts()->list();

if ($response->successful()) {
    foreach ($response->data() as $contact) {
        echo $contact['full_name'] . "\n";
    }
}

// Send a message
$response = $dzly->messages()->send([
    'phone' => '+1234567890',
    'message' => 'Hello from Dzly!',
]);
```

### Laravel Facade

[](#laravel-facade)

```
use Dzly\Facades\Dzly;

$response = Dzly::contacts()->list();
```

### Dependency Injection

[](#dependency-injection)

```
use Dzly\Dzly;

class ContactController
{
    public function __construct(private Dzly $dzly) {}

    public function index()
    {
        return $this->dzly->contacts()->list()->data();
    }
}
```

---

📖 API Reference
---------------

[](#-api-reference)

### ApiResponse

[](#apiresponse)

All API calls return an `ApiResponse` object with consistent methods:

```
$response = $dzly->contacts()->list();

// Status
$response->successful();     // true if 2xx
$response->failed();         // true if error
$response->statusCode();     // HTTP status code
$response->message();        // Response message

// Data Access
$response->data();           // Array of items
$response->id();             // Resource ID (for create/update)
$response->get('key');       // Get specific field
$response->toArray();        // Raw response array

// Pagination
$response->total();          // Total items
$response->currentPage();    // Current page number
$response->lastPage();       // Last page number
$response->perPage();        // Items per page
$response->hasMorePages();   // Has more pages?
$response->nextPageUrl();    // Next page URL
$response->previousPageUrl(); // Previous page URL

// Collection
$response->isEmpty();        // No data?
$response->isNotEmpty();     // Has data?
$response->count();          // Number of items

// Errors
$response->hasErrors();              // Has validation errors?
$response->errors();                 // All errors array
$response->getFieldErrors('phone');  // Errors for specific field
$response->getFirstError('phone');   // First error for field
```

---

👥 Contacts
----------

[](#-contacts)

### List Contacts

[](#list-contacts)

```
$response = $dzly->contacts()->list();

// With pagination
$response = $dzly->contacts()->list([
    'page' => 1,
    'per_page' => 25,
]);

foreach ($response->data() as $contact) {
    echo $contact['first_name'] . ' ' . $contact['last_name'];
}
```

### Create Contact

[](#create-contact)

```
// Using array
$response = $dzly->contacts()->create([
    'first_name' => 'John',
    'last_name' => 'Doe',
    'email' => 'john@example.com',
    'phone' => '+1234567890',
]);

if ($response->successful()) {
    echo "Created contact: " . $response->id();
}

// Using DTO
use Dzly\DataTransferObjects\ContactData;

$response = $dzly->contacts()->create(new ContactData(
    firstName: 'John',
    lastName: 'Doe',
    email: 'john@example.com',
    phone: '+1234567890',
));
```

### Delete Contact

[](#delete-contact)

```
$response = $dzly->contacts()->delete('contact-uuid');

if ($response->successful()) {
    echo $response->message(); // "Contact deleted successfully"
}
```

---

📁 Contact Groups
----------------

[](#-contact-groups)

### List Groups

[](#list-groups)

```
$response = $dzly->contactGroups()->list();
```

### Create Group

[](#create-group)

```
// Using array
$response = $dzly->contactGroups()->create([
    'name' => 'VIP Customers',
]);

// Using DTO
use Dzly\DataTransferObjects\ContactGroupData;

$response = $dzly->contactGroups()->create(new ContactGroupData(
    name: 'VIP Customers',
));
```

### Update Group

[](#update-group)

```
$response = $dzly->contactGroups()->update('group-uuid', [
    'name' => 'Premium Customers',
]);
```

### Delete Group

[](#delete-group)

```
$response = $dzly->contactGroups()->delete('group-uuid');
```

---

💬 Messages
----------

[](#-messages)

### Send Text Message

[](#send-text-message)

```
// Using array
$response = $dzly->messages()->send([
    'phone' => '+1234567890',
    'message' => 'Hello, how are you?',
]);

// Using DTO
use Dzly\DataTransferObjects\MessageData;

$response = $dzly->messages()->send(new MessageData(
    phone: '+1234567890',
    message: 'Hello, how are you?',
));
```

### Send Media Message

[](#send-media-message)

```
// Using array
$response = $dzly->messages()->sendMedia([
    'phone' => '+1234567890',
    'media_type' => 'image',
    'media_url' => 'https://example.com/photo.jpg',
    'caption' => 'Check this out!',
    'file_name' => 'photo.jpg',
]);

// Using DTO
use Dzly\DataTransferObjects\MediaMessageData;

$response = $dzly->messages()->sendMedia(new MediaMessageData(
    phone: '+1234567890',
    mediaType: 'image',
    mediaUrl: 'https://example.com/photo.jpg',
    caption: 'Check this out!',
    fileName: 'photo.jpg',
));
```

### Media Helper Methods

[](#media-helper-methods)

```
// Image
$dzly->messages()->sendImage('+1234567890', 'https://example.com/photo.jpg', 'Caption');

// Video
$dzly->messages()->sendVideo('+1234567890', 'https://example.com/video.mp4', 'Caption');

// Document
$dzly->messages()->sendDocument('+1234567890', 'https://example.com/doc.pdf', 'Invoice', 'invoice.pdf');

// Audio
$dzly->messages()->sendAudio('+1234567890', 'https://example.com/audio.mp3', 'audio.mp3');
```

### Send Template Message

[](#send-template-message)

```
// Simple template
$dzly->messages()->sendTemplateByName(
    phone: '+1234567890',
    templateName: 'welcome_message',
    languageCode: 'en',
);

// With components
$components = [
    [
        'type' => 'body',
        'parameters' => [
            ['type' => 'text', 'text' => 'John Doe'],
        ],
    ],
];

$dzly->messages()->sendTemplateByName(
    phone: '+1234567890',
    templateName: 'order_confirmation',
    languageCode: 'en',
    components: $components,
);
```

---

📋 Templates
-----------

[](#-templates)

### List Templates

[](#list-templates)

```
$response = $dzly->templates()->list();

foreach ($response->data() as $template) {
    echo $template['name'] . ' - ' . $template['status'];
}
```

---

🤖 Canned Replies
----------------

[](#-canned-replies)

### List Canned Replies

[](#list-canned-replies)

```
$response = $dzly->cannedReplies()->list();
```

### Create Canned Reply

[](#create-canned-reply)

```
// Using array
$response = $dzly->cannedReplies()->create([
    'name' => 'About Us',
    'trigger' => 'what do you do?',
    'match_criteria' => 'contains',
    'response_type' => 'text',
    'response' => 'We sell shoes and clothes',
]);

// Using DTO
use Dzly\DataTransferObjects\CannedReplyData;

$response = $dzly->cannedReplies()->create(new CannedReplyData(
    name: 'About Us',
    trigger: 'what do you do?',
    matchCriteria: 'contains',
    responseType: 'text',
    response: 'We sell shoes and clothes',
));
```

### Update Canned Reply

[](#update-canned-reply)

```
$response = $dzly->cannedReplies()->update('reply-uuid', [
    'response' => 'Updated response text',
]);
```

### Delete Canned Reply

[](#delete-canned-reply)

```
$response = $dzly->cannedReplies()->delete('reply-uuid');
```

---

⚠️ Error Handling
-----------------

[](#️-error-handling)

The SDK returns `ApiResponse` for all requests, including errors:

```
$response = $dzly->contacts()->create([
    'phone' => 'invalid-phone',
]);

if ($response->failed()) {
    echo "Error: " . $response->message();
    echo "Status: " . $response->statusCode();

    // Validation errors
    if ($response->hasErrors()) {
        foreach ($response->errors() as $field => $messages) {
            echo "$field: " . implode(', ', $messages);
        }
    }

    // Get specific field error
    $phoneError = $response->getFirstError('phone');
}
```

### Status Codes

[](#status-codes)

CodeDescription200Success400Validation Error401Authentication Error404Not Found500Server Error---

🧪 Testing
---------

[](#-testing)

Run the test suite:

```
composer test
```

Or directly with PHPUnit:

```
./vendor/bin/phpunit
```

### Mocking in Tests

[](#mocking-in-tests)

```
use Dzly\Contracts\HttpClientInterface;
use Dzly\Http\ApiResponse;
use Dzly\Dzly;
use Mockery;

$mockClient = Mockery::mock(HttpClientInterface::class);
$mockClient->shouldReceive('get')
    ->with('/api/contacts', [])
    ->andReturn(ApiResponse::success([
        'data' => [['id' => 1, 'first_name' => 'John']],
        'meta' => ['total' => 1],
    ]));

$dzly = Dzly::withClient($mockClient);
$response = $dzly->contacts()->list();
```

---

📄 License
---------

[](#-license)

The MIT License (MIT). See [LICENSE](LICENSE) for details.

---

 Made with ❤️ by [Dzly](https://dzly.ai)

###  Health Score

37

—

LowBetter than 84% of packages

Maintenance88

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~10 days

Total

4

Last Release

58d ago

PHP version history (2 changes)v1.0.0PHP ^8.1

v1.1.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/22634d946ccae8799787bebcd8ea49cb4df8936e767c8acf972d990e3e0e8b8b?d=identicon)[tocaan](/maintainers/tocaan)

---

Tags

apilaravelmessagingwhatsappcontactsdzly

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dzly-dzly-api/health.svg)

```
[![Health](https://phpackages.com/badges/dzly-dzly-api/health.svg)](https://phpackages.com/packages/dzly-dzly-api)
```

###  Alternatives

[scriptdevelop/whatsapp-manager

Paquete para manejo de WhatsApp Business API en Laravel

762.5k](/packages/scriptdevelop-whatsapp-manager)[missael-anda/laravel-whatsapp

A Whatsapp Business Cloud API wrapper for Laravel.

677.2k](/packages/missael-anda-laravel-whatsapp)[crenspire/laravel-whatsapp

Laravel WhatsApp Business API package

102.1k](/packages/crenspire-laravel-whatsapp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
