Hi guys
I’m implementing a post-call routine for OpenAI Realtime API SIP calls using the @openai/agents SDK (TypeScript) with openai transport, but I cannot detect when calls end.
I looked around a bit in open source projects and documentation, but I don’t understand why I can’t detect the end of the websocket connection.
My Setup:
import { RealtimeSession, OpenAIRealtimeSIP } from '@openai/agents/realtime'
const session = new RealtimeSession(agent, {
transport: new OpenAIRealtimeSIP(),
...sessionOptions,
})
await session.connect({ apiKey, callId })
What I’ve Tried:
- Listening to multiple event names - None fire when caller hangs up:
const closeEvents = ['close', 'disconnect', 'end', 'finish', 'completed', 'terminated']
for (const eventName of closeEvents) {
session.on(eventName, () => {
console.log(`${eventName} triggered`) // Never logs
})
}
- Intercepting all session events - No events emitted on hangup:
const originalEmit = session.emit?.bind(session)
session.emit = (event, ...args) => {
console.log(`Event emitted: ${event}`) // Nothing on call end
return originalEmit(event, ...args)
}
What I Need: When a caller hangs up, I need to trigger a post-call routine that:
- Extracts conversation transcript, do some custom code like xhr call etc
Thank you for your help!