laravel-chatwoot maintained by alan01777
Laravel Chatwoot
A robust and professional Laravel package for integrating with the Chatwoot API. Built with a clean architecture using Managers, Facades, and DTOs.
Features
- Multi-account Support: Seamlessly manage multiple Chatwoot accounts/connections in a single project.
- Elegant Facade: Use
Chatwoot::getConversations()for a static, user-friendly interface. - Type-safe DTOs: Avoid array-key mistakes with dedicated Data Transfer Objects for Messages, Contacts, Agents, and Teams.
- WhatsApp Templates: Full support for Meta/WhatsApp Business templates via API.
- Error Handling: Automatic exception throwing on 4xx/5xx API responses.
Installation
You can install the package via composer:
composer require alan01777/laravel-chatwoot
You can publish the config file with:
php artisan vendor:publish --tag="chatwoot-config"
Configuration
Add your Chatwoot credentials to your .env file:
CHATWOOT_BASE_URL=https://app.chatwoot.com
CHATWOOT_ACCOUNT_ID=your_account_id
CHATWOOT_API_ACCESS_TOKEN=your_access_token
The configuration file config/chatwoot.php allows you to define multiple accounts:
'accounts' => [
'default' => [
'base_url' => env('CHATWOOT_BASE_URL'),
'account_id' => env('CHATWOOT_ACCOUNT_ID'),
'api_access_token' => env('CHATWOOT_API_ACCESS_TOKEN'),
],
'marketing' => [
'base_url' => '...',
'account_id' => '...',
'api_access_token' => '...',
],
],
Usage
Simple API Calls
use Chatwoot;
// Get all contacts
$contacts = Chatwoot::getContacts();
// Get conversations from the default account
$conversations = Chatwoot::getConversations(['status' => 'open']);
Switching Accounts
// Use a specific account defined in config
$inboxes = Chatwoot::account('marketing')->getInboxes();
Sending Messages with DTOs
use Alan01777\LaravelChatwoot\DTOs\MessageDTO;
$message = new MessageDTO(
content: 'Hello from Laravel!',
private: false
);
Chatwoot::sendMessage($conversationId, $message);
Sending WhatsApp Templates
$message = new MessageDTO(
content: 'Fallback text',
templateParams: [
"name" => "hello_world",
"category" => "MARKETING",
"language" => "en_US",
"processed_params" => [
"body" => ["1" => "Customer Name"]
]
]
);
Chatwoot::sendMessage($conversationId, $message);
Managing Resources (POST/PATCH/DELETE)
use Alan01777\LaravelChatwoot\DTOs\ContactDTO;
// Create a new contact
$contact = Chatwoot::createContact(new ContactDTO(
name: "John Doe",
email: "john@example.com"
));
// Update a conversation status
Chatwoot::updateConversation($conversationId, ['status' => 'resolved']);
License
The MIT License (MIT). Please see License File for more information.