meta-cloud-api 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,436 @@
1
+ /**
2
+ * Represents a message received through the webhook
3
+ * Based on Meta's documentation: https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/components#messages-object
4
+ */
5
+ interface WebhookMessage {
6
+ /**
7
+ * The message ID
8
+ */
9
+ id: string;
10
+ /**
11
+ * The sender's phone number
12
+ */
13
+ from: string;
14
+ /**
15
+ * The timestamp of the message
16
+ */
17
+ timestamp: string;
18
+ /**
19
+ * The type of message (text, image, etc.)
20
+ */
21
+ type: MessageType;
22
+ /**
23
+ * The phone number ID that received the message
24
+ */
25
+ phoneNumberId: string;
26
+ /**
27
+ * Text object for text messages
28
+ */
29
+ text?: {
30
+ /**
31
+ * The text content of the message
32
+ */
33
+ body: string;
34
+ };
35
+ /**
36
+ * Image object for image messages
37
+ */
38
+ image?: {
39
+ /**
40
+ * The image caption (if provided)
41
+ */
42
+ caption?: string;
43
+ /**
44
+ * The SHA256 hash of the image
45
+ */
46
+ sha256?: string;
47
+ /**
48
+ * The ID for the image
49
+ */
50
+ id: string;
51
+ /**
52
+ * The MIME type of the image
53
+ */
54
+ mime_type: string;
55
+ };
56
+ /**
57
+ * Video object for video messages
58
+ */
59
+ video?: {
60
+ /**
61
+ * The video caption (if provided)
62
+ */
63
+ caption?: string;
64
+ /**
65
+ * The SHA256 hash of the video
66
+ */
67
+ sha256?: string;
68
+ /**
69
+ * The ID for the video
70
+ */
71
+ id: string;
72
+ /**
73
+ * The MIME type of the video
74
+ */
75
+ mime_type: string;
76
+ };
77
+ /**
78
+ * Audio object for audio messages
79
+ */
80
+ audio?: {
81
+ /**
82
+ * The ID for the audio file
83
+ */
84
+ id: string;
85
+ /**
86
+ * The MIME type of the audio file
87
+ */
88
+ mime_type: string;
89
+ /**
90
+ * Whether the audio is a voice message
91
+ */
92
+ voice?: boolean;
93
+ };
94
+ /**
95
+ * Document object for document messages
96
+ */
97
+ document?: {
98
+ /**
99
+ * The document caption (if provided)
100
+ */
101
+ caption?: string;
102
+ /**
103
+ * The document filename
104
+ */
105
+ filename: string;
106
+ /**
107
+ * The SHA256 hash of the document
108
+ */
109
+ sha256?: string;
110
+ /**
111
+ * The ID for the document
112
+ */
113
+ id: string;
114
+ /**
115
+ * The MIME type of the document
116
+ */
117
+ mime_type: string;
118
+ };
119
+ /**
120
+ * Sticker object for sticker messages
121
+ */
122
+ sticker?: {
123
+ /**
124
+ * The ID for the sticker
125
+ */
126
+ id: string;
127
+ /**
128
+ * Whether this is an animated sticker
129
+ */
130
+ animated: boolean;
131
+ /**
132
+ * The MIME type of the sticker
133
+ */
134
+ mime_type: string;
135
+ };
136
+ /**
137
+ * Contacts object for contact messages
138
+ */
139
+ contacts?: Array<{
140
+ /**
141
+ * The contact's name
142
+ */
143
+ name: {
144
+ formatted_name: string;
145
+ first_name?: string;
146
+ last_name?: string;
147
+ middle_name?: string;
148
+ suffix?: string;
149
+ prefix?: string;
150
+ };
151
+ /**
152
+ * The contact's phone numbers
153
+ */
154
+ phones?: Array<{
155
+ phone: string;
156
+ type?: string;
157
+ wa_id?: string;
158
+ }>;
159
+ /**
160
+ * The contact's emails
161
+ */
162
+ emails?: Array<{
163
+ email: string;
164
+ type?: string;
165
+ }>;
166
+ /**
167
+ * The contact's addresses
168
+ */
169
+ addresses?: Array<{
170
+ street?: string;
171
+ city?: string;
172
+ state?: string;
173
+ zip?: string;
174
+ country?: string;
175
+ country_code?: string;
176
+ type?: string;
177
+ }>;
178
+ /**
179
+ * The contact's organizations
180
+ */
181
+ org?: {
182
+ company?: string;
183
+ department?: string;
184
+ title?: string;
185
+ };
186
+ /**
187
+ * The contact's URLs
188
+ */
189
+ urls?: Array<{
190
+ url: string;
191
+ type?: string;
192
+ }>;
193
+ /**
194
+ * The contact's birthday (YYYY-MM-DD format)
195
+ */
196
+ birthday?: string;
197
+ }>;
198
+ /**
199
+ * Location object for location messages
200
+ */
201
+ location?: {
202
+ /**
203
+ * Latitude of the location
204
+ */
205
+ latitude: number;
206
+ /**
207
+ * Longitude of the location
208
+ */
209
+ longitude: number;
210
+ /**
211
+ * Name of the location
212
+ */
213
+ name?: string;
214
+ /**
215
+ * Address of the location
216
+ */
217
+ address?: string;
218
+ };
219
+ /**
220
+ * Interactive object for interactive messages
221
+ */
222
+ interactive?: {
223
+ /**
224
+ * Type of the interactive message
225
+ */
226
+ type: string;
227
+ /**
228
+ * ID for the button that was clicked
229
+ */
230
+ button_reply?: {
231
+ id: string;
232
+ title: string;
233
+ };
234
+ /**
235
+ * ID for the list item that was selected
236
+ */
237
+ list_reply?: {
238
+ id: string;
239
+ title: string;
240
+ description?: string;
241
+ };
242
+ };
243
+ /**
244
+ * System object for system messages (like user phone number changes)
245
+ */
246
+ system?: {
247
+ /**
248
+ * The type of system update
249
+ */
250
+ type: string;
251
+ /**
252
+ * User's identity if the update is a customer identity change
253
+ */
254
+ identity?: string;
255
+ /**
256
+ * Old and new phone numbers if the update is a phone number change
257
+ */
258
+ customer?: {
259
+ /**
260
+ * The previous phone number
261
+ */
262
+ previous_wa_id: string;
263
+ /**
264
+ * The new phone number
265
+ */
266
+ wa_id: string;
267
+ };
268
+ };
269
+ /**
270
+ * Order object for order messages
271
+ */
272
+ order?: {
273
+ /**
274
+ * Catalog ID
275
+ */
276
+ catalog_id: string;
277
+ /**
278
+ * Product items in the order
279
+ */
280
+ product_items: Array<{
281
+ /**
282
+ * Product ID
283
+ */
284
+ product_retailer_id: string;
285
+ /**
286
+ * Quantity of the product
287
+ */
288
+ quantity: number;
289
+ /**
290
+ * Item price
291
+ */
292
+ item_price: number;
293
+ /**
294
+ * Currency code
295
+ */
296
+ currency: string;
297
+ }>;
298
+ /**
299
+ * Text message included with the order
300
+ */
301
+ text?: string;
302
+ };
303
+ /**
304
+ * Context object, included when a user replies or interacts
305
+ */
306
+ context?: {
307
+ /**
308
+ * ID of the message being replied to or interacted with
309
+ */
310
+ message_id: string;
311
+ /**
312
+ * ID of the forwarded message, if applicable
313
+ */
314
+ forwarded?: boolean;
315
+ /**
316
+ * Frequently forwarded status
317
+ */
318
+ frequently_forwarded?: boolean;
319
+ /**
320
+ * Original message information if the message was referred
321
+ */
322
+ referred_product?: {
323
+ /**
324
+ * Catalog ID
325
+ */
326
+ catalog_id: string;
327
+ /**
328
+ * Product ID
329
+ */
330
+ product_retailer_id: string;
331
+ };
332
+ };
333
+ /**
334
+ * Errors array, if the message had errors
335
+ */
336
+ errors?: Array<{
337
+ /**
338
+ * Error code
339
+ */
340
+ code: number;
341
+ /**
342
+ * Error title
343
+ */
344
+ title: string;
345
+ /**
346
+ * Error message
347
+ */
348
+ message: string;
349
+ /**
350
+ * Error details object
351
+ */
352
+ error_data?: {
353
+ /**
354
+ * Describes the error details
355
+ */
356
+ details: string;
357
+ };
358
+ }>;
359
+ /**
360
+ * Button object for button messages
361
+ */
362
+ button?: {
363
+ /**
364
+ * The payload for the button
365
+ */
366
+ payload: string;
367
+ /**
368
+ * Button text
369
+ */
370
+ text: string;
371
+ };
372
+ /**
373
+ * The original message data as received from the webhook
374
+ */
375
+ originalData: any;
376
+ }
377
+ /**
378
+ * Represents a non-message event received through the webhook
379
+ */
380
+ interface WebhookEvent {
381
+ /**
382
+ * The field type of the event
383
+ */
384
+ field: string;
385
+ /**
386
+ * The event data
387
+ */
388
+ value: any;
389
+ }
390
+ /**
391
+ * Handler function for processing messages
392
+ */
393
+ type MessageHandler = (message: WebhookMessage) => void | Promise<void>;
394
+ /**
395
+ * Handler function for processing events
396
+ */
397
+ type EventHandler = (event: WebhookEvent) => void | Promise<void>;
398
+ /**
399
+ * Message types that can be received through the webhook
400
+ */
401
+ declare enum MessageType {
402
+ TEXT = "text",
403
+ IMAGE = "image",
404
+ AUDIO = "audio",
405
+ VIDEO = "video",
406
+ DOCUMENT = "document",
407
+ STICKER = "sticker",
408
+ LOCATION = "location",
409
+ CONTACTS = "contacts",
410
+ BUTTON = "button",
411
+ INTERACTIVE = "interactive",
412
+ ORDER = "order",
413
+ SYSTEM = "system",
414
+ UNKNOWN = "unknown"
415
+ }
416
+ /**
417
+ * Statuses that can be received in status updates
418
+ */
419
+ declare enum MessageStatus {
420
+ DELIVERED = "delivered",
421
+ READ = "read",
422
+ SENT = "sent"
423
+ }
424
+ /**
425
+ * Event fields that can be received through the webhook
426
+ */
427
+ declare enum EventField {
428
+ MESSAGES = "messages",
429
+ STATUSES = "statuses",
430
+ MESSAGE_TEMPLATE_STATUS_UPDATE = "message_template_status_update",
431
+ PHONE_NUMBER_QUALITY_UPDATE = "phone_number_quality_update",
432
+ PHONE_NUMBER_NAME_UPDATE = "phone_number_name_update",
433
+ UNKNOWN = "unknown"
434
+ }
435
+
436
+ export { EventField, type EventHandler, type MessageHandler, MessageStatus, MessageType, type WebhookEvent, type WebhookMessage };