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
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 ๐ฅ
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โข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!
This would really help us figure out what went wrong!
To help resolve this:
Could you please confirm if your assistant's
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 eventslike-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.
sounds, good.
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.
Glad the issue was resolved. Please reach out to us if you have any other questions regarding this issue