How to end or reject a 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
To end an active call, use the hangUp method, and to reject an incoming call, use the reject method. Both call the REST API, and the connection reports that the call has ended: the state changes to idle, and the end-call event arrives.
// Ending an active call
try {
await client.hangUp();
console.log('Call ended successfully.');
} catch (error) {
console.error('Error ending the call:', error);
}
// Rejecting an incoming call
try {
await client.reject();
console.log('Call rejected.');
} catch (error) {
console.error('Error rejecting the call:', error);
}
Return the interface to its initial state on the end-call event, not right after calling the method: a call can end without your participation. What this event contains is described in the Handling call states section.
The library turns off audio transmission by itself when the call ends — you do not need to call stopAudioBridge().
When calls are no longer needed at all, call calls.close(): the method stops audio transmission and closes the connection.
calls.close();