Make a Call

This guide covers how to make a call with the Vonage Client SDK. Before you begin, make sure you added the SDK to your app and (Android, iOS, JS).

NOTE: On iOS it is expected that you use CallKit for incoming and outgoing calls. Please follow the Outbound Calls Using iOS CallKit blog post.

Making a Call

The serverCall method allows you to initiate a voice call using the feature rich Voice API. When this method is called, the answer_url webhook that is configured for your Vonage Application will execute. That defines the logic and capabilities of the call.

// After creating a session
client.serverCall({to:phoneNumberOrUsername})
    .then(callId => {
        console.log("Id of created call: ", callId);
    })
    .catch(error => {
        console.error("Error making call: ", error);
    });

Custom Data

Including your own custom data allows you to pass context, in a key-value format, to your answer_url webhook server. If you supply a value with the to key, it will populate the top level to in the query you make to your webhook server. Other data will be under the custom_data object.

// After creating a session
client.serverCall({to:phoneNumberOrUsername, device_name: "Alice app"})
    .then(callId => {
        console.log("Id of created call: ", callId);
    })
    .catch(error => {
        console.error("Error making call: ", error);
    });

The data will be available on the request's query made to your answer_url webhook server:

{
  "to": "447000000000",
  "from_user": "Alice",
  "conversation_uuid": "CON-8dd32088-66be-42ae-b0af-c9e12ca588ed",
  "uuid": "54c255ca-9c1c-4ecd-b175-a1d022dc7b07",
  "custom_data": {
      "to": "447000000000",
      "device_name": "Alice app"
    }
}

Listen For Call Events

To see updates on the state of a call, for example, to know if the other member answered or hung up the call, you should listen to leg status events.

To see updates on the status of the call:

// After creating a session
client.on("legStatusUpdate", (callId, legId, status) => {
    console.log({callId, legId, status});
});

client.on("callInvite", (callId, from, channelType) => {
    // Answer / Reject Call
    console.log({callId, from, channelType});
});

client.on("callHangup", (callId, callQuality, reason) => {
    console.log(`Call ${callId} has hung up, callQuality:${callQuality}, reason:${reason}`);
});

client.on("sessionError", (error) => {
    console.error({error});
});

Reference