VapiAI/client-sdk-react

Events - not triggered

Closed this issue · 1 comments

Hi team,
I'm currently trying to add the widget to onea of websites using raw HTML, all is working fine but events :)

So currently attaching events this way is not logging anything:

<html>
<body>
<!--StartFragment-->
<script>
--
document.addEventListener('DOMContentLoaded', function() {
const widget = document.querySelector('vapi-widget');
 
// Listen for call events
widget.addEventListener('call-start', function(event) {
console.log('Voice call started');
// Track analytics, update UI, etc.
});
 
widget.addEventListener('call-end', function(event) {
console.log('Voice call ended');
// Update UI, save conversation, etc.
});
 
widget.addEventListener('message', function(event) {
console.log('Message received:', event.detail);
// Process message, update state, etc.
});
 
widget.addEventListener('error', function(event) {
console.error('Widget error:', event.detail);
// Handle errors, show fallback UI, etc.
});
});
</script>

<!--EndFragment-->
</body>
</html>

Please use Events from the @vapi-ai/client-sdk-web library to hook into call lifecycle.