twilly_cli 0.2.2

A CLI tool for interacting the Twilio API built upon the twilly crate
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
use chrono::Datelike;
use std::{process, str::FromStr};

use inquire::{validator::Validation, Confirm, Select, Text};
use strum::IntoEnumIterator;
use strum_macros::{Display, EnumIter, EnumString};
use twilly::{
    conversation::{Conversation, State, UpdateConversation},
    Client, ErrorKind,
};
use twilly_cli::{
    get_action_choice_from_user, get_date_from_user, get_filter_choice_from_user, prompt_user,
    prompt_user_selection, ActionChoice, DateRange, FilterChoice,
};

#[derive(Clone, Display, EnumIter, EnumString)]
pub enum Action {
    #[strum(to_string = "Get conversation")]
    GetConversation,
    #[strum(to_string = "List Conversations")]
    ListConversations,
    #[strum(to_string = "List Conversations by identifier")]
    ListByIdentifier,
    #[strum(to_string = "Close Conversation")]
    CloseConversation,
    #[strum(to_string = "Close all Conversations")]
    CloseAllConversations,
    #[strum(to_string = "Delete Conversation")]
    DeleteConversation,
    #[strum(to_string = "Delete all Conversations")]
    DeleteAllConversations,
    Back,
    Exit,
}

