Call States and Lifecycle
call.state exposes the current CallState. Use it to decide which commands are
valid and when serialization (to_json) is allowed.
States
Inbound lifecycle
@sm.on_incoming_callreceivesIncomingCallNotification(addressing only, no media credentials).open_session→process_call(noti)→CallinNEW.- Choose a path:
- Agent answers:
answer()→ media opens → streamcaller/send_audio. - Ambient / pass-through:
connect()after answering to bring in the callee → thenspy/whisper/barge.
- Agent answers:
- Hangup (remote,
close, ordisconnect) →TERMINATED.on_hangupfires.
Outbound lifecycle
Two entry points:
- A. SDK-placed call:
session.make_call(Address.telco(...))→NEW. Thendial(ring_time_seconds=...)→ rings. FalsyCommandResultwithCALL_UNANSWERED/TIMEOUTif no answer. - B. Subscriber-originated call:
@sm.on_outgoing_callfires when the subscriber’s own line dials out (requiresTriggerConditionsBuilder.outbound_call).process_call(noti)→NEW.
On success, stream call.callee.audio_stream() (the dialed party) and send_audio.
Optionally connect() for conference-style flows, then ambient modes.
Handoff constraint
to_json() / from_json() only while CallState.NEW. After media opens, serialization raises CallStateError. See Sessions and Handoff.
