Skip to main content

plexus_comms/activations/whatsapp/
activation.rs

1use super::types::*;
2use crate::config::WhatsappConfig;
3use async_stream::stream;
4use futures::Stream;
5
6// Required for macro-generated code
7use plexus_core::plexus;
8use plexus_core::serde_helpers;
9
10#[derive(Clone)]
11pub struct Whatsapp {
12    config: WhatsappConfig,
13    client: reqwest::Client,
14}
15
16impl Whatsapp {
17    pub async fn new(config: WhatsappConfig) -> Result<Self, String> {
18        Ok(Self {
19            config,
20            client: reqwest::Client::new(),
21        })
22    }
23}
24
25#[plexus_macros::hub_methods(
26    namespace = "whatsapp",
27    version = "1.0.0",
28    description = "Send and receive WhatsApp messages via Business API"
29)]
30impl Whatsapp {
31    #[plexus_macros::hub_method(
32        description = "Send a WhatsApp message",
33        params(
34            to = "Recipient phone number (E.164 format)",
35            message = "Message content (text, template, or media)"
36        )
37    )]
38    async fn send_message(
39        &self,
40        to: String,
41        message: MessageContent,
42    ) -> impl Stream<Item = SendMessageEvent> + Send + 'static {
43        let _params = SendMessageParams {
44            to: to.clone(),
45            message,
46        };
47
48        stream! {
49            // WhatsApp Business API implementation would go here
50            yield SendMessageEvent::Sent {
51                message_id: uuid::Uuid::new_v4().to_string(),
52                to,
53            };
54        }
55    }
56
57    #[plexus_macros::hub_method(
58        streaming,
59        description = "Listen for incoming webhook events (messages, status updates)"
60    )]
61    async fn listen_webhooks(&self) -> impl Stream<Item = WebhookEvent> + Send + 'static {
62        stream! {
63            // WhatsApp webhook handling would go here
64            yield WebhookEvent::Error {
65                message: "Not implemented yet".to_string(),
66            };
67        }
68    }
69}