VoiceResponse

Struct VoiceResponse 

Source
pub struct VoiceResponse { /* private fields */ }
Expand description

TwiML for Voice

Implementations§

Source§

impl VoiceResponse

Source

pub fn new() -> Self

TwiML for Voice

Examples found in repository?
examples/voice_call.rs (line 39)
38fn simple_greeting() {
39    let response = VoiceResponse::new()
40        .say("Hello! Welcome to TwiML Rust.")
41        .say("This is a simple voice response example.")
42        .hangup();
43
44    println!("{}", response.to_xml());
45}
46
47/// Interactive voice response menu
48fn ivr_menu() {
49    let gather = Gather::new()
50        .input(vec!["dtmf".to_string(), "speech".to_string()])
51        .action("https://example.com/handle-input")
52        .method("POST")
53        .timeout(10)
54        .num_digits(1)
55        .add_say(Say::new(
56            "Press 1 for sales, 2 for support, or 3 for billing. You can also say the department name.",
57        ));
58
59    let response = VoiceResponse::new()
60        .say("Welcome to our automated phone system.")
61        .gather(gather)
62        .say("We didn't receive any input.")
63        .redirect("https://example.com/main-menu");
64
65    println!("{}", response.to_xml());
66}
67
68/// Call forwarding to a phone number
69fn call_forwarding() {
70    let dial = Dial::new()
71        .timeout(30)
72        .add_number(DialNumber::new("+15559876543").send_digits("wwww1234"));
73
74    let response = VoiceResponse::new()
75        .say("Please wait while we connect your call.")
76        .dial_with(dial)
77        .say("The call could not be completed. Please try again later.")
78        .hangup();
79
80    println!("{}", response.to_xml());
81}
82
83/// Voicemail recording system
84fn voicemail() {
85    let record = Record::new()
86        .action("https://example.com/handle-recording")
87        .method("POST")
88        .max_length(120)
89        .finish_on_key("#")
90        .transcribe(true)
91        .transcribe_callback("https://example.com/transcription");
92
93    let response = VoiceResponse::new()
94        .say("Please leave a message after the beep. Press the pound key when finished.")
95        .record(record)
96        .say("Thank you for your message. Goodbye!")
97        .hangup();
98
99    println!("{}", response.to_xml());
100}
101
102/// Advanced SSML features
103fn advanced_ssml() {
104    let say = Say::new("Welcome to our service")
105        .voice("Polly.Joanna")
106        .language("en-US")
107        .add_break(Some("medium".to_string()), None)
108        .add_emphasis(Some("strong".to_string()), "Please listen carefully")
109        .add_break(None, Some("1s".to_string()))
110        .add_prosody(
111            Some("high".to_string()),
112            Some("slow".to_string()),
113            None,
114            "This is important information",
115        );
116
117    let response = VoiceResponse::new()
118        .say_with(say)
119        .play("https://example.com/music.mp3")
120        .hangup();
121
122    println!("{}", response.to_xml());
123}
Source

pub fn comment(self, comment: impl Into<String>) -> Self

Comments in

§Arguments
  • comment - XML Comment
Source

pub fn comment_after(self, comment: impl Into<String>) -> Self

Comments after

§Arguments
  • comment - XML Comment
Source

pub fn comment_before(self, comment: impl Into<String>) -> Self

Comments before

§Arguments
  • comment - XML Comment
Source

pub fn connect(self, connect: Connect) -> Self

TwiML Verb

§Arguments
  • connect - Pre-configured Connect object
Source

pub fn dial(self, number: impl Into<String>) -> Self

TwiML Verb

§Arguments
  • number - Phone number to dial
Source

pub fn dial_with_attributes( self, attributes: DialAttributes, number: Option<impl Into<String>>, ) -> Dial

TwiML Verb with attributes

§Arguments
  • attributes - TwiML attributes
  • number - Phone number to dial (optional)
Source

pub fn echo(self) -> Self

TwiML Verb

Source

pub fn enqueue(self, enqueue: Enqueue) -> Self

TwiML Noun

§Arguments
  • enqueue - Pre-configured Enqueue object
Source

pub fn gather(self, gather: Gather) -> Self

TwiML Verb

§Arguments
  • gather - Pre-configured Gather object
