Files
od8n_homepage/public/widget/custom/brandize.js
2025-07-28 18:46:28 -03:00

46 lines
1.1 KiB
JavaScript

console.log('INIT ELEVENLABS')
import { Conversation } from 'https://cdn.skypack.dev/@elevenlabs/client';
const callBtn = document.getElementById('callBtn');
let conversation = null;
callBtn.addEventListener('click', async () => {
console.log('Requesting microphone access...');
try {
await navigator.mediaDevices.getUserMedia({ audio: true });
} catch (error) {
console.log('Microphone access denied.');
return;
}
console.log('Connecting to agent...');
try {
const { Conversation } = window.ElevenLabs;
conversation = await Conversation.startSession({
agentId: 'agent_01jx2xm2w4exwvjhbq52js687f',
connectionType: 'websocket', // or "webrtc"
onConnect: () => {
console.log('✅ Connected to AI Agent!');
},
onDisconnect: () => {
console.log('🔌 Disconnected.');
},
onError: (err) => {
console.log(`❌ Error: ${err.message || err}`);
},
onMessage: (msg) => {
console.log('Agent:', msg);
},
});
} catch (err) {
console.log('Failed to start session.');
console.error(err);
}
});