-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Description
I've got an 11labs agent that gets stuck in listening mode and stops without any warnings
The code
const conversation = useConversation({
clientTools: { ...setPropertyFiltersFunctions, ...postPropertyFunctions, },
dynamicVariables,
volume: 0.9,
onDebug: (message) => console.log('Debug:', message),
onStatusChange(prop) {
console.log('Status changed:', prop)
},
overrides: {
agent: {
language: locale ? ((locale.includes('-') ? locale.split('-')[0] : locale) as 'en' | 'ro') : 'ro',
},
},
});
const startConversation = useCallback(async () => {
async function start(token: string) {
const str = await conversation.startSession({
onMessage: (message) => {
setMessages((prev) => [...prev, { ...message, id: nanoid() }])
},
// agentId: process.env.AGENT_ID!, // Replace with your agent I
conversationToken: token,
connectionType: 'webrtc', // either "webrtc" or "websocket"
onError(message, context) {
console.log('Error:', message, context)
},
onConnect({ conversationId }) {
console.log('Connected', conversationId)
},
onStatusChange(prop) {
console.log('Status changed:', prop)
},
onAgentToolResponse(message: any) {
console.log('Agent tool response:', message)
},
onDisconnect: () => {
console.log('Disconnected')
},
onModeChange(prop) {
console.log('Mode changed:', prop)
},
// userId: 'YOUR_CUSTOMER_USER_ID' // Optional field for tracking your end user IDs
});
console.log(str)
}
console.log('start conversation', conversationToken)
try {
// Request microphone permission
await navigator.mediaDevices.getUserMedia({ audio: true });
await start(tokenQuery.data.token);
// Start the conversation with your agent
} catch (error) {
console.log('Failed to start conversation:', { error });
if ((error as any).status == 401) {
tokenQuery.refetch().then(_ => start(_.data?.token ?? ''));
}
}
}, [conversation]);
// somewhere else in the code : `await startConversation()`
Metadata
Metadata
Assignees
Labels
No labels