LemonGateway.Voice.CallSession (lemon_gateway v0.1.0)

View Source

GenServer that manages a single voice call session.

Handles:

  • WebSocket connections (Twilio + Deepgram)
  • Audio streaming and buffering
  • Speech-to-text processing
  • LLM response generation
  • Text-to-speech synthesis
  • Call state management

Summary

Functions

Returns a specification to start this module under a supervisor.

Ends the call session.

Handles incoming audio from Twilio (mulaw 8kHz).

Handles transcript from Deepgram.

Looks up a call session by call SID.

Registers the Deepgram WebSocket connection.

Registers the Twilio WebSocket connection.

Sends a text response to be spoken.

Starts a new call session.

Returns the via tuple for registry lookup.

Types

t()

@type t() :: %LemonGateway.Voice.CallSession{
  call_sid: String.t(),
  conversation_history: list(),
  current_utterance: String.t(),
  deepgram_ws_pid: pid() | nil,
  from_number: String.t(),
  interruption_detected: boolean(),
  is_processing: boolean(),
  is_speaking: boolean(),
  last_activity_at: DateTime.t(),
  response_queue: list(),
  session_key: String.t(),
  started_at: DateTime.t(),
  to_number: String.t(),
  twilio_ws_pid: pid() | nil
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

end_call(session_pid)

@spec end_call(pid()) :: :ok

Ends the call session.

handle_audio(session_pid, audio_data)

@spec handle_audio(pid(), binary()) :: :ok

Handles incoming audio from Twilio (mulaw 8kHz).

handle_transcript(session_pid, transcript_data)

@spec handle_transcript(pid(), map()) :: :ok

Handles transcript from Deepgram.

lookup(call_sid)

@spec lookup(String.t()) :: pid() | nil

Looks up a call session by call SID.

register_deepgram_ws(session_pid, ws_pid)

@spec register_deepgram_ws(pid(), pid()) :: :ok

Registers the Deepgram WebSocket connection.

register_twilio_ws(session_pid, ws_pid)

@spec register_twilio_ws(pid(), pid()) :: :ok

Registers the Twilio WebSocket connection.

speak(session_pid, text)

@spec speak(pid(), String.t()) :: :ok

Sends a text response to be spoken.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Starts a new call session.

via_tuple(call_sid)

@spec via_tuple(String.t()) :: {:via, Registry, {atom(), String.t()}}

Returns the via tuple for registry lookup.