Examples found in repository?
examples/voice_call.rs (line 61)
48fn ivr_menu() {
49    let gather = Gather::new()
50        .input(vec!["dtmf".to_string(), "speech".to_string()])
51        .action("https://example.com/handle-input")
52        .method("POST")
53        .timeout(10)
54        .num_digits(1)
55        .add_say(Say::new(
56            "Press 1 for sales, 2 for support, or 3 for billing. You can also say the department name.",
57        ));
58
59    let response = VoiceResponse::new()
60        .say("Welcome to our automated phone system.")
61        .gather(gather)
62        .say("We didn't receive any input.")
63        .redirect("https://example.com/main-menu");
64
65    println!("{}", response.to_xml());
66}
Source

pub fn hangup(self) -> Self

TwiML Verb

Examples found in repository?
examples/voice_call.rs (line 42)
38fn simple_greeting() {
39    let response = VoiceResponse::new()
40        .say("Hello! Welcome to TwiML Rust.")
41        .say("This is a simple voice response example.")
42        .hangup();
43
44    println!("{}", response.to_xml());
45}
46
47/// Interactive voice response menu
48fn ivr_menu() {
49    let gather = Gather::new()
50        .input(vec!["dtmf".to_string(), "speech".to_string()])
51        .action("https://example.com/handle-input")
52        .method("POST")
53        .timeout(10)
54        .num_digits(1)
55        .add_say(Say::new(
56            "Press 1 for sales, 2 for support, or 3 for billing. You can also say the department name.",
57        ));
58
59    let response = VoiceResponse::new()
60        .say("Welcome to our automated phone system.")
61        .gather(gather)
62        .say("We didn't receive any input.")
63        .redirect("https://example.com/main-menu");
64
65    println!("{}", response.to_xml());
66}
67
68/// Call forwarding to a phone number
69fn call_forwarding() {
70    let dial = Dial::new()
71        .timeout(30)
72        .add_number(DialNumber::new("+15559876543").send_digits("wwww1234"));
73
74    let response = VoiceResponse::new()
75        .say("Please wait while we connect your call.")
76        .dial_with(dial)
77        .say("The call could not be completed. Please try again later.")
78        .hangup();
79
80    println!("{}", response.to_xml());
81}
82
83/// Voicemail recording system
84fn voicemail() {
85    let record = Record::new()
86        .action("https://example.com/handle-recording")
87        .method("POST")
88        .max_length(120)
89        .finish_on_key("#")
90        .transcribe(true)
91        .transcribe_callback("https://example.com/transcription");
92
93    let response = VoiceResponse::new()
94        .say("Please leave a message after the beep. Press the pound key when finished.")
95        .record(record)
96        .say("Thank you for your message. Goodbye!")
97        .hangup();
98
99    println!("{}", response.to_xml());
100}
101
102/// Advanced SSML features
103fn advanced_ssml() {
104    let say = Say::new("Welcome to our service")
105        .voice("Polly.Joanna")
106        .language("en-US")
107        .add_break(Some("medium".to_string()), None)
108        .add_emphasis(Some("strong".to_string()), "Please listen carefully")
109        .add_break(None, Some("1s".to_string()))
110        .add_prosody(
111            Some("high".to_string()),
112            Some("slow".to_string()),
113            None,
114            "This is important information",
115        );
116
117    let response = VoiceResponse::new()
118        .say_with(say)
119        .play("https://example.com/music.mp3")
120        .hangup();
121
122    println!("{}", response.to_xml());
123}
Source

pub fn leave(self) -> Self

TwiML Verb

Source

pub fn pause(self, length: Option<u32>) -> Self

TwiML Verb

§Arguments
  • length - Pause length in seconds (optional)
Source

pub fn pay(self, pay: Pay) -> Self

TwiML Verb

§Arguments
  • pay - Pre-configured Pay object
Source

pub fn play(self, url: impl Into<String>) -> Self

TwiML Verb

§Arguments
  • url - Media URL
