### Install Zenziva PHP Client Source: https://github.com/mul14/zenziva.php/blob/master/README.md Install the Zenziva PHP client using Composer. Ensure you have Composer installed and configured. ```bash composer require nasution/zenziva ``` -------------------------------- ### Complete Zenziva Integration Example in PHP Source: https://context7.com/mul14/zenziva.php/llms.txt Demonstrates a comprehensive notification system using the Zenziva SDK, supporting multiple channels (SMS, WhatsApp, Voice) with fallback logic. This class helps manage sending OTPs and general messages with preferred channel prioritization. ```php zenziva = new Zenziva($userkey, $passkey, $options); } public function sendOtp(string $phone, string $otp, string $channel = 'sms'): object { $message = "Your verification code is {$otp}. Valid for 5 minutes. Do not share this code."; return match($channel) { 'sms' => $this->zenziva->sms($phone, $message), 'whatsapp' => $this->zenziva->wa($phone, $message), 'voice' => $this->zenziva->voice($phone, "Your verification code is " . implode(' ', str_split($otp))), default => throw new InvalidArgumentException("Invalid channel: {$channel}") }; } public function sendWithFallback(string $phone, string $message): ?object { // Try WhatsApp first $response = $this->zenziva->wa($phone, $message); if (isset($response->status) && $response->status == 1) { return $response; } // Fallback to SMS $response = $this->zenziva->sms($phone, $message); if (isset($response->status) && $response->status == 1) { return $response; } return null; } } // Usage $notification = new NotificationService('your_userkey', 'your_passkey'); // Send OTP via different channels $otp = strval(random_int(100000, 999999)); $response = $notification->sendOtp('6285551112222', $otp, 'whatsapp'); // Send notification with automatic fallback $response = $notification->sendWithFallback( '6285551112222', 'Your order #12345 has been shipped and will arrive tomorrow.' ); ``` -------------------------------- ### Send OTP via WhatsApp Source: https://context7.com/mul14/zenziva.php/llms.txt Send a One-Time Password (OTP) via WhatsApp. This example generates a random 6-digit OTP and includes it in the WhatsApp message content. ```php // Sending OTP via WhatsApp $zenziva = new Zenziva('your_userkey', 'your_passkey'); $otp = random_int(100000, 999999); $response = $zenziva->wa('6285551112222', "Your OTP code is: {$otp}. Valid for 5 minutes."); ``` -------------------------------- ### Get Zenziva API URL with PHP Source: https://context7.com/mul14/zenziva.php/llms.txt Retrieves the base API URL configured for the Zenziva service. This is helpful for debugging and logging. The URL dynamically changes based on masking or custom domain configurations. ```php url(); // Output: https://gsm.zenziva.net/api // With masking enabled - returns https://masking.zenziva.net/api $zenzivaWithMasking = new Zenziva('your_userkey', 'your_passkey', [ 'masking' => true, ]); echo $zenzivaWithMasking->url(); // Output: https://masking.zenziva.net/api // With custom domain - returns https://your_custom_domain.com/api $zenzivaCustom = new Zenziva('your_userkey', 'your_passkey', [ 'domain' => 'your_custom_domain.com', ]); echo $zenzivaCustom->url(); // Output: https://your_custom_domain.com/api ``` -------------------------------- ### Send Voice Message with Zenziva PHP SDK Source: https://context7.com/mul14/zenziva.php/llms.txt Initiates a voice call to a specified phone number. The message text is converted to speech. Useful for OTP verification, appointment reminders, and delivery notifications. Ensure you have the SDK installed via Composer. ```php voice('08122334455', 'Your verification code is 1 2 3 4 5 6. I repeat, 1 2 3 4 5 6.'); // Check response if (isset($response->status) && $response->status == 1) { echo "Voice call initiated successfully!"; } else { echo "Failed to initiate voice call: " . ($response->text ?? 'Unknown error'); } // Voice message for appointment reminder $response = $zenziva->voice('08122334455', 'This is a reminder that you have a doctor appointment tomorrow at 9 AM at Central Hospital.'); // Voice message for delivery notification $response = $zenziva->voice('08122334455', 'Hello, your package with tracking number A B C 1 2 3 has arrived. Please pick it up at the front desk.'); ``` -------------------------------- ### Initialize Zenziva Client Instance Source: https://context7.com/mul14/zenziva.php/llms.txt Create a new Zenziva client instance. You can initialize it with basic userkey and passkey, or with options for SMS masking, custom SMS domains, or custom WhatsApp centers. ```php true, ]); // Initialize with custom domain for Zenziva SMS Center $zenzivaSmsCenter = new Zenziva('your_userkey', 'your_passkey', [ 'domain' => 'your_custom_domain.com', ]); // Initialize with custom domain and WhatsApp instance ID for Zenziva WhatsApp Center $zenzivaWaCenter = new Zenziva('your_userkey', 'your_passkey', [ 'domain' => 'your_custom_domain.com', 'whatsapp_id' => 'your_whatsapp_instance_id', ]); ``` -------------------------------- ### Basic Zenziva Client Usage (PHP) Source: https://github.com/mul14/zenziva.php/blob/master/README.md Initialize the Zenziva client with your user key and passkey, then send SMS, WhatsApp, or voice messages. Requires 'vendor/autoload.php' to be included. ```php // Regular require 'vendor/autoload.php'; use Nasution\Zenziva\Zenziva; $zenziva = new Zenziva('userkey', 'passkey'); // SMS $zenziva->sms('0812223333', 'Halo'); // WhatsApp $zenziva->wa('6285551111', 'Halo'); // Voice message $zenziva->voice('0812223333', 'Halo'); ``` -------------------------------- ### Zenziva Client with Custom WhatsApp Center (PHP) Source: https://github.com/mul14/zenziva.php/blob/master/README.md Configure the Zenziva client to use a custom domain and WhatsApp ID for WhatsApp messaging services by providing 'domain' and 'whatsapp_id' options. ```php // Zenziva WhatsApp Center $zenziva = new Zenziva('userkey', 'passkey', [ 'domain' => 'domain_name.com', 'whatsapp_id' => 'whatsapp_id', ]); $zenziva->wa('6285551111', 'Halo'); ``` -------------------------------- ### Zenziva Client with Custom SMS Domain (PHP) Source: https://github.com/mul14/zenziva.php/blob/master/README.md Use a custom domain for Zenziva SMS services by providing the 'domain' option during client initialization. This is useful for specific Zenziva SMS center configurations. ```php // Zenziva Sms Center $zenziva = new Zenziva('userkey', 'passkey', [ 'domain' => 'domain_name.com', ]); $zenziva->sms('0812223333', 'Halo'); ``` -------------------------------- ### Send WhatsApp Message via Custom WhatsApp Center Source: https://context7.com/mul14/zenziva.php/llms.txt Send a WhatsApp message using a custom Zenziva WhatsApp Center, specifying a custom domain and WhatsApp instance ID. This allows for more control over your WhatsApp messaging. ```php // WhatsApp via Zenziva WhatsApp Center with custom instance $zenzivaWaCenter = new Zenziva('your_userkey', 'your_passkey', [ 'domain' => 'wa.yourdomain.com', 'whatsapp_id' => 'your_whatsapp_instance_id', ]); $response = $zenzivaWaCenter->wa('6285551112222', 'Your package has been delivered. Thank you for shopping with us!'); ``` -------------------------------- ### Zenziva Client with SMS Masking (PHP) Source: https://github.com/mul14/zenziva.php/blob/master/README.md Configure the Zenziva client to use SMS masking by setting the 'masking' option to true during instantiation. This allows for custom sender IDs. ```php // SMS Masking $zenziva = new Zenziva('userkey', 'passkey', [ 'masking' => true, ]); $zenziva->sms('0812223333', 'Halo'); ``` -------------------------------- ### Send Regular WhatsApp Message Source: https://context7.com/mul14/zenziva.php/llms.txt Send a WhatsApp message to a specified phone number. Ensure the phone number includes the country code. The response indicates success or failure. ```php wa('6285551112222', 'Hello! Your appointment is confirmed for tomorrow at 10:00 AM'); // Check response if (isset($response->status) && $response->status == 1) { echo "WhatsApp message sent successfully!"; } else { echo "Failed to send WhatsApp message: " . ($response->text ?? 'Unknown error'); } ``` -------------------------------- ### Send SMS via Custom Zenziva SMS Center Source: https://context7.com/mul14/zenziva.php/llms.txt Send an SMS message using a custom domain for the Zenziva SMS Center. This is useful if you are using a private or specific Zenziva endpoint. ```php // SMS via custom Zenziva SMS Center $zenzivaSmsCenter = new Zenziva('your_userkey', 'your_passkey', [ 'domain' => 'sms.yourdomain.com', ]); $response = $zenzivaSmsCenter->sms('08122334455', 'Welcome to our service!'); ``` -------------------------------- ### Send SMS Message with Masking Source: https://context7.com/mul14/zenziva.php/llms.txt Send an SMS message where the sender ID is masked, appearing as your brand name. This requires enabling the 'masking' option during client initialization. ```php // SMS with masking (sender ID appears as your brand name) $zenzivaWithMasking = new Zenziva('your_userkey', 'your_passkey', [ 'masking' => true, ]); $response = $zenzivaWithMasking->sms('08122334455', 'Your order #12345 has been shipped'); ``` -------------------------------- ### Send Regular SMS Message Source: https://context7.com/mul14/zenziva.php/llms.txt Send a standard SMS message to a phone number. The response from the Zenziva API will be JSON-decoded. Check the 'status' and 'messageId' in the response. ```php sms('08122334455', 'Hello! Your verification code is 123456'); // Check response if (isset($response->status) && $response->status == 1) { echo "SMS sent successfully!"; echo "Message ID: " . $response->messageId; } else { echo "Failed to send SMS: " . ($response->text ?? 'Unknown error'); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.