eventData retrieval in a web snippet call
# support
k
VAPI support provided this: // 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 }); so I am using 'call-start' instead of 'callStarted', but using the above eventData shows as undefined in the console.log, and therefore there is no callId inside that. What am I doing wrong?
v
@krthkntrjn It seems like there might be a slight misunderstanding with the event name. The code snippet you received from VAPI support uses
'callStarted'
as the event name. If you're using
'call-start'
instead, that could be the reason why
eventData
is undefined—because the event listener is not correctly set up to listen for the right event. Please ensure that you use the exact event name as provided by VAPI support. Here's the corrected version of your code:
Copy code
javascript
// Listen for the 'callStarted' event
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
});
Make sure to replace
vapiInstance
with the actual instance of your VAPI object. If you continue to face issues, please check the documentation or reach out to support for further assistance.
You can continue this conversation by mentioning me in the message.
k
vapiInstance is the name of my object @User @User Documentation has no such details
s
@krthkntrjn checkout this code on how to use web-snippet https://codesandbox.io/p/sandbox/nedzo-vapi-2s4nnq Do let me knowif you have more questions.
2 Views