1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
use serde::{Deserialize, Serialize};

use super::message::StatusCode;

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct NotificationPayload {
    pub object: String,
    pub entry: Vec<Entry>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Entry {
    pub id: String,
    pub changes: Vec<Change>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Change {
    pub value: Value,
    pub field: String,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Value {
    pub contacts: Option<Vec<Contact>>,
    pub errors: Option<Vec<Error>>,
    pub messaging_product: String,
    pub metadata: Metadata,
    pub messages: Option<Vec<NotificationMessage>>,
    pub statuses: Option<Vec<Status>>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Contact {
    pub wa_id: String,
    pub profile: Profile,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Profile {
    pub name: String,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Metadata {
    pub display_phone_number: String,
    pub phone_number_id: String,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct NotificationMessage {
    pub from: String,
    pub id: String,
    pub context: Option<Context>,
    pub errors: Option<Vec<Error>>,
    pub timestamp: String,

    #[serde(rename = "type")]
    pub message_type: NotificationMessageType,
    pub audio: Option<Audio>,
    pub button: Option<Button>,
    pub document: Option<Document>,
    pub text: Option<Text>,
    pub image: Option<Image>,
    pub interactive: Option<Interactive>,
    pub order: Option<Order>,
    pub sticker: Option<Sticker>,
    pub system: Option<System>,
    pub video: Option<Video>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Context {
    forwarded: Option<bool>,
    frequently_forwarded: Option<bool>,
    from: String,
    id: String,
    referred_product: Option<ReferredProduct>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ReferredProduct {
    pub catalog_id: String,
    pub product_retailer_id: String,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Error {
    pub code: i32,
    pub title: String,
    // TODO: Add more fields from v16.0 and newer
}

#[derive(Deserialize, Serialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
pub enum NotificationMessageType {
    Audio,
    Button,
    Document,
    Text,
    Image,
    Interactive,
    Order,
    Sticker,
    System,
    Unknown,
    Video,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Audio {
    pub id: String,
    pub meme_type: String,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Button {
    pub payload: String,
    pub text: String,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Document {
    pub caption: Option<String>,
    pub filename: String,
    pub sha256: String,
    pub meme_type: String,
    pub id: String,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Image {
    pub caption: Option<String>,
    pub sha256: String,
    pub id: String,
    pub meme_type: Option<String>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Interactive {
    pub button_reply: Option<ButtonReply>,
    pub list_reply: Option<ListReply>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ButtonReply {
    pub id: String,
    pub title: String,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ListReply {
    pub id: String,
    pub title: String,
    pub description: String,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Order {
    pub catalog_id: String,
    pub product_items: Vec<ProductItem>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ProductItem {
    pub product_retailer_id: String,
    pub quantity: String,
    pub item_price: String,
    pub currency: String,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Sticker {
    pub meme_type: String,
    pub sha256: String,
    pub id: String,
    pub animated: Option<bool>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct System {
    pub body: String,
    pub identity: String,
    pub new_wa_id: Option<String>,
    pub wa_id: Option<String>,
    pub system_type: String,
    pub customer: String,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Text {
    pub body: String,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Video {
    pub caption: Option<String>,
    pub filename: String,
    pub sha256: String,
    pub id: String,
    pub meme_type: String,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Status {
    pub biz_opaque_callback_data: Option<String>,
    pub conversation: Option<Conversation>,
    pub errors: Option<Vec<Error>>,
    pub id: String,
    pub pricing: Option<Pricing>,
    pub recipient_id: String,
    pub status: StatusCode,
    pub timestamp: String,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Conversation {
    pub id: String,
    pub origin: Origin,
    // TODO: Other fields
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Origin {
    #[serde(rename = "type")]
    pub origin_type: String,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Pricing {
    pub pricing_model: String,
    // TODO: Other fields
}