Skip to content

How to receive and process a notification using a server#


npm i @green-api/whatsapp-api-client


There are several ways how to import the library to a project Using standard javascript

const whatsAppClient = require("@green-api/whatsapp-api-client");
Using ES6 javascript
import whatsAppClient from "@green-api/whatsapp-api-client";
Using typescript
import * as whatsAppClient from "@green-api/whatsapp-api-client";

How to initialize an object#

Store your authorization data separate from the code. The library allows you to create a file with an arbitrary name and location in the following format:

You can pass the keys using the below example:
const restAPI = whatsAppClient.restAPI(({
    credentialsPath: "examples\\credentials"


You may see the full example at: ReceiveWebhook.js

How to receive and process a notification using a server#

Only works in node js with express based

import whatsAppClient from '@green-api/whatsapp-api-client'
import express from "express";
import bodyParser from 'body-parser';

(async () => {
    try {

        // Set http url where webhooks will be sent to. 
        // Url must have a public address.
        await restAPI.settings.setSettings({
            webhookUrl: 'MY_HTTP_SERVER:3000/webhooks'

        const app = express();
        const webHookAPI = whatsAppClient.webhookAPI(app, '/webhooks')

        // Subscribe to the webhook event upon a message receipt
        webHookAPI.onIncomingMessageText((data, idInstance, idMessage, sender, typeMessage, textMessage) => {
            console.log(`outgoingMessageStatus data ${data.toString()}`)

        // Start a web server with a public address
        app.listen(3000, async () => {
            console.log(`Started. App listening on port 3000!`)

            const restAPI = whatsAppClient.restAPI(({
                idInstance: MY_ID_INSTANCE,
                apiTokenInstance: MY_API_TOKEN_INSTANCE
            // Send a text message to trigger webhook events
            const response = await restAPI.message.sendMessage("", null, "hello world");

    } catch (error) {

The full list of examples#

Description Module
Example of sending text using Async SendWhatsAppMessageAsync.js
Example of sending text using Callback SendWhatsAppMessageCallback.js
Example of sending a picture by URL SendWhatsAppFileUrl.js
Example of sending a picture by uploading from the disk SendWhatsAppFileUpload.js
Example of receiving an incoming notification with the receiveNotification method ReceiveNotifications.js
Example of receiving a webhook endpoint notification on the local machine SampleReceiveWebhook.js
Example of receiving incoming notifications via webhook service REST API StartReceivingNotifications.js
Example of receiving incoming notifications to a server ReceiveWebhook.js
Example of getting a QR code via HTTP getQRCode.js
Example of getting a QR code via websocket getQRCodeWebsocket.js