Examples found in repository?
examples/voice_call.rs (line 119)
103fn advanced_ssml() {
104    let say = Say::new("Welcome to our service")
105        .voice("Polly.Joanna")
106        .language("en-US")
107        .add_break(Some("medium".to_string()), None)
108        .add_emphasis(Some("strong".to_string()), "Please listen carefully")
109        .add_break(None, Some("1s".to_string()))
110        .add_prosody(
111            Some("high".to_string()),
112            Some("slow".to_string()),
113            None,
114            "This is important information",
115        );
116
117    let response = VoiceResponse::new()
118        .say_with(say)
119        .play("https://example.com/music.mp3")
120        .hangup();
121
122    println!("{}", response.to_xml());
123}
Source

pub fn record(self, record: Record) -> Self

TwiML Verb

§Arguments
  • record - Pre-configured Record object
Examples found in repository?
examples/voice_call.rs (line 95)
84fn voicemail() {
85    let record = Record::new()
86        .action("https://example.com/handle-recording")
87        .method("POST")
88        .max_length(120)
89        .finish_on_key("#")
90        .transcribe(true)
91        .transcribe_callback("https://example.com/transcription");
92
93    let response = VoiceResponse::new()
94        .say("Please leave a message after the beep. Press the pound key when finished.")
95        .record(record)
96        .say("Thank you for your message. Goodbye!")
97        .hangup();
98
99    println!("{}", response.to_xml());
100}
Source

pub fn redirect(self, url: impl Into<String>) -> Self

TwiML Verb

§Arguments
  • url - Redirect URL
Examples found in repository?
examples/voice_call.rs (line 63)
48fn ivr_menu() {
49    let gather = Gather::new()
50        .input(vec!["dtmf".to_string(), "speech".to_string()])
51        .action("https://example.com/handle-input")
52        .method("POST")
53        .timeout(10)
54        .num_digits(1)
55        .add_say(Say::new(
56            "Press 1 for sales, 2 for support, or 3 for billing. You can also say the department name.",
57        ));
58
59    let response = VoiceResponse::new()
60        .say("Welcome to our automated phone system.")
61        .gather(gather)
62        .say("We didn't receive any input.")
63        .redirect("https://example.com/main-menu");
64
65    println!("{}", response.to_xml());
66}
Source

pub fn refer(self, refer: Refer) -> Self

TwiML Verb

§Arguments
  • refer - Pre-configured Refer object
Source

pub fn reject(self, reject: Reject) -> Self

TwiML Verb

§Arguments
  • reject - Pre-configured Reject object
Source

pub fn say(self, message: impl Into<String>) -> Self

TwiML Verb

§Arguments
  • message - Message to say
Examples found in repository?
examples/voice_call.rs (line 40)
38fn simple_greeting() {
39    let response = VoiceResponse::new()
40        .say("Hello! Welcome to TwiML Rust.")
41        .say("This is a simple voice response example.")
42        .hangup();
43
44    println!("{}", response.to_xml());
45}
46
47/// Interactive voice response menu
48fn ivr_menu() {
49    let gather = Gather::new()
50        .input(vec!["dtmf".to_string(), "speech".to_string()])
51        .action("https://example.com/handle-input")
52        .method("POST")
53        .timeout(10)
54        .num_digits(1)
55        .add_say(Say::new(
56            "Press 1 for sales, 2 for support, or 3 for billing. You can also say the department name.",
57        ));
58
59    let response = VoiceResponse::new()
60        .say("Welcome to our automated phone system.")
61        .gather(gather)
62        .say("We didn't receive any input.")
63        .redirect("https://example.com/main-menu");
64
65    println!("{}", response.to_xml());
66}
67
68/// Call forwarding to a phone number
69fn call_forwarding() {
70    let dial = Dial::new()
71        .timeout(30)
72        .add_number(DialNumber::new("+15559876543").send_digits("wwww1234"));
73
74    let response = VoiceResponse::new()
75        .say("Please wait while we connect your call.")
76        .dial_with(dial)
77        .say("The call could not be completed. Please try again later.")
78        .hangup();
79
80    println!("{}", response.to_xml());
81}
82
83/// Voicemail recording system
84fn voicemail() {
85    let record = Record::new()
86        .action("https://example.com/handle-recording")
87        .method("POST")
88        .max_length(120)
89        .finish_on_key("#")
90        .transcribe(true)
91        .transcribe_callback("https://example.com/transcription");
92
93    let response = VoiceResponse::new()
94        .say("Please leave a message after the beep. Press the pound key when finished.")
95        .record(record)
96        .say("Thank you for your message. Goodbye!")
97        .hangup();
98
99    println!("{}", response.to_xml());
100}
Source

