How to get callID from https://github.com/VapiAI/h...
# support
m
I'm wanting to get a unique identifier for the call which could be stored within user's web session. My intent is to have the voice agent call a function on my server, and after performing some actions, to in turn return data back to the web application (but is intended only for the particular user's session). I don't see a way to get the callID from this JS implementation. Advice?
v
Hi @misterb0886, I'm an AI assistant for Vapi. I'll analyze available sources and get back to you shortly.
----------------------------- **While I generate an answer, here are some sources that might be helpful**: * [Get Call]() * [Create Phone Call]() * [List Calls]() * [Vapi Web SDK]() -----------------------------
### Answer For implementing the scenario you've described using Vapi, especially with the focus on obtaining a
callID
that can be used for server interactions within a user's web session, the official documentation doesn't provide a direct method to retrieve the
callID
from the HTML script tag implementation provided by the GitHub repository you mentioned. However, based on the discussion in the discord forum [(1)]() , a workaround in such scenarios involves using the Vapi Web SDK [(2)]() or the Vapi Web snippet. While the discussion doesn't directly address retrieving a
callID
, it points towards using the SDK for more complex interactions, including server communications. For server interactions and function calls, consider implementing server-side logic as described in the Server Events documentation [(3)]() . It outlines how to handle function calls, which can be initiated by the voice agent. While the documentation doesn't directly cover fetching a
callID
through the HTML script tag method, using the SDK or server-side logic can provide a pathway to achieve your goal. To have your voice agent call a function on your server and manage interactions based on a
callID
, you might need to integrate more deeply with Vapi's backend APIs or SDK functionalities that allow tracking and managing calls, as mentioned in the examples for creating [(4)]() and listing calls [(5)]() . These APIs return detailed call objects, including a
callID
, that can be stored and referenced throughout a user's session. If integrating directly with the Vapi APIs or SDKs is not viable in your scenario, you might
consider using the approach mentioned in the discord conversation, where after a call is initiated, a List Calls API request is made to fetch the latest call details, including the
callID
. This method, while not ideal due to potential timing issues, can serve as a workaround until a more direct solution is available. Keep in mind that for real-time, user-specific interactions, ensuring secure and accurate mapping between web sessions and call IDs is crucial to maintain privacy and data integrity.
s
@misterb0886 whenever a call is started a callID is generated you need to print all the variable values you will get your answer!
m
my understanding of JS is that printing all variables in a given scope isn't straightforward due to its lexical scope handling. Can you provide more info or an example?
v
Got it. Tagging @User for additional help.
s
@Aayush can you help him out?
a
yeah sure
you can use the events provided by the vapi web sdk
like when the call starts or ends you can listen to those events and get the call related details including the id
you can do something like this:
Copy code
js
const vapi = new Vapi("your-public-key");

// Listen for when the call starts
vapi.on("call-start", () => {
    // This is where you might capture and store the call ID in the user's session
});

// Listen for when the call ends
vapi.on("call-end", () => {
    // Here you can also manage the call ID and associate data return to your web application
});
m
thanks! I'll give try it out