meta-cloud-api 0.2.18 → 0.2.19

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.
Files changed (52) hide show
  1. package/dist/{BusinessProfileApi-DDkv2WQK.d.ts → BusinessProfileApi-BjOyDR-8.d.ts} +3 -3
  2. package/dist/{EncryptionApi-CwxQlC-2.d.ts → EncryptionApi-B3hzgZwc.d.ts} +1 -1
  3. package/dist/{FlowApi-BIBrWYEv.d.ts → FlowApi-OEAji2dP.d.ts} +2 -2
  4. package/dist/{MediaApi-VqxndaBJ.d.ts → MediaApi-C2-eC3BR.d.ts} +1 -1
  5. package/dist/{MessageApi-CHc6bn3g.d.ts → MessageApi-BQhqbAOY.d.ts} +2 -2
  6. package/dist/{PhoneNumberApi-C-bs6YAe.d.ts → PhoneNumberApi-BgfYrui-.d.ts} +2 -2
  7. package/dist/{QrCodeApi-BjlyPUXV.d.ts → QrCodeApi-CimaUuYP.d.ts} +1 -1
  8. package/dist/{RegistrationApi-D7Bg8BUz.d.ts → RegistrationApi-BSDXRJlL.d.ts} +2 -2
  9. package/dist/{TemplateApi-dmZbvMkO.d.ts → TemplateApi-B7dTBIlN.d.ts} +3 -3
  10. package/dist/{TwoStepVerificationApi-DaYWPjY_.d.ts → TwoStepVerificationApi-BY0eD8R2.d.ts} +1 -1
  11. package/dist/{WabaApi-CMoTCWiH.d.ts → WabaApi-BFbVUUlw.d.ts} +1 -1
  12. package/dist/{base-BG2gtoDs.d.ts → base-B4QLc9vb.d.ts} +2 -2
  13. package/dist/chunk-34SVEEB7.js +3 -0
  14. package/dist/chunk-34SVEEB7.js.map +1 -0
  15. package/dist/chunk-BSNA6RYF.js +3 -0
  16. package/dist/chunk-BSNA6RYF.js.map +1 -0
  17. package/dist/{chunk-FFOE5YKT.js → chunk-GT3XQN7Y.js} +2 -2
  18. package/dist/chunk-GT3XQN7Y.js.map +1 -0
  19. package/dist/chunk-H55VIWDI.js +2 -0
  20. package/dist/chunk-H55VIWDI.js.map +1 -0
  21. package/dist/chunk-I222VSWK.js +2 -0
  22. package/dist/chunk-I222VSWK.js.map +1 -0
  23. package/dist/{chunk-XIIJD6SG.js → chunk-R36L2XYO.js} +2 -2
  24. package/dist/chunk-R36L2XYO.js.map +1 -0
  25. package/dist/core/webhook/index.d.ts +630 -0
  26. package/dist/core/webhook/index.js +2 -0
  27. package/dist/core/webhook/index.js.map +1 -0
  28. package/dist/core/whatsapp/index.d.ts +100 -0
  29. package/dist/core/whatsapp/index.js +2 -0
  30. package/dist/core/whatsapp/index.js.map +1 -0
  31. package/dist/{enums-Z1f7QuVx.d.ts → enums-CL4CRQAe.d.ts} +1 -1
  32. package/dist/features/encryption/index.d.ts +4 -4
  33. package/dist/features/flow/index.d.ts +4 -4
  34. package/dist/features/media/index.d.ts +4 -4
  35. package/dist/features/messages/index.d.ts +4 -4
  36. package/dist/features/phone/index.d.ts +4 -4
  37. package/dist/features/profile/index.d.ts +4 -4
  38. package/dist/features/qrCode/index.d.ts +4 -4
  39. package/dist/features/qrCode/index.js +1 -1
  40. package/dist/features/registration/index.d.ts +4 -4
  41. package/dist/features/template/index.d.ts +4 -4
  42. package/dist/features/template/index.js +1 -1
  43. package/dist/features/twoStepVerification/index.d.ts +4 -4
  44. package/dist/features/waba/index.d.ts +4 -4
  45. package/dist/index.d.ts +18 -674
  46. package/dist/index.js +1 -2
  47. package/dist/index.js.map +1 -1
  48. package/dist/shared/types/config.d.ts +1 -1
  49. package/dist/shared/types/enums.d.ts +1 -1
  50. package/package.json +1 -1
  51. package/dist/chunk-FFOE5YKT.js.map +0 -1
  52. package/dist/chunk-XIIJD6SG.js.map +0 -1
