pub struct TwilioCall {
pub from_twilio: Sender<String>,
pub to_twilio: Receiver<String>,
/* private fields */
}Expand description
A live phone call attached to a session — the telephone counterpart of
Talk::talk.
attach wires the session’s pump to a pair of
text-frame channels speaking the Media Streams protocol. The caller owns
the WebSocket: forward every text message Twilio delivers into
from_twilio, and forward every message from
to_twilio back over the socket.
// `ignore`: `ws` is the application's Twilio WebSocket (see examples/telephony).
let session = Live::builder()
.instruction("You are the front desk. Answer the call.")
.greeting("Greet the caller.")
.connect_from_env().await?;
let mut call = TwilioCall::attach(&session);
loop {
tokio::select! {
Some(msg) = ws.recv() => call.from_twilio.send(msg.into_text()?).await?,
Some(out) = call.to_twilio.recv() => ws.send(Message::Text(out)).await?,
else => break,
}
}Fields§
§from_twilio: Sender<String>Feed Twilio’s inbound WebSocket text frames here.
to_twilio: Receiver<String>Text frames to send back to Twilio over the WebSocket.
Implementations§
Source§impl TwilioCall
impl TwilioCall
Sourcepub fn attach(handle: &LiveHandle) -> TwilioCall
pub fn attach(handle: &LiveHandle) -> TwilioCall
Attach a Twilio Media Stream to a connected session, with the
default CallOptions.
Audio starts flowing once Twilio’s start frame arrives (outbound
frames need its stream SID; audio generated before it is dropped —
there is no call to play it into yet). Stream metadata and DTMF
digits are written into session state under the telephony: keys.
Sourcepub fn attach_with(handle: &LiveHandle, options: CallOptions) -> TwilioCall
pub fn attach_with(handle: &LiveHandle, options: CallOptions) -> TwilioCall
Attach a Twilio Media Stream to a connected session.
Beyond attach:
- the caller’s audio passes through a
KeypadGuard, so keypad tones never reach the model and a masked keypad silences the caller; - the agent’s audio goes out in 20 ms frames, as the network expects, with the last partial frame padded once the model pauses;
- on barge-in,
KEY_UNPLAYED_MSrecords how much queued agent audio the caller never heard; - with
CallOptions::recorder, the call is recorded in stereo as heard.
Auto Trait Implementations§
impl Freeze for TwilioCall
impl RefUnwindSafe for TwilioCall
impl Send for TwilioCall
impl Sync for TwilioCall
impl Unpin for TwilioCall
impl UnwindSafe for TwilioCall
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].