Web API Function call not working
# support
t
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?
v
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](https://docs.vapi.ai/sdk/web#message), [pizza example](https://docs.vapi.ai/examples/pizza-website#handle-function-call-events)). If you can share your assistant creation/config snippet, I can help review it for issues. Sources: - [Vapi Web SDK documentation](https://docs.vapi.ai/sdk/web) - [Pizza Website Example – Handle function call events](https://docs.vapi.ai/examples/pizza-website#handle-function-call-events)
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](https://docs.vapi.ai/sdk/web#message), [pizza example](https://docs.vapi.ai/examples/pizza-website#handle-function-call-events)). If you can share your assistant creation/config snippet, I can help review it for issues. Sources: - [Vapi Web SDK documentation](https://docs.vapi.ai/sdk/web) - [Pizza Website Example – Handle function call events](https://docs.vapi.ai/examples/pizza-website#handle-function-call-events)
k
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!
v
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](https://docs.vapi.ai/sdk/web#message)). Sources: - [Vapi Web SDK documentation](https://docs.vapi.ai/sdk/web#message) - [Pizza Website Example – Handle function call events](https://docs.vapi.ai/examples/pizza-website#handle-function-call-events)
t
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.
s
sounds, good.
t
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.
s
Glad the issue was resolved. Please reach out to us if you have any other questions regarding this issue