Get Call id from Web SDK
# support
k
Hello, I'm using the web SDK, when starting the call I want to get the Id of the call in the frontend so I can link it with the reporting, any solution please ? Thank you
v
@Karim Hello! To retrieve the call ID in the frontend when starting a call using the web SDK, you would typically initiate the call and then listen for an event or callback that provides the call details, including the call ID. The exact method to do this can vary based on the SDK you're using, but generally, you would use the SDK's method to create a phone call and then handle the response or event that includes the call metadata. Here's a generic example using JavaScript:
Copy code
javascript
// Assuming `sdk` is your initialized web SDK instance

// Function to start a call and get the call ID
function startCallAndGetId() {
  sdk.createPhoneCall({
    // ... your call parameters ...
  }).then(callDetails => {
    // callDetails should contain the call ID and other metadata
    const callId = callDetails.id;
    console.log('Call ID:', callId);
    // You can now link this call ID with your reporting
  }).catch(error => {
    console.error('Error starting the call:', error);
  });
}

// Call the function to start the call
startCallAndGetId();
Please replace
sdk.createPhoneCall
with the actual method provided by the web SDK you are using, and ensure that the parameters passed to the method match the SDK's requirements. The
callDetails
object is expected to contain the call ID, but you should refer to the SDK's documentation to know the exact structure of the response. If you need more specific instructions or if there's a particular part of the SDK you're unsure about, please let me know, and I'll be happy to assist further!
You can continue this conversation by mentioning me in the message.
k
this code isn't working, it's not from Vapi SDK
s
@Karim The response object will contain the call ID. If you have already integrated VAPI, please share the code snippet you are using.
Copy code
ts
const response = vapi.start(assistantId);