pub fn start(self, start: Start) -> Self

TwiML Verb

§Arguments
  • start - Pre-configured Start object
Source

pub fn stop(self) -> Self

TwiML Verb

Source

pub fn sms(self, message: impl Into<String>) -> Self

TwiML Noun

§Arguments
  • message - SMS message body
Source

pub fn queue(self, name: impl Into<String>) -> Self

TwiML Noun

§Arguments
  • name - Queue name
Source

pub fn prompt(self, prompt: Prompt) -> Self

TwiML Verb

§Arguments
  • prompt - Pre-configured Prompt object
Source

pub fn say_with(self, say: Say) -> Self

Add a Say verb with a pre-configured Say object

Examples found in repository?
examples/voice_call.rs (line 118)
103fn advanced_ssml() {
104    let say = Say::new("Welcome to our service")
105        .voice("Polly.Joanna")
106        .language("en-US")
107        .add_break(Some("medium".to_string()), None)
108        .add_emphasis(Some("strong".to_string()), "Please listen carefully")
109        .add_break(None, Some("1s".to_string()))
110        .add_prosody(
111            Some("high".to_string()),
112            Some("slow".to_string()),
113            None,
114            "This is important information",
115        );
116
117    let response = VoiceResponse::new()
118        .say_with(say)
119        .play("https://example.com/music.mp3")
120        .hangup();
121
122    println!("{}", response.to_xml());
123}
Source

pub fn play_with(self, play: Play) -> Self

Add a Play verb with a pre-configured Play object

Source

pub fn dial_with(self, dial: Dial) -> Self

Add a Dial verb with a pre-configured Dial object

Examples found in repository?
examples/voice_call.rs (line 76)
69fn call_forwarding() {
70    let dial = Dial::new()
71        .timeout(30)
72        .add_number(DialNumber::new("+15559876543").send_digits("wwww1234"));
73
74    let response = VoiceResponse::new()
75        .say("Please wait while we connect your call.")
76        .dial_with(dial)
77        .say("The call could not be completed. Please try again later.")
78        .hangup();
79
80    println!("{}", response.to_xml());
81}
Source

pub fn gather_with(self, gather: Gather) -> Self

Add a Gather verb with a pre-configured Gather object

Source

pub fn record_with(self, record: Record) -> Self

Add a Record verb with a pre-configured Record object

Source

pub fn connect_with(self, connect: Connect) -> Self

Add a Connect verb with a pre-configured Connect object

Source

pub fn enqueue_with(self, enqueue: Enqueue) -> Self

Add an Enqueue verb with a pre-configured Enqueue object

Source

pub fn pay_with(self, pay: Pay) -> Self

Add a Pay verb with a pre-configured Pay object

Source

pub fn refer_with(self, refer: Refer) -> Self

Add a Refer verb with a pre-configured Refer object

Source

pub fn reject_with(self, reject: Reject) -> Self

Add a Reject verb with a pre-configured Reject object

Source

pub fn start_with(self, start: Start) -> Self

Add a Start verb with a pre-configured Start object

Source

pub fn pause_simple(self, length: u32) -> Self

Simple pause with just a length parameter

Source

pub fn sms_with(self, sms: Sms) -> Self

Add an Sms verb with a pre-configured Sms object

Source

pub fn queue_with(self, queue: Queue) -> Self

Add a Queue verb with a pre-configured Queue object

Source

pub fn prompt_with(self, prompt: Prompt) -> Self

Add a Prompt verb with a pre-configured Prompt object

Trait Implementations§

Source§

impl Clone for VoiceResponse

Source§

fn clone(&self) -> VoiceResponse

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VoiceResponse

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VoiceResponse

Source§

fn default() -> VoiceResponse

Returns the “default value” for a type. Read more
Source§

impl TwiML for VoiceResponse

Source§

fn to_xml(&self) -> String

Convert the TwiML to an XML string
Source§

fn validate(&self) -> Result<Vec<ValidationError>>

Validate the TwiML
Source§

fn validate_strict(&self) -> Result<Vec<ValidationError>>

Validate the TwiML with strict validation

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.