Files
od8n_homepage/public/widget/custom/brandize.js
Oliver d20d5706aa fix
2025-07-29 11:58:14 -03:00

49 lines
1.1 KiB
JavaScript

console.log('INIT ELEVENLABS')
import { Conversation } from 'https://cdn.skypack.dev/@elevenlabs/client';
let conversation = null;
console.log("INIT")
document.addEventListener('JSsucks', () => {
console.log("JSsucks")
const callBtn = document.getElementById('callBtn');
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 {
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);
}
})
});