Skip to content

Close OpenAI websocket on Twilio call end #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rafalszulejko
Copy link

@rafalszulejko rafalszulejko commented Feb 18, 2025

On Twilio call end, the OpenAI websocket connection isn't closed, leading to an error happening in 30 minutes (maximum permissible OpenAI real-time session length). This also prevents graceful app exit on Ctrl+C.

The proposed change closes the connection on "stop" event from Twilio, received at a call end.

@mahimairaja
Copy link

@rafalszulejko But how can I notify that the call is about to end? Or to hung up

@rafalszulejko
Copy link
Author

When you hang up, a stop event is sent from Twilio.
https://www.twilio.com/docs/voice/media-streams/websocket-messages#stop-message

@mahimairaja
Copy link

Thank you @rafalszulejko

@mahimairaja
Copy link

Do you know how to make similar outbound call @rafalszulejko ?

@rafalszulejko
Copy link
Author

@mahimairaja
Copy link

Thank you! @rafalszulejko

Copy link

@mahimairaja mahimairaja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But to hung up the call we need to send the stop event from the conversation as well right?

@rafalszulejko
Copy link
Author

If you hang up on your phone, stop event will be sent and application can handle it.

If you want to end call on the application side, just close the twilio websocket and the call will end automatically.

@mahimairaja
Copy link

Yes, I am asking in terms of application prospective

To hung the call from AI side we have to have some end token like [end_call] and then after receiving it we need to close the websocket?

@rafalszulejko
Copy link
Author

rafalszulejko commented Mar 6, 2025 via email

@mahimairaja
Copy link

What are you mentioning as function calling here? Anything related to langchain or LLM tool calling?

@rafalszulejko
Copy link
Author

rafalszulejko commented Mar 6, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants