Elastic
04/05/2025, 4:10 PMVapi Support Bot
04/05/2025, 4:12 PMstartConversation()
function, you're using vapi.send()
, but the variable vapi
is never defined. Instead, you should be using vapiInstance.send()
since that's the variable you've defined when initializing the SDK.
Here's how to fix your code:
javascript
function startConversation() {
// Function to start the conversation
vapiInstance.send({
type: "add-message",
message: {
role: "system",
content: "The user has clicked to start a conversation",
},
});
}
This is a common issue when embedding Vapi assistants. According to the [troubleshooting documentation](https://docs.vapi.ai/examples/voice-widget), the vapiSDK.run
function returns a vapiInstance
that should be used to send messages and listen to events.
Also, make sure that:
1. You've replaced the placeholder values for assistant
and apiKey
with your actual Assistant ID and Public API key from the Vapi Dashboard
2. The script is properly loaded before you try to use the vapiInstance
3. Your browser console doesn't show any other errors that might be preventing the assistant from working
The rest of your code looks good! The structure with the vapiSDK.run
function is correct, as it includes the mandatory apiKey
and assistant
parameters, as well as the optional config
parameter.
Is there anything else you'd like me to help you with regarding your Vapi assistant implementation?
Sources:
- [Troubleshooting common issues when embedding Vapi assistant on a website](https://docs.vapi.ai/examples/voice-widget)
- [Explanation of vapiSDK.run function in Vapi](https://docs.vapi.ai/sdks)
- [Explanation of vapi.send function in Vapi](https://docs.vapi.ai/sdk/web)Elastic
04/05/2025, 5:33 PMShubham Bajaj
04/06/2025, 8:47 AMPraveen Nair
04/06/2025, 11:52 AMPraveen Nair
04/06/2025, 11:58 AMElastic
04/06/2025, 12:53 PMElastic
04/06/2025, 12:56 PMElastic
04/06/2025, 1:01 PMElastic
04/06/2025, 1:01 PMPraveen Nair
04/07/2025, 1:20 PMElastic
04/07/2025, 1:36 PMElastic
04/07/2025, 1:38 PMPraveen Nair
04/08/2025, 10:48 PMShubham Bajaj
04/08/2025, 10:49 PMElastic
04/08/2025, 10:59 PMElastic
04/08/2025, 10:59 PMElastic
04/08/2025, 11:01 PMPraveen Nair
04/10/2025, 10:45 PMPraveen Nair
04/10/2025, 10:47 PM