Skip to main content

android_sms_gateway/types/
inbox.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4/// The type of an incoming message.
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
7pub enum IncomingMessageType {
8    Sms,
9    DataSms,
10    Mms,
11    MmsDownloaded,
12    #[serde(other)]
13    Other,
14}
15
16/// An incoming (received) message.
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(rename_all = "camelCase")]
19pub struct IncomingMessage {
20    pub id: String,
21    /// Message type (SMS, DATA_SMS, MMS, etc.).
22    #[serde(rename = "type")]
23    pub message_type: IncomingMessageType,
24    /// Sender phone number.
25    pub sender: String,
26    /// Recipient phone number (the device's number).
27    #[serde(default, skip_serializing_if = "Option::is_none")]
28    pub recipient: Option<String>,
29    /// SIM card number that received the message.
30    #[serde(default, skip_serializing_if = "Option::is_none")]
31    pub sim_number: Option<u8>,
32    /// A preview of the message content.
33    pub content_preview: String,
34    /// When the message was received.
35    pub created_at: DateTime<Utc>,
36    /// MMS attachment metadata (only present when `include_attachments` is true).
37    #[serde(default, skip_serializing_if = "Option::is_none")]
38    pub attachments: Option<Vec<IncomingMessageAttachment>>,
39}
40
41/// Metadata for an MMS attachment returned by the inbox API.
42#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(rename_all = "camelCase")]
44pub struct IncomingMessageAttachment {
45    /// Part ID of the attachment, corresponding to the `_id` in `content://mms/part`.
46    pub part_id: i32,
47    /// Display name of the attachment file.
48    pub name: String,
49    /// Size of the attachment in bytes.
50    pub size: i64,
51    /// MIME type of the attachment (e.g. `image/jpeg`).
52    pub content_type: String,
53}
54
55/// The delivery mode for webhooks.
56#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
57pub enum WebhookDelivery {
58    #[serde(rename = "Disabled")]
59    Disabled,
60    #[serde(rename = "Individual")]
61    Individual,
62    #[serde(rename = "Batch")]
63    Batch,
64}
65
66/// Request to refresh the inbox and pull new messages from the device.
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(rename_all = "camelCase")]
69pub struct InboxRefreshRequest {
70    /// Optional device ID filter.
71    #[serde(default, skip_serializing_if = "Option::is_none")]
72    pub device_id: Option<String>,
73    /// Start of the time range.
74    pub since: DateTime<Utc>,
75    /// End of the time range.
76    pub until: DateTime<Utc>,
77    /// Types of messages to include.
78    #[serde(default, skip_serializing_if = "Option::is_none")]
79    pub message_types: Option<Vec<IncomingMessageType>>,
80    /// Whether to trigger webhooks for pulled messages.
81    ///
82    /// Deprecated: use `webhook_delivery` instead.
83    #[serde(default, skip_serializing_if = "std::ops::Not::not")]
84    pub trigger_webhooks: bool,
85    /// Delivery mode for webhooks (overrides `trigger_webhooks` when set).
86    #[serde(default, skip_serializing_if = "Option::is_none")]
87    pub webhook_delivery: Option<WebhookDelivery>,
88}
89
90/// Request to export inbox messages via webhooks.
91#[derive(Debug, Clone, Serialize, Deserialize)]
92#[serde(rename_all = "camelCase")]
93pub struct MessagesExportRequest {
94    /// Device ID to export messages for.
95    pub device_id: String,
96    /// Start of the time range.
97    pub since: DateTime<Utc>,
98    /// End of the time range.
99    pub until: DateTime<Utc>,
100}