MessagingResponse

Struct MessagingResponse 

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

TwiML for Messages

Implementations§

Source§

impl MessagingResponse

Source

pub fn new() -> Self

Create a new MessagingResponse

TwiML for Messages

Examples found in repository?
examples/sms_message.rs (line 40)
38fn simple_sms() {
39    let response =
40        MessagingResponse::new().message("Thanks for your message! We'll get back to you soon.");
41
42    println!("{}", response.to_xml());
43}
44
45/// SMS with custom attributes
46fn sms_with_attributes() {
47    let response = MessagingResponse::new().message_with_attributes(
48        MessageAttributes::new()
49            .to("+15551234567")
50            .from("+15559876543")
51            .action("https://example.com/message-status")
52            .method("POST")
53            .status_callback("https://example.com/status"),
54        "Your order #12345 has been shipped!",
55    );
56
57    println!("{}", response.to_xml());
58}
59
60/// MMS with a single media attachment
61fn mms_single_media() {
62    let message = Message::with_nouns(MessageAttributes::new())
63        .body(Body::new("Check out this image!"))
64        .add_media(Media::new("https://example.com/image.jpg"));
65
66    let response = MessagingResponse::new().message_with_nouns(message);
67
68    println!("{}", response.to_xml());
69}
70
71/// MMS with multiple media attachments
72fn mms_multiple_media() {
73    let message = Message::with_nouns(
74        MessageAttributes::new()
75            .to("+15551234567")
76            .from("+15559876543"),
77    )
78    .body(Body::new("Here are the photos from today's event!"))
79    .add_media(Media::new("https://example.com/photo1.jpg"))
80    .add_media(Media::new("https://example.com/photo2.jpg"))
81    .add_media(Media::new("https://example.com/photo3.jpg"));
82
83    let response = MessagingResponse::new().message_with_nouns(message);
84
85    println!("{}", response.to_xml());
86}
87
88/// Message followed by a redirect
89fn message_with_redirect() {
90    let response = MessagingResponse::new()
91        .message("Processing your request...")
92        .redirect_with_attributes(
93            RedirectAttributes::new().method("POST"),
94            "https://example.com/next-step",
95        );
96
97    println!("{}", response.to_xml());
98}
Source

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

TwiML Verb

Supports two calling patterns:

  • message(body) - Simple message with just body text
  • Use message_with_attributes for attributes + body
§Arguments
  • body - Message Body
§Returns

Returns self for method chaining

Examples found in repository?
examples/sms_message.rs (line 40)
38fn simple_sms() {
39    let response =
40        MessagingResponse::new().message("Thanks for your message! We'll get back to you soon.");
41
42    println!("{}", response.to_xml());
43}
44
45/// SMS with custom attributes
46fn sms_with_attributes() {
47    let response = MessagingResponse::new().message_with_attributes(
48        MessageAttributes::new()
49            .to("+15551234567")
50            .from("+15559876543")
51            .action("https://example.com/message-status")
52            .method("POST")
53            .status_callback("https://example.com/status"),
54        "Your order #12345 has been shipped!",
55    );
56
57    println!("{}", response.to_xml());
58}
59
60/// MMS with a single media attachment
61fn mms_single_media() {
62    let message = Message::with_nouns(MessageAttributes::new())
63        .body(Body::new("Check out this image!"))
64        .add_media(Media::new("https://example.com/image.jpg"));
65
66    let response = MessagingResponse::new().message_with_nouns(message);
67
68    println!("{}", response.to_xml());
69}
70
71/// MMS with multiple media attachments
72fn mms_multiple_media() {
73    let message = Message::with_nouns(
74        MessageAttributes::new()
75            .to("+15551234567")
76            .from("+15559876543"),
77    )
78    .body(Body::new("Here are the photos from today's event!"))
79    .add_media(Media::new("https://example.com/photo1.jpg"))
80    .add_media(Media::new("https://example.com/photo2.jpg"))
81    .add_media(Media::new("https://example.com/photo3.jpg"));
82
83    let response = MessagingResponse::new().message_with_nouns(message);
84
85    println!("{}", response.to_xml());
86}
87
88/// Message followed by a redirect
89fn message_with_redirect() {
90    let response = MessagingResponse::new()
91        .message("Processing your request...")
92        .redirect_with_attributes(
93            RedirectAttributes::new().method("POST"),
94            "https://example.com/next-step",
95        );
96
97    println!("{}", response.to_xml());
98}
Source

