Minimal SDK to Evolution API | PHP
This document provides a simple guide on how to use the EvolutionSDK PHP SDK to interact with the Evolution API.
To use the EvolutionSDK, you need to include it in your PHP project. You can do this via Composer:
bashcomposer require evolution-sdk/sdk
First, you need to initialize the SDK by providing the required configurations.
php<?php use EvolutionSDK\SDK; use EvolutionSDK\util\Config;
// Include Composer's autoloader require_once 'vendor/autoload.php';
// Initialize SDK with configuration $config = new Config('YOUR_API_KEY', 'https://api.example.com'); $sdk = new SDK($config);
You can create a new instance using the create
method.
php$instanceName = 'example_instance'; $qrcode = true; // Optional $response = $sdk->create($instanceName, $qrcode); print_r($response);
Send a message to a specific number on WhatsApp.
php$instance = 'example_instance'; $number = '551234567890'; // WhatsApp number $message = 'Hello, this is a test message.'; $options = []; // Optional $response = $sdk->sendMessage($instance, $number, $message, $options); print_r($response);
Connect to a specific instance by generating a QR code.
php$instance = 'example_instance'; $response = $sdk->connect($instance); print_r($response);
Check the status of a specific instance.
php$instance = 'example_instance'; $response = $sdk->instanceStatus($instance); print_r($response);
In case of errors, exceptions will be thrown. You can catch them using standard PHP try-catch blocks.
phptry { // Perform SDK operations } catch (Exception $e) { echo 'Error: ' . $e->getMessage(); }
Replace 'YOUR_API_KEY'
and 'https://api.example.com'
with your actual API key and API base URL respectively.
This documentation covers basic usage of the EvolutionSDK PHP SDK. For more advanced usage and detailed information, refer to the EvolutionSDK documentation or source code.