Wapi.js SDK provides a single client utility per phone number basis, this means you can create a client with your Whatsapp Business Account regisytered phone numnber and you whatsapp business account id.

Creating a client

To create a client, you need to provide the following details:

  • Phone number: The phone number of the whatsapp business account
  • Whatsapp Business Account ID: The whatsapp business account id of the whatsapp business account
  • Whatsapp Business Account Token: The whatsapp business account token of the whatsapp business account
Now, to get the above details do checkout our guide on how to setup the whatsapp api to start building your application here

// creating a wapi.js client

import { Client } from '@wapijs/wapi.js'

export const whatsappClient = new Client({
	apiAccessToken: <WHATSAPP_API_ACCESS_TOKEN>,
	businessAccountId: WHATSAPP_BUSINESS_ACCOUNT_ID,
	phoneNumberId: WHATSAPP_PHONE_NUMBER_ID,
	port: 8080, // the port you want your webhook to be exposed on
	webhookEndpoint: '/webhook', // the endpoint where the webhook will be exposed
	webhookSecret: WHATSAPP_WEBHOOK_SECRET // the secret key for the webhook, this would later be added to the whatsapp business account to verify the integrity of the webhook.
})

Initiating the client

To initiate the client, you need to call the initiate method on the client instance. This method ensures that your webhook server is up and running and listening to the incoming event from the whatsapp business platform.

This method must be called at the very end of the application flow logic, which ensures that all the event listeners the application intend to listen to must be attached before initiating the client.

// assuming you have already instantiated the client from the above guide

whatsappClient.initiate()