Skip to main content

plexus_comms/activations/push/
types.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5// Request types
6#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
7pub struct SendPushParams {
8    pub device_token: String,
9    pub platform: Platform,
10    pub title: String,
11    pub body: String,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub data: Option<HashMap<String, String>>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub badge: Option<i32>,
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub sound: Option<String>,
18}
19
20#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
21#[serde(rename_all = "lowercase")]
22pub enum Platform {
23    Ios,
24    Android,
25    Web,
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
29pub struct SendBatchParams {
30    pub notifications: Vec<SendPushParams>,
31}
32
33// Response/Event types
34#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
35#[serde(tag = "type", rename_all = "snake_case")]
36pub enum SendPushEvent {
37    Queued {
38        message_id: String,
39        platform: Platform,
40    },
41    Sent {
42        message_id: String,
43        platform: Platform,
44        timestamp: i64,
45    },
46    Error {
47        message: String,
48        platform: Option<Platform>,
49        code: Option<String>,
50    },
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
54#[serde(tag = "type", rename_all = "snake_case")]
55pub enum BatchSendEvent {
56    Progress {
57        sent: usize,
58        total: usize,
59        percentage: f32,
60    },
61    NotificationSent {
62        index: usize,
63        message_id: String,
64        platform: Platform,
65    },
66    NotificationFailed {
67        index: usize,
68        platform: Platform,
69        error: String,
70    },
71    Complete {
72        total_sent: usize,
73        total_failed: usize,
74    },
75}