Skip to content

How to handle incoming notifications#


Before adding the green-api package, you need to install composer (php dependency manager).

composer require green-api/whatsapp-api-client-php


require './vendor/autoload.php';


You may see the full example at: receiveNotification.php

How to initialize an object#

$greenApi = new GreenApiClient( ID_INSTANCE, API_TOKEN_INSTANCE );
Please note that keys can be obtained from environment variables:
require './vendor/autoload.php';

define( "ID_INSTANCE", getenv("ID_INSTANCE" ));

Receiving incoming messages by HTTP API#

The general concept of receiving data in the Green API is described here To start receiving messages by the HTTP API, you need to execute the library method:


onEvent - your method which should contain parameters:

Parameter Description
typewebhook received message type (string)
body message body (json)

Message body types and formats here

This method will be called when an incoming message is received. Next, process messages according to the business logic of your system.

Running index.php#

php -S localhost:8080

The full list of examples#

Description Module
Example of sending text sendTextMessage.php
Example of sending a picture by URL sendPictureByLink.php
Example of sending a picture by uploading from the disk sendPictureByUpload.php
Example of a group creation and sending a message to the group createGroupAndSendMessage.php
Example of incoming webhooks receiving receiveNotification.php