pub struct MessagingResponse { /* private fields */ }Expand description
Implementations§
Source§impl MessagingResponse
impl MessagingResponse
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new MessagingResponse
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}Sourcepub fn message(self, body: impl Into<String>) -> Self
pub fn message(self, body: impl Into<String>) -> Self
Supports two calling patterns:
message(body)- Simple message with just body text- Use
message_with_attributesfor 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}Sourcepub fn message_with_attributes(
self,
attributes: MessageAttributes,
body: impl Into<String>,
) -> Self
pub fn message_with_attributes( self, attributes: MessageAttributes, body: impl Into<String>, ) -> Self
§Arguments
attributes- TwiML attributesbody- 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}Sourcepub fn message_with_nouns(self, message: Message) -> Self
pub fn message_with_nouns(self, message: Message) -> Self
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}Sourcepub fn redirect_with_attributes(
self,
attributes: RedirectAttributes,
url: impl Into<String>,
) -> Self
pub fn redirect_with_attributes( self, attributes: RedirectAttributes, url: impl Into<String>, ) -> Self
Sourcepub fn comment_after(self, comment: impl Into<String>) -> Self
pub fn comment_after(self, comment: impl Into<String>) -> Self
Source§impl MessagingResponse
impl MessagingResponse
Sourcepub fn validate(&self) -> Vec<TwiMLWarning>
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 fineTrait Implementations§
Source§impl Clone for MessagingResponse
impl Clone for MessagingResponse
Source§fn clone(&self) -> MessagingResponse
fn clone(&self) -> MessagingResponse
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MessagingResponse
impl Debug for MessagingResponse
Source§impl Default for MessagingResponse
impl Default for MessagingResponse
Source§fn default() -> MessagingResponse
fn default() -> MessagingResponse
Returns the “default value” for a type. Read more
Source§impl TwiML for MessagingResponse
impl TwiML for MessagingResponse
Auto Trait Implementations§
impl Freeze for MessagingResponse
impl RefUnwindSafe for MessagingResponse
impl Send for MessagingResponse
impl Sync for MessagingResponse
impl Unpin for MessagingResponse
impl UnwindSafe for MessagingResponse
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
Mutably borrows from an owned value. Read more