gsm_core/platforms/
provider.rs

1use async_trait::async_trait;
2use std::sync::Arc;
3
4use crate::{
5    cards::{Card, CardRenderer},
6    http::{HttpClient, RawRequest, RawResponse},
7    ingress::VerifiedEvent,
8    telemetry::TelemetryHandle,
9};
10use greentic_secrets::spec::SecretsBackend;
11use greentic_types::TenantCtx;
12
13#[derive(Clone)]
14pub struct PlatformInit {
15    pub secrets: Arc<dyn SecretsBackend + Send + Sync>,
16    pub telemetry: TelemetryHandle,
17    pub http: Arc<dyn HttpClient + Send + Sync>,
18    pub card_renderer: Arc<dyn CardRenderer>,
19}
20
21#[async_trait]
22pub trait PlatformProvider: Send + Sync {
23    fn platform_id(&self) -> &'static str;
24
25    async fn health(&self) -> anyhow::Result<()>;
26
27    async fn send_card(&self, ctx: &TenantCtx, to: &str, card: &Card) -> anyhow::Result<()>;
28
29    async fn send_text(&self, ctx: &TenantCtx, to: &str, text: &str) -> anyhow::Result<()> {
30        let card = Card::from_text(text);
31        self.send_card(ctx, to, &card).await
32    }
33
34    async fn verify_webhook(&self, raw: &RawRequest) -> anyhow::Result<VerifiedEvent>;
35
36    async fn raw_call(
37        &self,
38        _ctx: &TenantCtx,
39        _method: &str,
40        _path: &str,
41        _body: Option<&[u8]>,
42    ) -> anyhow::Result<RawResponse> {
43        anyhow::bail!("raw_call not supported for {}", self.platform_id())
44    }
45}