billdogeng 1.0.0-beta.1

Official BilldogEng server SDK for Rust — Analytics, Feature Flags (remote + local eval), Surveys, Messaging, and LLM observability.
Documentation
//! Messaging dispatch (BillDog advantage over PostHog) — server-side delivery
//! across push / email / sms / in-app / live-activity.
//!
//! Note: `messaging-dispatch` authenticates with a Supabase session **Bearer
//! JWT** + project membership, not the `x-api-key` key used by the other
//! modules. Pass the JWT as `access_token` per call.

use serde_json::{json, Map, Value};

use crate::error::Result;
use crate::transport::{RequestOptions, Transport};
use crate::types::DispatchParams;

/// Messaging-dispatch client.
pub struct Messaging {
    transport: Transport,
}

impl Messaging {
    /// Construct the messaging client.
    pub fn new(transport: Transport) -> Self {
        Self { transport }
    }

    /// Dispatch a message. Returns the raw JSON result (`{ sent, failed }` or an
    /// envelope when no recipients match).
    pub fn dispatch(&self, params: &DispatchParams) -> Result<Value> {
        let mut body = Map::new();
        body.insert("action".to_string(), json!("send"));
        body.insert("project_id".to_string(), json!(params.project_id));
        body.insert("channel".to_string(), json!(params.channel));
        body.insert("content".to_string(), Value::Object(params.content.clone()));
        if let Some(t) = &params.targeting {
            body.insert("targeting".to_string(), serde_json::to_value(t).unwrap());
        }
        if let Some(s) = &params.scheduling {
            body.insert("scheduling".to_string(), serde_json::to_value(s).unwrap());
        }
        if let Some(t) = &params.template_id {
            body.insert("template_id".to_string(), json!(t));
        }

        let opts = RequestOptions::post("/messaging-dispatch", Value::Object(body))
            .header("Authorization", format!("Bearer {}", params.access_token))
            .gzip(false);

        self.transport.request(&opts)
    }
}