How to make an outgoing call#
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
An outgoing call is started with the dial method of the client, and audio transmission is started right after it. By this time, the client and the connection must already be created, see initialization.
dial accepts a phone number, a full chat ID like 79991234567@c.us or an @lid ID like 1062110180230@lid — the latter is needed when you do not have the phone number of the other party.
const phoneNumber = '79991234567'; // the number you are calling
try {
await client.dial(phoneNumber);
await calls.startAudioBridge();
console.log('Call started.');
} catch (error) {
console.error('Error starting the call:', error);
}
The order matters here: call startAudioBridge() only after dial() has completed, otherwise the server responds with the no active call error. For details, see the Audio transmission section; it also describes what to do if the bridge has not been started.
In the vanilla JavaScript example, it looks like this:
startCallButton.addEventListener('click', async () => {
const phoneNumber = document.getElementById('phoneNumber').value;
await client.dial(phoneNumber);
await calls.startAudioBridge();
});
Dialing is indicated by the out-call state, and when the other party answers, the state changes to on-call — see handling call states.
If the number is entered by the user
Parse the number relative to the country instead of simply joining it with the country code: otherwise a long-distance prefix 8 or the British 0 ends up in the dialed address, and the call goes to a different person. In the React example, a separate address model is responsible for this, see React client.