pub async fn choose_conversation_action(twilio: &Client) {
    let options: Vec<Action> = Action::iter().collect();

    loop {
        let action_selection_prompt = Select::new("Select an action:", options.clone());

        if let Some(action) = prompt_user_selection(action_selection_prompt) {
            match action {
                Action::GetConversation => {
                    let conversation_sid_prompt =
                        Text::new("Please provide a conversation SID, or unique name:")
                            .with_placeholder("CH...")
                            .with_validator(|val: &str| {
                                if val.starts_with("CH") && val.len() == 34 {
                                    Ok(Validation::Valid)
                                } else {
                                    Ok(Validation::Invalid(
                                        "Conversation SID should be 34 characters in length".into(),
                                    ))
                                }
                            });

                    if let Some(conversation_sid) = prompt_user(conversation_sid_prompt) {
                        match twilio.conversations().get(&conversation_sid).await {
                            Ok(conversation) => {
                                println!("Conversation found.");
                                println!();

                                if let Some(action_choice) = get_action_choice_from_user(
                                    vec![String::from("List Details"), String::from("Delete")],
                                    "Select an action: ",
                                ) {
                                    match action_choice {
                                        ActionChoice::Back => {
                                            break;
                                        }
                                        ActionChoice::Exit => process::exit(0),
                                        ActionChoice::Other(choice) => match choice.as_str() {
                                            "List Details" => {
                                                println!("{:#?}", conversation);
                                                println!();
                                            }
                                            "Delete" => {
                                                let confirm_prompt = Confirm::new(
                                                        "Are you sure you wish to delete the Conversation?"
                                                    )
                                                        .with_placeholder("N")
                                                        .with_default(false);
                                                let confirmation = prompt_user(confirm_prompt);
                                                if confirmation.is_some() && confirmation.unwrap() {
                                                    println!("Deleting Conversation...");
                                                    twilio
                                                        .conversations()
                                                        .delete(&conversation_sid)
                                                        .await
                                                        .unwrap_or_else(|error| {
                                                            panic!("{}", error)
                                                        });
                                                    println!("Conversation deleted.");
                                                    println!();
                                                }
                                            }
                                            _ => println!("Unknown action '{}'", choice),
                                        },
                                    }
                                } else {
                                    break;
                                }
                            }
                            Err(error) => match error.kind {
                                ErrorKind::TwilioError(twilio_error) => {
                                    if twilio_error.status == 404 {
                                        println!(
                                            "A Conversation with SID '{}' was not found.",
                                            &conversation_sid
                                        );
                                        println!();
                                    } else {
                                        panic!("{}", twilio_error);
                                    }
                                }
                                _ => panic!("{}", error),
                            },
                        }
                    }
                }
                Action::ListConversations => {
                    let mut start_date: Option<chrono::NaiveDate> = None;
                    let mut end_date: Option<chrono::NaiveDate> = None;

                    let mut user_filtered_dates = false;

                    let filter_dates_prompt =
                        Confirm::new("Would you like to filter between specified dates?")
                            .with_placeholder("N")
                            .with_default(false);

                    if let Some(decision) = prompt_user(filter_dates_prompt) {
                        if decision {
                            user_filtered_dates = true;
                            let utc_now = chrono::Utc::now();
                            let utc_one_year_ago = utc_now - chrono::Duration::days(365);
                            if let Some(user_start_date) = get_date_from_user(
                                "Choose a start date:",
                                Some(DateRange {
                                    minimum_date: chrono::NaiveDate::from_ymd_opt(
                                        utc_one_year_ago.year(),
                                        utc_one_year_ago.month(),
                                        utc_one_year_ago.day(),
                                    )
                                    .unwrap(),
                                    maximum_date: chrono::NaiveDate::from_ymd_opt(
                                        utc_now.year(),
                                        utc_now.month(),
                                        utc_now.day(),
                                    )
                                    .unwrap(),
                                }),
                            ) {
                                start_date = Some(user_start_date);
                                end_date = get_date_from_user(
                                    "Choose an end date:",
                                    Some(DateRange {
                                        minimum_date: chrono::NaiveDate::from_ymd_opt(
                                            user_start_date.year_ce().1.try_into().unwrap(),
                                            user_start_date.month0() + 1,
                                            user_start_date.day0() + 1,
                                        )
                                        .unwrap(),
                                        maximum_date: chrono::NaiveDate::from_ymd_opt(
                                            utc_now.year(),
                                            utc_now.month(),
                                            utc_now.day(),
                                        )
                                        .unwrap(),
                                    }),
                                );
                            }
                        }
                    }

                    // Only continue if the user filtered by dates *and* provided both options.
                    // If they didn't then they must of cancelled the operation.
                    if !user_filtered_dates || (start_date.is_some() && end_date.is_some()) {
                        if let Some(filter_choice) = get_filter_choice_from_user(
                            State::iter().map(|state| state.to_string()).collect(),
                            "Filter by state? ",
                        ) {
                            let state = match filter_choice {
                                FilterChoice::Any => None,
                                FilterChoice::Other(choice) => {
                                    Some(State::from_str(&choice).unwrap())
                                }
                            };

                            println!("Fetching conversations...");
                            let mut conversations = twilio
                                .conversations()
                                .list(start_date, end_date, state)
                                .await
                                .unwrap_or_else(|error| panic!("{}", error));

                            let number_of_conversations = conversations.len();

                            if number_of_conversations == 0 {
                                println!("No conversations found.");
                                println!();
                            } else {
                                println!("Found {} conversations.", number_of_conversations);

                                // Stores the index of the conversation the user is currently interacting
                                // with. For the first loop this is certainly `None`.
                                let mut selected_conversation_index: Option<usize> = None;
                                loop {
                                    // If we know the index (a.k.a it hasn't been cleared by some other operation)
                                    // then use this conversation otherwise let the user choice.
                                    let selected_conversation = if let Some(index) =
                                        selected_conversation_index
                                    {
                                        &mut conversations[index]
                                    } else if let Some(action_choice) = get_action_choice_from_user(
                                        conversations
                                            .iter()
                                            .map(|conv| match &conv.unique_name {
                                                Some(unique_name) => {
                                                    format!("({}) {}", unique_name, conv)
                                                }
                                                None => {
                                                    format!("{}", conv)
                                                }
                                            })
                                            .collect::<Vec<String>>(),
                                        "Conversations: ",
                                    ) {
                                        match action_choice {
                                            ActionChoice::Back => {
                                                break;
                                            }
                                            ActionChoice::Exit => process::exit(0),
                                            ActionChoice::Other(choice) => {
                                                let conversation_position = conversations
                                                    .iter()
                                                    .position(|conv| conv.sid == choice[..34])
                                                    .expect(
                                                        "Could not find conversation in existing conversation list"
                                                    );

                                                selected_conversation_index =
                                                    Some(conversation_position);
                                                &mut conversations[conversation_position]
                                            }
                                        }
                                    } else {
                                        break;
                                    };

                                    if selected_conversation.state.is_none() {
                                        eprintln!(
                                            "Conversation {} had an unknown state.",
                                            selected_conversation.sid
                                        );
                                        break;
                                    }

                                    match selected_conversation.state.clone().unwrap() {
                                        State::Closed => loop {
                                            if let Some(conversation_action) =
                                                get_action_choice_from_user(
                                                    vec![
                                                        String::from("List details"),
                                                        String::from("Delete"),
                                                    ],
                                                    "Select an action: ",
                                                )
                                            {
                                                match conversation_action {
                                                    ActionChoice::Back => {
                                                        selected_conversation_index = None;
                                                        break;
                                                    }
                                                    ActionChoice::Exit => process::exit(0),
                                                    ActionChoice::Other(choice) => match choice
                                                        .as_str()
                                                    {
                                                        "List details" => {
                                                            println!(
                                                                "{:#?}",
                                                                selected_conversation
                                                            );
                                                            println!();
                                                        }
                                                        "Delete" => {
                                                            delete_conversation(
                                                                twilio,
                                                                &selected_conversation.sid,
                                                            )
                                                            .await;
                                                            conversations.remove(
                                                                        selected_conversation_index.expect(
                                                                            "Could not find conversation in existing conversation list"
                                                                        )
                                                                    );
                                                            selected_conversation_index = None;
                                                            break;
                                                        }
                                                        _ => {
                                                            println!("Unknown action '{}'", choice);
                                                        }
                                                    },
                                                }
                                            } else {
                                                selected_conversation_index = None;
                                                break;
                                            }
                                        },
                                        State::Inactive => loop {
                                            if let Some(conversation_action) =
                                                get_action_choice_from_user(
                                                    vec![
                                                        String::from("List details"),
                                                        String::from("Re-activate"),
                                                        String::from("Delete"),
                                                    ],
                                                    "Select an action: ",
                                                )
                                            {
                                                match conversation_action {
                                                    ActionChoice::Back => {
                                                        selected_conversation_index = None;
                                                        break;
                                                    }
                                                    ActionChoice::Exit => process::exit(0),
                                                    ActionChoice::Other(choice) => match choice
                                                        .as_str()
                                                    {
                                                        "List details" => {
                                                            println!(
                                                                "{:#?}",
                                                                selected_conversation
                                                            );
                                                            println!();
                                                        }
                                                        "Re-activate" => {
                                                            let updated_conversation =
                                                                update_conversation(
                                                                    twilio,
                                                                    &selected_conversation.sid,
                                                                    UpdateConversation {
                                                                        state: Some(State::Active),
                                                                        friendly_name: None,
                                                                        unique_name: None,
                                                                        attributes: None,
                                                                        timers: None,
                                                                    },
                                                                )
                                                                .await;
                                                            conversations[
                                                                        selected_conversation_index.expect(
                                                                            "Could not find conversation in existing conversation list"
                                                                        )
                                                                    ] = updated_conversation;
                                                            break;
                                                        }
                                                        "Delete" => {
                                                            delete_conversation(
                                                                twilio,
                                                                &selected_conversation.sid,
                                                            )
                                                            .await;
                                                            conversations.remove(
                                                                        selected_conversation_index.expect(
                                                                            "Could not find conversation in existing conversation list"
                                                                        )
                                                                    );
                                                            selected_conversation_index = None;
                                                            break;
                                                        }
                                                        _ => {
                                                            println!("Unknown action '{}'", choice);
                                                        }
                                                    },
                                                }
                                            } else {
                                                selected_conversation_index = None;
                                                break;
                                            }
                                        },
                                        State::Active => loop {
                                            if let Some(conversation_action) =
                                                get_action_choice_from_user(
                                                    vec![
                                                        String::from("List details"),
                                                        String::from("De-activate"),
                                                        String::from("Delete"),
                                                    ],
                                                    "Select an action: ",
                                                )
                                            {
                                                match conversation_action {
                                                    ActionChoice::Back => {
                                                        selected_conversation_index = None;
                                                        break;
                                                    }
                                                    ActionChoice::Exit => process::exit(0),
                                                    ActionChoice::Other(choice) => match choice
                                                        .as_str()
                                                    {
                                                        "List details" => {
                                                            println!(
                                                                "{:#?}",
                                                                selected_conversation
                                                            );
                                                            println!();
                                                        }
                                                        "De-activate" => {
                                                            let updated_conversation =
                                                                update_conversation(
                                                                    twilio,
                                                                    &selected_conversation.sid,
                                                                    UpdateConversation {
                                                                        state: Some(
                                                                            State::Inactive,
                                                                        ),
                                                                        friendly_name: None,
                                                                        unique_name: None,
                                                                        attributes: None,
                                                                        timers: None,
                                                                    },
                                                                )
                                                                .await;
                                                            conversations[
                                                                        selected_conversation_index.expect(
                                                                            "Could not find conversation in existing conversation list"
                                                                        )
                                                                    ] = updated_conversation;
                                                            break;
                                                        }
                                                        "Delete" => {
                                                            delete_conversation(
                                                                twilio,
                                                                &selected_conversation.sid,
                                                            )
                                                            .await;
                                                            conversations.remove(
                                                                        selected_conversation_index.expect(
                                                                            "Could not find conversation in existing conversation list"
                                                                        )
                                                                    );
                                                            selected_conversation_index = None;
                                                            break;
                                                        }
                                                        _ => {
                                                            println!("Unknown action '{}'", choice);
                                                        }
                                                    },
                                                }
                                            }
                                        },
                                    }
                                }
                            }
                        }
                    }
                }
                Action::ListByIdentifier => {
                    let mut identity: Option<String> = None;
                    let mut address: Option<String> = None;

                    let identifier_selection =
                        Select::new("Select an identifier:", vec!["Identity", "Address"])
                            .with_help_message("Identity for chat-based users otherwise Address");

                    if let Some(identifier) = prompt_user_selection(identifier_selection) {
                        match identifier {
                            "Identity" => {
                                let identity_prompt =
                                    Text::new("Please provide the identity to search for:");

                                identity = prompt_user(identity_prompt);
                            }
                            "Address" => {
                                let address_prompt =
                                    Text::new("Please provide the address to search for:");

                                address = prompt_user(address_prompt);
                            }
                            _ => {
                                println!("Unknown identifier '{}'", identifier)
                            }
                        }
                    } else {
                        break;
                    }

                    if let Some(filter_choice) = get_filter_choice_from_user(
                        State::iter().map(|state| state.to_string()).collect(),
                        "Filter by state? ",
                    ) {
                        let state = match filter_choice {
                            FilterChoice::Any => None,
                            FilterChoice::Other(choice) => Some(State::from_str(&choice).unwrap()),
                        };

                        println!("Fetching conversations...");
                        let participant_conversations = twilio
                            .conversations()
                            .participant_conversations()
                            .list(identity, address)
                            .await
                            .unwrap_or_else(|error| panic!("{}", error));

                        // The Participant Conversations endpoint doesn't support state filtering so we need
                        // to fetch all then filter here.
                        let filtered_conversations = match state {
                            None => participant_conversations,
                            Some(state) => participant_conversations
                                .into_iter()
                                .filter(|participant_conv| {
                                    participant_conv.conversation_state == state
                                })
                                .collect(),
                        };

                        let number_of_conversations = filtered_conversations.len();
                        if filtered_conversations.is_empty() {
                            println!("No conversations found with the provided identifier.");
                            println!();
                        } else {
                            println!("Found {} conversations.", number_of_conversations);
                            println!();
                            filtered_conversations.into_iter().for_each(|conv| {
                                println!(
                                    "{} - {}",
                                    conv.conversation_sid, conv.conversation_date_created
                                )
                            });
                            println!();
                        }
                    }
                }
                Action::CloseConversation => {
                    let conversation_sid_prompt =
                        Text::new("Please provide a conversation SID, or unique name:")
                            .with_placeholder("CH...")
                            .with_validator(|val: &str| {
                                if val.starts_with("CH") && val.len() == 34 {
                                    Ok(Validation::Valid)
                                } else {
                                    Ok(Validation::Invalid(
                                        "Conversation SID should be 34 characters in length".into(),
                                    ))
                                }
                            });

                    if let Some(conversation_sid) = prompt_user(conversation_sid_prompt) {
                        close_conversation(twilio, &conversation_sid).await;
                    } else {
                        println!("Operation canceled. No changes were made.");
                    }
                }
                Action::CloseAllConversations => {
                    let confirmation_prompt =
                        Confirm::new("Are you sure to wish to close **all** conversations?")
                            .with_default(false)
                            .with_placeholder("N");

                    let confirmation_result = prompt_user(confirmation_prompt);

                    if confirmation_result.is_none() {
                        return;
                    }

                    if let Some(false) = confirmation_result {
                        return;
                    }

                    let conversations = twilio
                        .conversations()
                        .list(None, None, Some(State::Active))
                        .await
                        .unwrap_or_else(|error| panic!("{}", error));

                    println!(
                        "We've found {} active conversations to close.",
                        conversations.len()
                    );
                    let count_confirmation_prompt = Confirm::new("Continue?")
                        .with_default(false)
                        .with_placeholder("N");

                    let count_confirmation_result = prompt_user(count_confirmation_prompt);

                    if count_confirmation_result.is_none() {
                        return;
                    }

                    if let Some(false) = count_confirmation_result {
                        return;
                    }

                    println!("Proceeding with closing. Please wait...");
                    for conversation in conversations {
                        close_conversation(twilio, &conversation.sid).await;
                        // This is not particularly smart but this prevents overwhelming Twilio.
                        // Close 1 Conversation per second. The rate could be much higher than this.
                        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
                    }

                    println!("All active conversations closed.");
                    println!();
                    return;
                }
                Action::DeleteConversation => {
                    let conversation_sid_prompt =
                        Text::new("Please provide a conversation SID, or unique name:")
                            .with_placeholder("CH...")
                            .with_validator(|val: &str| {
                                if val.starts_with("CH") && val.len() == 34 {
                                    Ok(Validation::Valid)
                                } else {
                                    Ok(Validation::Invalid(
                                        "Conversation SID should be 34 characters in length".into(),
                                    ))
                                }
                            });

                    if let Some(conversation_sid) = prompt_user(conversation_sid_prompt) {
                        delete_conversation(twilio, &conversation_sid).await;
                    } else {
                        println!("Operation canceled. No changes were made.");
                    }
                }
                Action::DeleteAllConversations => {
                    let first_confirmation_prompt =
                        Confirm::new("Are you sure you wish to delete **all** Conversations?")
                            .with_placeholder("N")
                            .with_default(false);
                    let second_confirmation_prompt =
                        Confirm::new("Are you double sure? There is no going back.")
                            .with_placeholder("N")
                            .with_default(false);

                    if let Some(first_confirmation) = prompt_user(first_confirmation_prompt) {
                        if first_confirmation {
                            if let Some(second_confirmation) =
                                prompt_user(second_confirmation_prompt)
                            {
                                if second_confirmation {
                                    println!("Proceeding with deletion. Please wait...");
                                    let conversations = twilio
                                        .conversations()
                                        .list(None, None, None)
                                        .await
                                        .unwrap_or_else(|error| panic!("{}", error));

                                    for conversation in conversations {
                                        twilio
                                            .conversations()
                                            .delete(&conversation.sid)
                                            .await
                                            .unwrap_or_else(|error| panic!("{}", error));
                                        // This is not particularly smart but this prevents overwhelming Twilio.
                                        // Delete 1 Conversation per second. The rate could be much higher than this.
                                        tokio::time::sleep(tokio::time::Duration::from_secs(1))
                                            .await;
                                    }

                                    println!("All conversations deleted.");
                                    println!();
                                    return;
                                }
                            }
                        }
                    }

                    println!("Operation canceled. No changes were made.");
                    println!();
                }
                Action::Back => {
                    break;
                }
                Action::Exit => process::exit(0),
            }
        } else {
            break;
        };
    }
}

