kirimi / kirimi-php
Official PHP client library for the Kirimi WhatsApp API. Send messages, handle OTP verification, and manage WhatsApp communication with ease.
Requires
- php: >=7.4
- ext-json: *
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpunit/phpunit: ^9.5 || ^10.0
- squizlabs/php_codesniffer: ^3.6
- symfony/var-dumper: ^5.0 || ^6.0
This package is not auto-updated.
Last update: 2025-07-09 13:46:39 UTC
README
Official PHP client library for the Kirimi WhatsApp API. This library provides a simple and efficient way to send WhatsApp messages, handle OTP generation and validation, and manage WhatsApp communication from your PHP applications.
๐ Features
- โ Send WhatsApp messages (text and media)
- โ Generate and validate OTP codes
- โ Support for multiple package types (Free, Lite, Basic, Pro)
- โ PSR-4 autoloading support
- โ Comprehensive error handling
- โ Type hints and modern PHP features
- โ Health check monitoring
- โ Service classes for common use cases
๐ฆ Installation
Install via Composer:
composer require kirimi/kirimi-php
๐ง Requirements
- PHP 7.4 or higher
- Guzzle HTTP client (installed automatically)
- ext-json (usually included in PHP)
๐ง Setup
Get your User Code and Secret Key from the Kirimi Dashboard.
<?php require_once 'vendor/autoload.php'; use Kirimi\KirimiClient; $client = new KirimiClient('YOUR_USER_CODE', 'YOUR_SECRET_KEY');
๐ API Reference
Constructor
$client = new KirimiClient($userCode, $secret, $endpoint = 'https://api.kirimi.id');
Parameters:
$userCode
(string): Your unique user code from Kirimi Dashboard$secret
(string): Your secret key for authentication$endpoint
(string): API endpoint URL (optional)
Send Message
Send WhatsApp messages with optional media support.
// Text message only $result = $client->sendMessage('device_id', '628123456789', 'Hello World!'); // Message with media $result = $client->sendMessage( 'device_id', '628123456789', 'Check out this image!', 'https://example.com/image.jpg' );
Parameters:
$deviceId
(string): Your device ID$receiver
(string): Recipient's phone number (with country code)$message
(string): Message content (max 1200 characters)$mediaUrl
(string|null): URL of media file to send (optional)
Package Support:
- Free: Text only (with watermark)
- Lite/Basic/Pro: Text + Media support
Generate OTP
Generate and send a 6-digit OTP code to a WhatsApp number.
$result = $client->generateOTP('device_id', '628123456789'); print_r($result); // Output: ['phone' => '628123456789', 'message' => 'OTP berhasil dikirim', 'expires_in' => '5 menit']
Parameters:
$deviceId
(string): Your device ID$phone
(string): Phone number to receive OTP
Requirements:
- Package must be Basic or Pro
- Device must be connected and not expired
Validate OTP
Validate a previously sent OTP code.
$result = $client->validateOTP('device_id', '628123456789', '123456'); print_r($result); // Output: ['phone' => '628123456789', 'verified' => true, 'verified_at' => '2024-01-15T10:30:00.000Z']
Parameters:
$deviceId
(string): Your device ID$phone
(string): Phone number that received the OTP$otp
(string): 6-digit OTP code to validate
Notes:
- OTP expires after 5 minutes
- Each OTP can only be used once
Health Check
Check the API service status.
$status = $client->healthCheck(); print_r($status);
๐ฏ Quick Start
Check out the examples/demo.php
file for a complete demonstration of all features:
# Set your credentials as environment variables export KIRIMI_USER_CODE="your_user_code" export KIRIMI_SECRET_KEY="your_secret_key" export KIRIMI_DEVICE_ID="your_device_id" export TEST_PHONE="628123456789" # Run the example composer run example # or php examples/demo.php
๐ก Usage Examples
Basic WhatsApp Messaging
<?php require_once 'vendor/autoload.php'; use Kirimi\KirimiClient; use Kirimi\KirimiException; $client = new KirimiClient('your_user_code', 'your_secret'); try { $result = $client->sendMessage( 'your_device_id', '628123456789', 'Welcome to our service! ๐' ); echo "Message sent successfully: " . json_encode($result) . PHP_EOL; } catch (KirimiException $e) { echo "Failed to send message: " . $e->getMessage() . PHP_EOL; }
OTP Verification Flow
<?php require_once 'vendor/autoload.php'; use Kirimi\Services\OTPService; $otpService = new OTPService('your_user_code', 'your_secret', 'your_device_id'); // Send OTP $result = $otpService->sendVerificationCode('628123456789'); if ($result['success']) { echo "OTP sent successfully!" . PHP_EOL; } else { echo "Failed to send OTP: " . $result['error'] . PHP_EOL; } // Verify OTP (user provides the code) $verifyResult = $otpService->verifyCode('628123456789', '123456'); if ($verifyResult['success'] && $verifyResult['verified']) { echo "OTP verified successfully!" . PHP_EOL; } else { echo "OTP verification failed!" . PHP_EOL; }
Notification Service
<?php require_once 'vendor/autoload.php'; use Kirimi\Services\NotificationService; $notificationService = new NotificationService('your_user_code', 'your_secret', 'your_device_id'); // Send welcome message $result = $notificationService->sendWelcomeMessage('628123456789', 'John Doe'); // Send order confirmation $result = $notificationService->sendOrderConfirmation( '628123456789', 'ORD-001', ['Product A', 'Product B', 'Product C'] ); // Send invoice with document $result = $notificationService->sendInvoiceWithDocument( '628123456789', 'INV-001', 'https://example.com/invoice.pdf' ); // Send appointment reminder $result = $notificationService->sendAppointmentReminder( '628123456789', '2024-01-15', '10:00 AM', 'Main Office' );
Laravel Integration
<?php // In your Laravel service provider or controller use Kirimi\KirimiClient; class WhatsAppService { private KirimiClient $kirimi; public function __construct() { $this->kirimi = new KirimiClient( config('services.kirimi.user_code'), config('services.kirimi.secret') ); } public function sendNotification(string $phone, string $message): bool { try { $this->kirimi->sendMessage( config('services.kirimi.device_id'), $phone, $message ); return true; } catch (KirimiException $e) { Log::error('WhatsApp notification failed: ' . $e->getMessage()); return false; } } } // In config/services.php return [ 'kirimi' => [ 'user_code' => env('KIRIMI_USER_CODE'), 'secret' => env('KIRIMI_SECRET_KEY'), 'device_id' => env('KIRIMI_DEVICE_ID'), ], ];
๐ Package Types & Features
Package | ID | Features | OTP Support |
---|---|---|---|
Free | 1 | Text only (with watermark) | โ |
Lite | 2, 6, 9 | Text + Media | โ |
Basic | 3, 7, 10 | Text + Media + OTP | โ |
Pro | 4, 8, 11 | Text + Media + OTP | โ |
โ ๏ธ Error Handling
The library provides comprehensive error handling using KirimiException
:
use Kirimi\KirimiException; try { $client->sendMessage('device_id', 'invalid_number', 'Hello'); } catch (KirimiException $e) { $errorMessage = $e->getMessage(); if (strpos($errorMessage, 'Parameter tidak lengkap') !== false) { echo 'Missing required parameters'; } elseif (strpos($errorMessage, 'device tidak terhubung') !== false) { echo 'Device is not connected'; } elseif (strpos($errorMessage, 'kuota habis') !== false) { echo 'Quota exceeded'; } // Handle other specific errors... }
๐ Security Notes
- Always keep your secret key secure and never expose it in client-side code
- Use environment variables to store credentials
- Validate phone numbers before sending messages
- Implement rate limiting in your application
// Good practice: use environment variables $client = new KirimiClient( $_ENV['KIRIMI_USER_CODE'], $_ENV['KIRIMI_SECRET_KEY'] );
๐ฆ Rate Limits & Quotas
- Each message sent reduces your device quota (unless unlimited)
- OTP codes expire after 5 minutes
- Device must be in 'connected' status to send messages
- Check your dashboard for current quota and usage statistics
๐งช Testing
Run the test suite:
composer test
Run tests with coverage:
composer test-coverage
Check code style:
composer cs-check
Fix code style:
composer cs-fix
๐ค Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch
- Follow PSR-12 coding standards
- Add tests for new features
- Submit a pull request
๐ License
๐จโ๐ป Author
Ari Padrian - yolkmonday@gmail.com
๐ Additional Resources
Made with โค๏ธ for the PHP and WhatsApp automation community