like-gold
like-goldโ€ข4mo ago

Web API Function call not working

Hi All, I have been trying to get function calling working in a web client app (no web server). I have a web client app and following the pizza web app example. I am using an ephemeral agent creation and I created a function definition following the OpenAI schema for functions. By looking at the VAPI dashboard, I see that the agent is triggering the function calls correctly, but they are not showing up in the messages event handler in the client. The transcript messages are working correctly. Any suggestions on how to fix or debug this?
8 Replies
Vapi
Vapiโ€ข4mo ago
It sounds like your function calls are being triggered but not received in your client event handler. One common cause is the clientMessages configuration: at assistant creation, you must specify which message types (like "function-call") should be sent to the client. Could you confirm whether your assistant's clientMessages field includes "function-call" as a value? This is required for function call events to be delivered to your web client (see docs, pizza example). If you can share your assistant creation/config snippet, I can help review it for issues. Sources: - Vapi Web SDK documentation - Pizza Website Example โ€“ Handle function call events
โคต๏ธ Mention @Vapi Support Bot for follow-ups ๐Ÿฅ
Vapi
Vapiโ€ข4mo ago
It sounds like your function calls are being triggered but not received in your client event handler. One common cause is the clientMessages configuration: at assistant creation, you must specify which message types (like "function-call") should be sent to the client. Could you confirm whether your assistant's clientMessages field includes "function-call" as a value? This is required for function call events to be delivered to your web client (see docs, pizza example). If you can share your assistant creation/config snippet, I can help review it for issues. Sources: - Vapi Web SDK documentation - Pizza Website Example โ€“ Handle function call events
โคต๏ธ Mention @Vapi Support Bot for follow-ups ๐Ÿฅ
stormy-gold
stormy-goldโ€ข4mo ago
To help track down this issue, could you share one or two: - The call ID - When exactly this happened (the timestamp) - What response you expected to get - What response you actually got instead
This would really help us figure out what went wrong!
Vapi
Vapiโ€ข4mo ago
To help resolve this:
Could you please confirm if your assistant's clientMessages field includes "function-call" as a value in its configuration? This is required for function call events to be delivered to your web client (see docs). Sources: - Vapi Web SDK documentation - Pizza Website Example โ€“ Handle function call events
like-gold
like-goldOPโ€ข4mo ago
Hi, It is solved ๐Ÿ™‚ The trick was to add "tool-calls" to the list of client-messages. For good measure, I added all possible messages clientMessages: ["conversation-update","function-call","hang","model-output","speech-update", "status-update","transfer-update","transcript","tool-calls","user-interrupted", "voice-input","workflow.node.started"], serverMessages: ["function-call","conversation-update","end-of-call-report","hang", "speech-update","status-update","tool-calls","transfer-destination-request","user-interrupted"], Note that I still do not receive a message called "function-call". Instead I receive a "tool-calls" message.
Shubham Bajaj
Shubham Bajajโ€ข4mo ago
sounds, good.
like-gold
like-goldOPโ€ข4mo ago
Something that is not mentioned in the documentation is how to respond from the web client. For others working on the same problem, this worked for me: // Send response to Vapi server try { await vapiClient.send({ type: "add-message", message: { role: "system", content: JSON.stringify({ results: [{ toolCallId: message.toolCalls[0].id, result: "Successfully executed tool" }] }) } }); console.log('[Vapi] Successfully sent tool-calls response'); } catch (error) { console.error('[Vapi] Error sending tool-calls response:', error); } This worked but let me know if I missed something.
Shubham Bajaj
Shubham Bajajโ€ข4mo ago
Glad the issue was resolved. Please reach out to us if you have any other questions regarding this issue

Did you find this page helpful?