ferro_notifications/channels/
whatsapp.rs1#[derive(Debug, Clone)]
9pub struct WhatsAppMessage {
10 pub message: ferro_whatsapp::Message,
12}
13
14impl WhatsAppMessage {
15 pub fn text(body: impl Into<String>) -> Self {
17 Self {
18 message: ferro_whatsapp::Message::Text { body: body.into() },
19 }
20 }
21
22 pub fn template(
27 name: impl Into<String>,
28 language: impl Into<String>,
29 parameters: Vec<serde_json::Value>,
30 ) -> Self {
31 Self {
32 message: ferro_whatsapp::Message::Template {
33 name: name.into(),
34 language: language.into(),
35 parameters,
36 },
37 }
38 }
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_whatsapp_message_text_builder() {
47 let msg = WhatsAppMessage::text("hello");
48 match msg.message {
49 ferro_whatsapp::Message::Text { body } => assert_eq!(body, "hello"),
50 _ => panic!("expected Text variant"),
51 }
52 }
53
54 #[test]
55 fn test_whatsapp_message_template_builder() {
56 let params = vec![serde_json::json!({"type": "text", "text": "Alberto"})];
57 let msg = WhatsAppMessage::template("order_confirmation", "it", params.clone());
58 match msg.message {
59 ferro_whatsapp::Message::Template {
60 name,
61 language,
62 parameters,
63 } => {
64 assert_eq!(name, "order_confirmation");
65 assert_eq!(language, "it");
66 assert_eq!(parameters, params);
67 }
68 _ => panic!("expected Template variant"),
69 }
70 }
71}