/// Prompts the user for confirmation before deleting the conversation with
/// the SID provided. Will panic if the delete operation fails.
async fn update_conversation(
    twilio: &Client,
    sid: &str,
    updates: UpdateConversation,
) -> Conversation {
    match twilio.conversations().update(sid, updates).await {
        Ok(updated_conversation) => {
            println!("Conversation updated.");
            println!();

            updated_conversation
        }
        Err(error) => panic!("{}", error),
    }
}

/// Helper function to encapsulate a conversation close update
async fn close_conversation(twilio: &Client, sid: &str) {
    match twilio
        .conversations()
        .update(
            sid,
            UpdateConversation {
                unique_name: None,
                friendly_name: None,
                state: Some(State::Closed),
                attributes: None,
                timers: None,
            },
        )
        .await
    {
        Ok(_) => {
            println!("Conversation closed.");
            println!();
        }
        Err(error) => {
            panic!("{}", error);
        }
    }
}

/// Prompts the user for confirmation before deleting the conversation with
/// the SID provided. Will panic if the delete operation fails.
async fn delete_conversation(twilio: &Client, sid: &str) {
    let confirmation_prompt = Confirm::new("Are you sure you wish to delete the Conversation?")
        .with_placeholder("N")
        .with_default(false);

    if let Some(confirmation) = prompt_user(confirmation_prompt) {
        if confirmation {
            match twilio.conversations().delete(sid).await {
                Ok(_) => {
                    println!("Conversation deleted.");
                    println!();
                }
                Err(error) => match error.kind {
                    ErrorKind::TwilioError(twilio_error) => {
                        if twilio_error.status == 404 {
                            println!("A Conversation with SID '{}' was not found.", &sid);
                            println!();
                        } else {
                            panic!("{}", twilio_error)
                        }
                    }
                    _ => panic!("{}", error),
                },
            }
        }
    }
}