Skip to content

JavaScript WhatsApp API Calls Client Library#

Beta version

The functionality is in beta mode. Features are subject to change and may also work unstably. There may be additional charges for functionality in the future.
You can request access to the functionality via GREEN-API support

The JavaScript WhatsApp API Calls Client library allows you to receive and make WhatsApp voice calls from JavaScript and TypeScript applications via the GREEN-API service API. Signaling messages are sent over WebSocket, and audio is sent over WebRTC, so calls work directly in the browser without installing additional software. To use the library, get the API token and the instance ID in the console.

What the library consists of#

  • GreenApiVoipClient — a client for the REST call management methods: start, accept, reject and end a call. The credentials are passed to the client constructor.
  • CallsConnection — the object returned by the connectCalls() method. It establishes a WebSocket connection to receive call state events and incoming call notifications. The call audio stream is transmitted separately over WebRTC.

Advantages of WebRTC:

  • Available in browsers
  • Low latency (fractions of a second), sub-second latency
  • Congestion control
  • Mandatory encryption

Authorization in the console#

To make and receive calls, the instance must be authorized. To authorize the instance, go to the console and scan the QR code with the WhatsApp application. The library handles calls only and does not take part in instance authorization.

Ready-made client based on this library#

The repository contains a working softphone built with React. It is the reference implementation to start with: everything described in this section is applied there in working form.

  • React client — what it can do, how to run it and how it is built
  • voip.green-api.com — a deployed example that you can open in a browser without installing anything

How to build your own client#

The sections below walk through the integration step by step — from setting up the environment to handling each event.

Improve our examples by adding user interface elements, error handling and any other custom logic required to build your own service.

Other examples#

Documentation#

Third-party products#

The library itself has no runtime dependencies. The React client from the examples uses React, Redux Toolkit, React Router, Ant Design, MUI icons and libphonenumber-js.

License#

Licensed under the MIT terms.