pub fn message_with_attributes( self, attributes: MessageAttributes, body: impl Into<String>, ) -> Self

TwiML Verb with attributes

§Arguments
  • attributes - TwiML attributes
  • body - Message Body
§Returns

Returns self for method chaining

Examples found in repository?
examples/sms_message.rs (lines 47-55)
46fn sms_with_attributes() {
47    let response = MessagingResponse::new().message_with_attributes(
48        MessageAttributes::new()
49            .to("+15551234567")
50            .from("+15559876543")
51            .action("https://example.com/message-status")
52            .method("POST")
53            .status_callback("https://example.com/status"),
54        "Your order #12345 has been shipped!",
55    );
56
57    println!("{}", response.to_xml());
58}
Source

pub fn message_with_nouns(self, message: Message) -> Self

TwiML Verb with Body and Media nouns

This allows you to create messages with proper

and nouns, supporting multiple media attachments for MMS.
§Arguments
  • message - Pre-configured Message with Body and/or Media nouns
§Returns

Returns self for method chaining

§Example
use twiml_rust::{MessagingResponse, Message, MessageAttributes, Body, Media, TwiML};

let message = Message::with_nouns(MessageAttributes::new())
    .body(Body::new("Check out these images!"))
    .add_media(Media::new("https://example.com/image1.jpg"))
    .add_media(Media::new("https://example.com/image2.jpg"));

let response = MessagingResponse::new().message_with_nouns(message);
let xml = response.to_xml();
Examples found in repository?
examples/sms_message.rs (line 66)
61fn mms_single_media() {
62    let message = Message::with_nouns(MessageAttributes::new())
63        .body(Body::new("Check out this image!"))
64        .add_media(Media::new("https://example.com/image.jpg"));
65
66    let response = MessagingResponse::new().message_with_nouns(message);
67
68    println!("{}", response.to_xml());
69}
70
71/// MMS with multiple media attachments
72fn mms_multiple_media() {
73    let message = Message::with_nouns(
74        MessageAttributes::new()
75            .to("+15551234567")
76            .from("+15559876543"),
77    )
78    .body(Body::new("Here are the photos from today's event!"))
79    .add_media(Media::new("https://example.com/photo1.jpg"))
80    .add_media(Media::new("https://example.com/photo2.jpg"))
81    .add_media(Media::new("https://example.com/photo3.jpg"));
82
83    let response = MessagingResponse::new().message_with_nouns(message);
84
85    println!("{}", response.to_xml());
86}
Source

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

TwiML Verb

Supports two calling patterns:

  • redirect(url) - Simple redirect with just URL
  • Use redirect_with_attributes for attributes + URL
§Arguments
  • url - Redirect URL
§Returns

Returns self for method chaining

Source

pub fn redirect_with_attributes( self, attributes: RedirectAttributes, url: impl Into<String>, ) -> Self

TwiML Verb with attributes

§Arguments
  • attributes - TwiML attributes
  • url - Redirect URL
§Returns

Returns self for method chaining

Examples found in repository?
examples/sms_message.rs (lines 92-95)
89fn message_with_redirect() {
90    let response = MessagingResponse::new()
91        .message("Processing your request...")
92        .redirect_with_attributes(
93            RedirectAttributes::new().method("POST"),
94            "https://example.com/next-step",
95        );
96
97    println!("{}", response.to_xml());
98}
Source

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

Comments in

§Arguments
  • comment - XML Comment
§Returns

Returns self for method chaining

Source

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

Comments after

§Arguments
  • comment - XML Comment
§Returns

Returns self for method chaining

Source

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

Comments before

§Arguments
  • comment - XML Comment
§Returns

Returns self for method chaining

Source§

impl MessagingResponse

Source

pub fn validate(&self) -> Vec<TwiMLWarning>

Validate the TwiML response and return warnings (if any)

This does NOT affect XML generation - the TwiML is still valid. Warnings help identify potential logic issues.

§Example
use twiml_rust::messaging::MessagingResponse;

let response = MessagingResponse::new()
    .message("Hello!")
    .redirect("https://example.com");

let warnings = response.validate();
assert!(warnings.is_empty()); // No warnings - this is fine

Trait Implementations§

Source§

impl Clone for MessagingResponse

Source§

fn clone(&self) -> MessagingResponse

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 MessagingResponse

Source§

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

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

impl Default for MessagingResponse

Source§

fn default() -> MessagingResponse

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

impl TwiML for MessagingResponse

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.