sms_message/
sms_message.rs1use twiml_rust::{
9 messaging::{Body, Media, Message, MessageAttributes, RedirectAttributes},
10 MessagingResponse, TwiML,
11};
12
13fn main() {
14 println!("=== TwiML Messaging Examples ===\n");
15
16 println!("1. Simple SMS:");
18 simple_sms();
19
20 println!("\n2. SMS with Attributes:");
22 sms_with_attributes();
23
24 println!("\n3. MMS with Single Media:");
26 mms_single_media();
27
28 println!("\n4. MMS with Multiple Media:");
30 mms_multiple_media();
31
32 println!("\n5. Message with Redirect:");
34 message_with_redirect();
35}
36
37fn 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
45fn 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
60fn 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
71fn 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
88fn 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}