fax_receive/
fax_receive.rs

1//! Fax TwiML examples
2//!
3//! Run this example with:
4//! ```bash
5//! cargo run --example fax_receive
6//! ```
7
8use twiml_rust::{
9    fax::{ReceiveAttributes, ReceiveMediaType, ReceivePageSize},
10    FaxResponse, TwiML,
11};
12
13fn main() {
14    println!("=== TwiML Fax Examples ===\n");
15
16    // Example 1: Simple fax receive
17    println!("1. Simple Fax Receive:");
18    simple_receive();
19
20    // Example 2: Fax receive with PDF storage
21    println!("\n2. Fax Receive with PDF Storage:");
22    receive_as_pdf();
23
24    // Example 3: Fax receive with all options
25    println!("\n3. Fax Receive with All Options:");
26    receive_with_all_options();
27
28    // Example 4: Fax receive without storage
29    println!("\n4. Fax Receive without Storage:");
30    receive_no_storage();
31}
32
33/// Simple fax receive with defaults
34fn simple_receive() {
35    let response = FaxResponse::new().receive(Some(ReceiveAttributes::new()));
36
37    println!("{}", response.to_xml());
38}
39
40/// Receive fax and store as PDF
41fn receive_as_pdf() {
42    let response = FaxResponse::new().receive(Some(
43        ReceiveAttributes::new()
44            .action("https://example.com/fax-received")
45            .media_type(ReceiveMediaType::ApplicationPdf),
46    ));
47
48    println!("{}", response.to_xml());
49}
50
51/// Receive fax with all configuration options
52fn receive_with_all_options() {
53    let response = FaxResponse::new().receive(Some(
54        ReceiveAttributes::new()
55            .action("https://example.com/fax-received")
56            .method("POST")
57            .media_type(ReceiveMediaType::ApplicationPdf)
58            .page_size(ReceivePageSize::Letter)
59            .store_media(true),
60    ));
61
62    println!("{}", response.to_xml());
63}
64
65/// Receive fax without storing media
66fn receive_no_storage() {
67    let response = FaxResponse::new().receive(Some(
68        ReceiveAttributes::new()
69            .action("https://example.com/fax-metadata")
70            .store_media(false),
71    ));
72
73    println!("{}", response.to_xml());
74}