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.
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.
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> 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].