whatsapp_cloud_api/models/
webhooks.rs

1use serde::{Deserialize, Serialize};
2
3use super::message::StatusCode;
4
5#[derive(Deserialize, Serialize, Debug, Clone)]
6pub struct NotificationPayload {
7    pub object: String,
8    pub entry: Vec<Entry>,
9}
10
11#[derive(Deserialize, Serialize, Debug, Clone)]
12pub struct Entry {
13    pub id: String,
14    pub changes: Vec<Change>,
15}
16
17#[derive(Deserialize, Serialize, Debug, Clone)]
18pub struct Change {
19    pub value: Value,
20    pub field: String,
21}
22
23#[derive(Deserialize, Serialize, Debug, Clone)]
24pub struct Value {
25    pub contacts: Option<Vec<Contact>>,
26    pub errors: Option<Vec<Error>>,
27    pub messaging_product: String,
28    pub metadata: Metadata,
29    pub messages: Option<Vec<NotificationMessage>>,
30    pub statuses: Option<Vec<Status>>,
31}
32
33#[derive(Deserialize, Serialize, Debug, Clone)]
34pub struct Contact {
35    pub wa_id: String,
36    pub profile: Profile,
37}
38
39#[derive(Deserialize, Serialize, Debug, Clone)]
40pub struct Profile {
41    pub name: String,
42}
43
44#[derive(Deserialize, Serialize, Debug, Clone)]
45pub struct Metadata {
46    pub display_phone_number: String,
47    pub phone_number_id: String,
48}
49
50#[derive(Deserialize, Serialize, Debug, Clone)]
51pub struct NotificationMessage {
52    pub from: String,
53    pub id: String,
54    pub context: Option<Context>,
55    pub errors: Option<Vec<Error>>,
56    pub timestamp: String,
57
58    #[serde(rename = "type")]
59    pub message_type: NotificationMessageType,
60    pub audio: Option<Audio>,
61    pub button: Option<Button>,
62    pub document: Option<Document>,
63    pub text: Option<Text>,
64    pub image: Option<Image>,
65    pub interactive: Option<Interactive>,
66    pub order: Option<Order>,
67    pub sticker: Option<Sticker>,
68    pub system: Option<System>,
69    pub video: Option<Video>,
70}
71
72#[derive(Deserialize, Serialize, Debug, Clone)]
73pub struct Context {
74    pub forwarded: Option<bool>,
75    pub frequently_forwarded: Option<bool>,
76    pub from: String,
77    pub id: String,
78    pub referred_product: Option<ReferredProduct>,
79}
80
81#[derive(Deserialize, Serialize, Debug, Clone)]
82pub struct ReferredProduct {
83    pub catalog_id: String,
84    pub product_retailer_id: String,
85}
86
87#[derive(Deserialize, Serialize, Debug, Clone)]
88pub struct Error {
89    pub code: i32,
90    pub title: String,
91    // TODO: Add more fields from v16.0 and newer
92}
93
94#[derive(Deserialize, Serialize, Debug, Clone)]
95#[serde(rename_all = "snake_case")]
96pub enum NotificationMessageType {
97    Audio,
98    Button,
99    Document,
100    Text,
101    Image,
102    Interactive,
103    Order,
104    Sticker,
105    System,
106    Unknown,
107    Video,
108    Unsupported,
109}
110
111#[derive(Deserialize, Serialize, Debug, Clone)]
112pub struct Audio {
113    pub id: String,
114    pub mime_type: String,
115}
116
117#[derive(Deserialize, Serialize, Debug, Clone)]
118pub struct Button {
119    pub payload: String,
120    pub text: String,
121}
122
123#[derive(Deserialize, Serialize, Debug, Clone)]
124pub struct Document {
125    pub caption: Option<String>,
126    pub filename: String,
127    pub sha256: String,
128    pub mime_type: String,
129    pub id: String,
130}
131
132#[derive(Deserialize, Serialize, Debug, Clone)]
133pub struct Image {
134    pub caption: Option<String>,
135    pub sha256: String,
136    pub id: String,
137    pub mime_type: Option<String>,
138}
139
140#[derive(Deserialize, Serialize, Debug, Clone)]
141pub struct Interactive {
142    pub button_reply: Option<ButtonReply>,
143    pub list_reply: Option<ListReply>,
144}
145
146#[derive(Deserialize, Serialize, Debug, Clone)]
147pub struct ButtonReply {
148    pub id: String,
149    pub title: String,
150}
151
152#[derive(Deserialize, Serialize, Debug, Clone)]
153pub struct ListReply {
154    pub id: String,
155    pub title: String,
156    pub description: Option<String>,
157}
158
159#[derive(Deserialize, Serialize, Debug, Clone)]
160pub struct Order {
161    pub catalog_id: String,
162    pub product_items: Vec<ProductItem>,
163}
164
165#[derive(Deserialize, Serialize, Debug, Clone)]
166pub struct ProductItem {
167    pub product_retailer_id: String,
168    pub quantity: String,
169    pub item_price: String,
170    pub currency: String,
171}
172
173#[derive(Deserialize, Serialize, Debug, Clone)]
174pub struct Sticker {
175    pub mime_type: String,
176    pub sha256: String,
177    pub id: String,
178    pub animated: Option<bool>,
179}
180
181#[derive(Deserialize, Serialize, Debug, Clone)]
182pub struct System {
183    pub body: String,
184    pub identity: String,
185    pub new_wa_id: Option<String>,
186    pub wa_id: Option<String>,
187    pub system_type: String,
188    pub customer: String,
189}
190
191#[derive(Deserialize, Serialize, Debug, Clone)]
192pub struct Text {
193    pub body: String,
194}
195
196#[derive(Deserialize, Serialize, Debug, Clone)]
197pub struct Video {
198    pub caption: Option<String>,
199    pub filename: String,
200    pub sha256: String,
201    pub id: String,
202    pub mime_type: String,
203}
204
205#[derive(Deserialize, Serialize, Debug, Clone)]
206pub struct Status {
207    pub biz_opaque_callback_data: Option<String>,
208    pub conversation: Option<Conversation>,
209    pub errors: Option<Vec<Error>>,
210    pub id: String,
211    pub pricing: Option<Pricing>,
212    pub recipient_id: String,
213    pub status: StatusCode,
214    pub timestamp: String,
215}
216
217#[derive(Deserialize, Serialize, Debug, Clone)]
218pub struct Conversation {
219    pub id: String,
220    pub origin: Origin,
221    // TODO: Other fields
222}
223
224#[derive(Deserialize, Serialize, Debug, Clone)]
225pub struct Origin {
226    #[serde(rename = "type")]
227    pub origin_type: String,
228}
229
230#[derive(Deserialize, Serialize, Debug, Clone)]
231pub struct Pricing {
232    pub pricing_model: String,
233    // TODO: Other fields
234}