Barty-Bart / openai-realtime-api-voice-assistant-V2

OpenAI Realtime API Voice Agent with RAG, Function Calling, and Caller History
39 stars 29 forks source link

sessionID references unknown header 'x-twilio-call-sid' #1

Open illgitthat opened 1 week ago

illgitthat commented 1 week ago

Hi @Barty-Bart thanks for publishing your changes here!

I'm confused on the session management piece that you are using. In particular, where are you getting this header from?

const sessionId = req.headers['x-twilio-call-sid'] ||session_${Date.now()}``

When I run it, it always resolves to Date.now() - the issue with this approach is that Date.now() will be different in /incoming-call vs. /media-stream (different timestamps) so the /media-stream session isn't actually able to reference any of the session info that was previously set.

Barty-Bart commented 1 week ago

hey legend :) Very good point. I may not have refined my V1 code as I built this V2, but to solve this I would just log the incoming twilio call (just ask AI to console.log the inbound twilio call that comes into /incoming-call) and inspect the payload. You can throw the payload into AI and ask it to set the sessionId correctly to the Call SID, as this will be consistent between both webhooks

I would then also log the inbound payload at the /media-stream webhook, as this package of info is different to the incoming-call webhook, so after you log it you should put it back into AI and ask it to appropriately capture the Call SID as well

Hope this helps!