how to get call id for a call initiated using web ...
# support
k
We are using the web snippet to initiate dynamic calls from our chatbot, code goes something like: vapiInstance = window.vapiSDK.run({ apiKey: apiKey, assistant: assistant, config: buttonConfig, maxDurationSeconds: maxDurationSeconds }); How to get the call id for this instance?
v
@krthkntrjn To retrieve the call ID for the instance you've created with the web snippet, you typically need to listen for an event that provides the call ID once the call has been successfully initiated. If the VAPI SDK you're using follows standard practices, there should be an event or a callback function that is triggered when the call starts, which includes the call ID as part of its data. Here's a general approach you might take:
Copy code
javascript
vapiInstance = window.vapiSDK.run({
  apiKey: apiKey,
  assistant: assistant,
  config: buttonConfig,
  maxDurationSeconds: maxDurationSeconds
});

// Listen for the 'callStarted' event or similar
vapiInstance.on('callStarted', function(eventData) {
  // Access the call ID from the event data
  var callId = eventData.callId;
  console.log('Call ID:', callId);
  // You can now use the callId for your purposes
});
Please replace
'callStarted'
and
eventData.callId
with the actual event name and property provided by the VAPI SDK documentation for obtaining the call ID. If you're unsure about the exact event name or property, please refer to the VAPI SDK documentation or ask support for more info on this.
You can continue this conversation by mentioning me in the message.
k
I figured 'callStarted' needs to be 'call-start', but what is function(eventData), I am not clear about this part? @User
s
@krthkntrjn by default html script tag snippet doesn't returns the call id you have to make change in the code to return the call id from vapi.start method. Current Code:-
Copy code
ts
  const toggleCall = () => {
    buttonStateHandler(button, "loading");
    if (isActiveCall) {
      vapi.stop();
      isActiveCall = false;
    } else {
      if(assistant || assistantOverrides) {
        vapi.start(assistant, assistantOverrides);
      } else {
        console.log('squad ,', squad, assistant, assistantOverrides)
        vapi.start(undefined, undefined, squad)
      }
      isActiveCall = true;
    }
  };
Copy code
ts
const call = vapi.start(assistant, assistantOverrides);
3 Views