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 theconnectCalls()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.
- Setting up the environment and the HTML page
- Installing and importing the library
- How to initialize and authorize the client
- Audio transmission: audio bridge and media streams
- Handling call states
- How to make an outgoing call
- How to handle an incoming call
- How to end or reject a call
Improve our examples by adding user interface elements, error handling and any other custom logic required to build your own service.
Other examples#
- Vanilla JavaScript client — the same calls without a framework, to look at the API on its own
Documentation#
- Calls API — the REST methods and the connection the library is built on: call state, dialing, accepting, rejecting, ending
- GREEN-API service methods documentation — the other instance methods, for example, getting the list of contacts
- Library description (README)
- Step-by-step guide
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.