@@ -0,0 +1,630 @@
1
+ import { M as MessageTypesEnum } from '../../enums-CL4CRQAe.js';
2
+ import { WhatsAppConfig } from '../../shared/types/config.js';
3
+ import { IncomingMessage } from 'http';
4
+ import { f as FlowEndpointRequest, m as FlowTypeEnum } from '../../FlowApi-OEAji2dP.js';
5
+ import { WhatsApp } from '../whatsapp/index.js';
6
+ import '../../base-B4QLc9vb.js';
7
+ import '../../MessageApi-BQhqbAOY.js';
8
+ import '../../MediaApi-C2-eC3BR.js';
9
+ import '../../BusinessProfileApi-BjOyDR-8.js';
10
+ import '../../EncryptionApi-B3hzgZwc.js';
11
+ import '../../PhoneNumberApi-BgfYrui-.js';
12
+ import '../../RegistrationApi-BSDXRJlL.js';
13
+ import '../../TemplateApi-B7dTBIlN.js';
14
+ import '../../QrCodeApi-CimaUuYP.js';
15
+ import '../../TwoStepVerificationApi-BY0eD8R2.js';
16
+ import '../../WabaApi-BFbVUUlw.js';
17
+ import 'https';
18
+
19
+ interface WebhookContact {
20
+ /**
21
+ * WhatsApp ID of the contact. Business can respond to this contact using this ID.
22
+ */
23
+ wa_id: string;
24
+ /**
25
+ * Additional unique, alphanumeric identifier for a WhatsApp user
26
+ */
27
+ user_id?: string;
28
+ /**
29
+ * Profile of Whatsapp user
30
+ */
31
+ profile: {
32
+ /**
33
+ * The display name of the contact
34
+ */
35
+ name: string;
36
+ };
37
+ }
38
+ /**
39
+ * Represents a message received through the webhook
40
+ * Based on Meta's documentation: https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/components#messages-object
41
+ */
42
+ interface WebhookMessage {
43
+ /**
44
+ * The message ID
45
+ */
46
+ id: string;
47
+ /**
48
+ * The sender's phone number
49
+ */
50
+ from: string;
51
+ /**
52
+ * The timestamp of the message
53
+ */
54
+ timestamp: string;
55
+ /**
56
+ * The type of message (text, image, etc.)
57
+ */
58
+ type: MessageTypesEnum;
59
+ /**
60
+ * The phone number ID that received the message
61
+ */
62
+ phoneNumberId: string;
63
+ /**
64
+ * The display phone number that received the message
65
+ */
66
+ displayPhoneNumber: string;
67
+ /**
68
+ * The profile name of the sender
69
+ */
70
+ profileName: string;
71
+ /**
72
+ * Text object for text messages
73
+ */
74
+ text?: {
75
+ /**
76
+ * The text content of the message
77
+ */
78
+ body: string;
79
+ };
80
+ /**
81
+ * Image object for image messages
82
+ */
83
+ image?: {
84
+ /**
85
+ * The image caption (if provided)
86
+ */
87
+ caption?: string;
88
+ /**
89
+ * The SHA256 hash of the image
90
+ */
91
+ sha256?: string;
92
+ /**
93
+ * The ID for the image
94
+ */
95
+ id: string;
96
+ /**
97
+ * The MIME type of the image
98
+ */
99
+ mime_type: string;
100
+ };
101
+ /**
102
+ * Video object for video messages
103
+ */
104
+ video?: {
105
+ /**
106
+ * The video caption (if provided)
107
+ */
108
+ caption?: string;
109
+ /**
110
+ * The SHA256 hash of the video
111
+ */
112
+ sha256?: string;
113
+ /**
114
+ * The ID for the video
115
+ */
116
+ id: string;
117
+ /**
118
+ * The MIME type of the video
119
+ */
120
+ mime_type: string;
121
+ };
122
+ /**
123
+ * Audio object for audio messages
124
+ */
125
+ audio?: {
126
+ /**
127
+ * The ID for the audio file
128
+ */
129
+ id: string;
130
+ /**
131
+ * The MIME type of the audio file
132
+ */
133
+ mime_type: string;
134
+ /**
135
+ * Whether the audio is a voice message
136
+ */
137
+ voice?: boolean;
138
+ };
139
+ /**
140
+ * Document object for document messages
141
+ */
142
+ document?: {
143
+ /**
144
+ * The document caption (if provided)
145
+ */
146
+ caption?: string;
147
+ /**
148
+ * The document filename
149
+ */
150
+ filename: string;
151
+ /**
152
+ * The SHA256 hash of the document
153
+ */
154
+ sha256?: string;
155
+ /**
156
+ * The ID for the document
157
+ */
158
+ id: string;
159
+ /**
160
+ * The MIME type of the document
161
+ */
162
+ mime_type: string;
163
+ };
164
+ /**
165
+ * Sticker object for sticker messages
166
+ */
167
+ sticker?: {
168
+ /**
169
+ * The ID for the sticker
170
+ */
171
+ id: string;
172
+ /**
173
+ * Whether this is an animated sticker
174
+ */
175
+ animated: boolean;
176
+ /**
177
+ * The MIME type of the sticker
178
+ */
179
+ mime_type: string;
180
+ };
181
+ /**
182
+ * Reaction object for reaction messages
183
+ */
184
+ reaction?: {
185
+ /**
186
+ * The ID of the message being reacted to
187
+ */
188
+ message_id: string;
189
+ /**
190
+ * Emoji used for the reaction
191
+ */
192
+ emoji: string;
193
+ };
194
+ /**
195
+ * Contacts object for contact messages
196
+ */
197
+ contacts?: Array<{
198
+ /**
199
+ * The contact's name
200
+ */
201
+ name: {
202
+ /**
203
+ * The formatted name
204
+ */
205
+ formatted_name: string;
206
+ /**
207
+ * The first name
208
+ */
209
+ first_name?: string;
210
+ /**
211
+ * The last name
212
+ */
213
+ last_name?: string;
214
+ /**
215
+ * The middle name
216
+ */
217
+ middle_name?: string;
218
+ /**
219
+ * The suffix
220
+ */
221
+ suffix?: string;
222
+ /**
223
+ * The prefix
224
+ */
225
+ prefix?: string;
226
+ };
227
+ /**
228
+ * The contact's phone numbers
229
+ */
230
+ phones?: Array<{
231
+ phone: string;
232
+ type?: string;
233
+ wa_id?: string;
234
+ }>;
235
+ /**
236
+ * The contact's emails
237
+ */
238
+ emails?: Array<{
239
+ email: string;
240
+ type?: string;
241
+ }>;
242
+ /**
243
+ * The contact's addresses
244
+ */
245
+ addresses?: Array<{
246
+ street?: string;
247
+ city?: string;
248
+ state?: string;
249
+ zip?: string;
250
+ country?: string;
251
+ country_code?: string;
252
+ type?: string;
253
+ }>;
254
+ /**
255
+ * The contact's organizations
256
+ */
257
+ org?: {
258
+ company?: string;
259
+ department?: string;
260
+ title?: string;
261
+ };
262
+ /**
263
+ * The contact's URLs
264
+ */
265
+ urls?: Array<{
266
+ url: string;
267
+ type?: string;
268
+ }>;
269
+ /**
270
+ * The contact's birthday (YYYY-MM-DD format)
271
+ */
272
+ birthday?: string;
273
+ }>;
274
+ /**
275
+ * Location object for location messages
276
+ */
277
+ location?: {
278
+ /**
279
+ * Latitude of the location
280
+ */
281
+ latitude: number;
282
+ /**
283
+ * Longitude of the location
284
+ */
285
+ longitude: number;
286
+ /**
287
+ * Name of the location
288
+ */
289
+ name?: string;
290
+ /**
291
+ * Address of the location
292
+ */
293
+ address?: string;
294
+ };
295
+ /**
296
+ * Interactive object for interactive messages
297
+ */
298
+ interactive?: {
299
+ /**
300
+ * Type of the interactive message
301
+ * Can be: button_reply, list_reply, flow, nfm_reply, etc.
302
+ */
303
+ type: string;
304
+ /**
305
+ * ID for the button that was clicked
306
+ */
307
+ button_reply?: {
308
+ id: string;
309
+ title: string;
310
+ };
311
+ /**
312
+ * ID for the list item that was selected
313
+ */
314
+ list_reply?: {
315
+ id: string;
316
+ title: string;
317
+ description?: string;
318
+ };
319
+ /**
320
+ * NFM (No-Code Flow Message) reply data
321
+ */
322
+ nfm_reply?: {
323
+ /**
324
+ * Response data in JSON format
325
+ */
326
+ response_json: string;
327
+ /**
328
+ * Body text of the reply
329
+ */
330
+ body: string;
331
+ /**
332
+ * Name of the flow
333
+ */
334
+ name: string;
335
+ };
336
+ };
337
+ /**
338
+ * System object for system messages (like user phone number changes)
339
+ */
340
+ system?: {
341
+ /**
342
+ * The type of system update
343
+ */
344
+ type: string;
345
+ /**
346
+ * User's identity if the update is a customer identity change
347
+ */
348
+ identity?: string;
349
+ /**
350
+ * Old and new phone numbers if the update is a phone number change
351
+ */
352
+ customer?: {
353
+ /**
354
+ * The previous phone number
355
+ */
356
+ previous_wa_id: string;
357
+ /**
358
+ * The new phone number
359
+ */
360
+ wa_id: string;
361
+ };
362
+ };
363
+ /**
364
+ * Order object for order messages
365
+ */
366
+ order?: {
367
+ /**
368
+ * Catalog ID
369
+ */
370
+ catalog_id: string;
371
+ /**
372
+ * Product items in the order
373
+ */
374
+ product_items: Array<{
375
+ /**
376
+ * Product ID
377
+ */
378
+ product_retailer_id: string;
379
+ /**
380
+ * Quantity of the product
381
+ */
382
+ quantity: number;
383
+ /**
384
+ * Item price
385
+ */
386
+ item_price: number;
387
+ /**
388
+ * Currency code
389
+ */
390
+ currency: string;
391
+ }>;
392
+ /**
393
+ * Text message included with the order
394
+ */
395
+ text?: string;
396
+ };
397
+ /**
398
+ * Context object, included when a user replies or interacts
399
+ */
400
+ context?: {
401
+ /**
402
+ * ID of the message
403
+ */
404
+ id?: string;
405
+ /**
406
+ * ID of the sender
407
+ */
408
+ from?: string;
409
+ /**
410
+ * ID of the message being replied to or interacted with
411
+ */
412
+ message_id: string;
413
+ /**
414
+ * ID of the forwarded message, if applicable
415
+ */
416
+ forwarded?: boolean;
417
+ /**
418
+ * Frequently forwarded status
419
+ */
420
+ frequently_forwarded?: boolean;
421
+ /**
422
+ * Original message information if the message was referred
423
+ */
424
+ referred_product?: {
425
+ /**
426
+ * Catalog ID
427
+ */
428
+ catalog_id: string;
429
+ /**
430
+ * Product ID
431
+ */
432
+ product_retailer_id: string;
433
+ };
434
+ };
435
+ /**
436
+ * Errors array, if the message had errors
437
+ */
438
+ errors?: Array<{
439
+ /**
440
+ * Error code
441
+ */
442
+ code: number;
443
+ /**
444
+ * Error title
445
+ */
446
+ title: string;
447
+ /**
448
+ * Error message
449
+ */
450
+ message: string;
451
+ /**
452
+ * Error details object
453
+ */
454
+ error_data?: {
455
+ /**
456
+ * Describes the error details
457
+ */
458
+ details: string;
459
+ };
460
+ }>;
461
+ /**
462
+ * Button object for button messages
463
+ */
464
+ button?: {
465
+ /**
466
+ * The payload for the button
467
+ */
468
+ payload: string;
469
+ /**
470
+ * Button text
471
+ */
472
+ text: string;
473
+ };
474
+ /**
475
+ * The original message data as received from the webhook
476
+ */
477
+ originalData: any;
478
+ }
479
+ /**
480
+ * Webhook event received from WhatsApp
481
+ */
482
+ interface WebhookEvent {
483
+ /**
484
+ * The field type of the event
485
+ */
486
+ field: string;
487
+ /**
488
+ * The event data
489
+ */
490
+ value: any;
491
+ /**
492
+ * The timestamp when the event was received
493
+ */
494
+ timestamp: number;
495
+ }
496
+ /**
497
+ * Message handler function type
498
+ */
499
+ type MessageHandler = (message: WebhookMessage) => void | Promise<void>;
500
+ /**
501
+ * Event handler function type
502
+ */
503
+ type EventHandler = (event: WebhookEvent) => void | Promise<void>;
504
+ /**
505
+ * Message status enum
506
+ */
507
+ declare enum MessageStatus {
508
+ DELIVERED = "delivered",
509
+ READ = "read",
510
+ SENT = "sent"
511
+ }
512
+ /**
513
+ * Event field enum for webhook events
514
+ */
515
+ declare enum EventField {
516
+ MESSAGES = "messages",
517
+ STATUSES = "statuses",
518
+ MESSAGE_TEMPLATE_STATUS_UPDATE = "message_template_status_update",
519
+ PHONE_NUMBER_QUALITY_UPDATE = "phone_number_quality_update",
520
+ PHONE_NUMBER_NAME_UPDATE = "phone_number_name_update",
521
+ UNKNOWN = "unknown"
522
+ }
523
+
524
+ interface IRequest extends IncomingMessage {
525
+ body: any;
526
+ query: Record<string, any>;
527
+ method?: string;
528
+ }
529
+ interface IResponse {
530
+ status: (code: number) => IResponse;
531
+ send: (body: any) => IResponse | void;
532
+ json: (body: any) => IResponse | void;
533
+ end: () => void;
534
+ }
535
+ /**
536
+ * Webhook handler for WhatsApp Cloud API
537
+ */
538
+ declare class WebhookHandler {
539
+ private config;
540
+ private client;
541
+ private messageHandlers;
542
+ private eventHandlers;
543
+ private preProcessHandler;
544
+ private postProcessHandler;
545
+ private flowHandlers;
546
+ /**
547
+ * Create a new WebhookHandler
548
+ * @param config The WhatsApp configuration
549
+ */
550
+ constructor(config: WhatsAppConfig);
551
+ /**
552
+ * Handle a GET request for webhook verification
553
+ */
554
+ handleVerificationRequest<Req extends IRequest, Res extends IResponse>(req: Req, res: Res): void;
555
+ handleVerificationRequest<Req extends IRequest>(req: Req): string;
556
+ /**
557
+ * Handle a POST request for webhook events
558
+ */
559
+ handleWebhookRequest<Req extends IRequest, Res extends IResponse>(req: Req, res: Res): Promise<void>;
560
+ handleWebhookRequest<Req extends IRequest>(req: Req): Promise<{
561
+ success: boolean;
562
+ errors?: string[];
563
+ }>;
564
+ /**
565
+ * Handle webhook requests (both verification and events)
566
+ */
567
+ handleRequest<Req extends IRequest, Res extends IResponse>(req: Req, res: Res): void | Promise<void>;
568
+ handleRequest<Req extends IRequest>(req: Req): string | Promise<{
569
+ success: boolean;
570
+ errors?: string[];
571
+ }>;
572
+ /**
573
+ * Process incoming messages
574
+ */
575
+ private processMessages;
576
+ /**
577
+ * Process other webhook events
578
+ */
579
+ private processEvent;
580
+ /**
581
+ * Register a message handler for a specific message type
582
+ */
583
+ onMessage(type: MessageTypesEnum, handler: (whatsapp: WhatsApp, message: WebhookMessage) => void | Promise<void>): void;
584
+ /**
585
+ * Register an event handler for a specific field
586
+ */
587
+ onEvent(field: string, handler: (event: WebhookEvent) => void | Promise<void>): void;
588
+ /**
589
+ * Register a pre-process handler that runs before all message handlers
590
+ */
591
+ onMessagePreProcess(handler: (whatsapp: WhatsApp, message: WebhookMessage) => void | Promise<void>): void;
592
+ /**
593
+ * Register a post-process handler that runs after all message handlers
594
+ */
595
+ onMessagePostProcess(handler: (whatsapp: WhatsApp, message: WebhookMessage) => void | Promise<void>): void;
596
+ handleFlowRequest<Req extends IRequest & {
597
+ rawBody: string;
598
+ }, Res extends IResponse>(req: Req, res: Res): Promise<void>;
599
+ handleFlowRequest<Req extends IRequest & {
600
+ rawBody: string;
601
+ }>(req: Req): Promise<{
602
+ statusCode: number;
603
+ body: any;
604
+ headers?: Record<string, string>;
605
+ }>;
606
+ /**
607
+ * Validate the request signature
608
+ */
609
+ isRequestSignatureValid(req: IRequest & {
610
+ rawBody: string;
611
+ }): boolean;
612
+ /**
613
+ * Decrypt a flow request
614
+ */
615
+ decryptRequest(body: any): {
616
+ decryptedBody: FlowEndpointRequest;
617
+ aesKeyBuffer: Buffer;
618
+ initialVectorBuffer: Buffer;
619
+ };
620
+ /**
621
+ * Encrypt a flow response
622
+ */
623
+ private encryptResponse;
624
+ /**
625
+ * Register a flow handler for a specific flow type
626
+ */
627
+ onFlow(type: FlowTypeEnum, handler: (whatsapp: WhatsApp, request: FlowEndpointRequest) => any | Promise<any>): void;
628
+ }
629
+
630
+ export { EventField, type EventHandler, type IRequest, type IResponse, type MessageHandler, MessageStatus, type WebhookContact, type WebhookEvent, WebhookHandler, type WebhookMessage };
@@ -0,0 +1,2 @@
1
+ export{b as EventField,a as MessageStatus,c as WebhookHandler}from'../../chunk-34SVEEB7.js';import'../../chunk-BSNA6RYF.js';import'../../chunk-3MO3BTBC.js';import'../../chunk-R36L2XYO.js';import'../../chunk-GT3XQN7Y.js';import'../../chunk-O2OTHNWM.js';import'../../chunk-7NQLQPLH.js';import'../../chunk-UQPD6GIF.js';import'../../chunk-5JGM556C.js';import'../../chunk-2NJVBJUN.js';import'../../chunk-XPPDOFBN.js';import'../../chunk-KFPOVYEJ.js';import'../../chunk-7GL74SXM.js';import'../../chunk-A264MT4Q.js';import'../../chunk-GIQLIMOD.js';import'../../chunk-BZ5QDXNR.js';import'../../chunk-VW3LGHTJ.js';import'../../chunk-EYGUX4EA.js';import'../../chunk-4C666HHU.js';//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}