waapi/waapi-php-sdk

The official EAZE WhatsApp PHP SDK

v1.0.1 2023-09-06 16:01 UTC

This package is auto-updated.

Last update: 2024-10-23 14:07:03 UTC


README

Latest Version on Packagist Total Downloads

Introduction

PHP package to easily interact with waapi.app.

Installation

Composer

composer require waapi/waapi-php-sdk

Usage

Initial Setup

use WaAPI\WaAPISdk\WaAPISdk;

$apiToken = 'xxxxxxxxxxxxxxxxxxxxxx';
$sdk = new WaAPISdk($apiToken);

Check if WhatsApp API is available

$isAvailable = $sdk->isApiAvailable();

Create a new instance

$instance = $sdk->createInstance();
$instanceId = $instance->id;

Get an existing instance

$instanceId = 10; //you need to know your instance id at this point
$instance = $sdk->getInstance($instanceId);

Update an existing instance

$instanceId = 10; //you need to know your instance id at this point

//if a subscribed event occurs, this url will be requested with the event data
//can also be null if you do not want to receive webhooks
$webhookUrl = '';
$subscribedEvents = ['', '']; //can also be null or an empty array

$sdk->updateInstance($instanceId, $webhookUrl, $subscribedEvents);

//if you have an instance object, you can also use the following method
$instance = $sdk->getInstance($instanceId);
$instance->update($webhookUrl, $subscribedEvents);

Delete an existing instance

$instanceId = 10; //you need to know your instance id at this point
$sdk->deleteInstance($instanceId);

//if you have an instance object, you can also use the following method to delete this instance
$instance = $sdk->getInstance($instanceId);
$instance->delete();

Get the QR-Code

After creating a new instance, you need to connect your WhatsApp phone number with this instance. With the following code, you are able to receive the current QR-Code.

$instanceId = 10; //you need to know your instance id at this point
$response = $sdk->getInstanceClientQrCode($instanceId);

//if you have an instance object, you can also use the following method to delete this instance
$instance = $sdk->getInstance($instanceId);
$response = $instance->clientQrCode();

// The QR code as a base64 image string (data:image/png;base64,…).
// Set this string in the src attribute of a <img src=““> html tag.
$qrCode = $response->qrCode;

Get the instance status

An instance always has a status.

$instanceId = 10; //you need to know your instance id at this point
$response = $sdk->getInstanceClientStatus($instanceId);

//if you have an instance object, you can also use the following method to delete this instance
$instance = $sdk->getInstance($instanceId);
$response = $instance->clientStatus();

$instanceStatus = $response->instanceStatus;

Get information about an existing instance

$instanceId = 10; //you need to know your instance id at this point
$response = $sdk->getInstanceClientInfo($instanceId);

//if you have an instance object, you can also use the following method to delete this instance
$instance = $sdk->getInstance($instanceId);
$response = $instance->clientInfo();

//your public name of your WhatsApp profile (your name)
$displayName = $response->displayName;

//the connected WhatsApp phone number (your phone number)
$phoneNumber = $response->formattedNumber;

//profile image url of the connected WhatsApp phone number (your profile picture)
$profileUrl = $response->profilePicUrl;

//a unique identifier for your WhatsApp account / profile / phone number
$whatsAppId = $response->contactId;

License

The MIT License (MIT). Please see License File for more information.