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 };
@@ -0,0 +1,2 @@
1
+ "use strict";var a=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var p=(i,r)=>{for(var o in r)a(i,o,{get:r[o],enumerable:!0})},l=(i,r,o,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of u(r))!c.call(i,s)&&s!==o&&a(i,s,{get:()=>r[s],enumerable:!(n=_(r,s))||n.enumerable});return i};var y=i=>l(a({},"__esModule",{value:!0}),i);var E={};p(E,{EventField:()=>m,MessageStatus:()=>d,MessageType:()=>g});module.exports=y(E);var g=(t=>(t.TEXT="text",t.IMAGE="image",t.AUDIO="audio",t.VIDEO="video",t.DOCUMENT="document",t.STICKER="sticker",t.LOCATION="location",t.CONTACTS="contacts",t.BUTTON="button",t.INTERACTIVE="interactive",t.ORDER="order",t.SYSTEM="system",t.UNKNOWN="unknown",t))(g||{}),d=(n=>(n.DELIVERED="delivered",n.READ="read",n.SENT="sent",n))(d||{}),m=(e=>(e.MESSAGES="messages",e.STATUSES="statuses",e.MESSAGE_TEMPLATE_STATUS_UPDATE="message_template_status_update",e.PHONE_NUMBER_QUALITY_UPDATE="phone_number_quality_update",e.PHONE_NUMBER_NAME_UPDATE="phone_number_name_update",e.UNKNOWN="unknown",e))(m||{});0&&(module.exports={EventField,MessageStatus,MessageType});
2
+ //# sourceMappingURL=webhook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/webhook.ts"],"sourcesContent":["/**\n * Represents a message received through the webhook\n * Based on Meta's documentation: https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/components#messages-object\n */\nexport interface WebhookMessage {\n /**\n * The message ID\n */\n id: string;\n\n /**\n * The sender's phone number\n */\n from: string;\n\n /**\n * The timestamp of the message\n */\n timestamp: string;\n\n /**\n * The type of message (text, image, etc.)\n */\n type: MessageType;\n\n /**\n * The phone number ID that received the message\n */\n phoneNumberId: string;\n\n /**\n * Text object for text messages\n */\n text?: {\n /**\n * The text content of the message\n */\n body: string;\n };\n\n /**\n * Image object for image messages\n */\n image?: {\n /**\n * The image caption (if provided)\n */\n caption?: string;\n /**\n * The SHA256 hash of the image\n */\n sha256?: string;\n /**\n * The ID for the image\n */\n id: string;\n /**\n * The MIME type of the image\n */\n mime_type: string;\n };\n\n /**\n * Video object for video messages\n */\n video?: {\n /**\n * The video caption (if provided)\n */\n caption?: string;\n /**\n * The SHA256 hash of the video\n */\n sha256?: string;\n /**\n * The ID for the video\n */\n id: string;\n /**\n * The MIME type of the video\n */\n mime_type: string;\n };\n\n /**\n * Audio object for audio messages\n */\n audio?: {\n /**\n * The ID for the audio file\n */\n id: string;\n /**\n * The MIME type of the audio file\n */\n mime_type: string;\n /**\n * Whether the audio is a voice message\n */\n voice?: boolean;\n };\n\n /**\n * Document object for document messages\n */\n document?: {\n /**\n * The document caption (if provided)\n */\n caption?: string;\n /**\n * The document filename\n */\n filename: string;\n /**\n * The SHA256 hash of the document\n */\n sha256?: string;\n /**\n * The ID for the document\n */\n id: string;\n /**\n * The MIME type of the document\n */\n mime_type: string;\n };\n\n /**\n * Sticker object for sticker messages\n */\n sticker?: {\n /**\n * The ID for the sticker\n */\n id: string;\n /**\n * Whether this is an animated sticker\n */\n animated: boolean;\n /**\n * The MIME type of the sticker\n */\n mime_type: string;\n };\n\n /**\n * Contacts object for contact messages\n */\n contacts?: Array<{\n /**\n * The contact's name\n */\n name: {\n formatted_name: string;\n first_name?: string;\n last_name?: string;\n middle_name?: string;\n suffix?: string;\n prefix?: string;\n };\n /**\n * The contact's phone numbers\n */\n phones?: Array<{\n phone: string;\n type?: string;\n wa_id?: string;\n }>;\n /**\n * The contact's emails\n */\n emails?: Array<{\n email: string;\n type?: string;\n }>;\n /**\n * The contact's addresses\n */\n addresses?: Array<{\n street?: string;\n city?: string;\n state?: string;\n zip?: string;\n country?: string;\n country_code?: string;\n type?: string;\n }>;\n /**\n * The contact's organizations\n */\n org?: {\n company?: string;\n department?: string;\n title?: string;\n };\n /**\n * The contact's URLs\n */\n urls?: Array<{\n url: string;\n type?: string;\n }>;\n /**\n * The contact's birthday (YYYY-MM-DD format)\n */\n birthday?: string;\n }>;\n\n /**\n * Location object for location messages\n */\n location?: {\n /**\n * Latitude of the location\n */\n latitude: number;\n /**\n * Longitude of the location\n */\n longitude: number;\n /**\n * Name of the location\n */\n name?: string;\n /**\n * Address of the location\n */\n address?: string;\n };\n\n /**\n * Interactive object for interactive messages\n */\n interactive?: {\n /**\n * Type of the interactive message\n */\n type: string;\n /**\n * ID for the button that was clicked\n */\n button_reply?: {\n id: string;\n title: string;\n };\n /**\n * ID for the list item that was selected\n */\n list_reply?: {\n id: string;\n title: string;\n description?: string;\n };\n };\n\n /**\n * System object for system messages (like user phone number changes)\n */\n system?: {\n /**\n * The type of system update\n */\n type: string;\n /**\n * User's identity if the update is a customer identity change\n */\n identity?: string;\n /**\n * Old and new phone numbers if the update is a phone number change\n */\n customer?: {\n /**\n * The previous phone number\n */\n previous_wa_id: string;\n /**\n * The new phone number\n */\n wa_id: string;\n };\n };\n\n /**\n * Order object for order messages\n */\n order?: {\n /**\n * Catalog ID\n */\n catalog_id: string;\n /**\n * Product items in the order\n */\n product_items: Array<{\n /**\n * Product ID\n */\n product_retailer_id: string;\n /**\n * Quantity of the product\n */\n quantity: number;\n /**\n * Item price\n */\n item_price: number;\n /**\n * Currency code\n */\n currency: string;\n }>;\n /**\n * Text message included with the order\n */\n text?: string;\n };\n\n /**\n * Context object, included when a user replies or interacts\n */\n context?: {\n /**\n * ID of the message being replied to or interacted with\n */\n message_id: string;\n /**\n * ID of the forwarded message, if applicable\n */\n forwarded?: boolean;\n /**\n * Frequently forwarded status\n */\n frequently_forwarded?: boolean;\n /**\n * Original message information if the message was referred\n */\n referred_product?: {\n /**\n * Catalog ID\n */\n catalog_id: string;\n /**\n * Product ID\n */\n product_retailer_id: string;\n };\n };\n\n /**\n * Errors array, if the message had errors\n */\n errors?: Array<{\n /**\n * Error code\n */\n code: number;\n /**\n * Error title\n */\n title: string;\n /**\n * Error message\n */\n message: string;\n /**\n * Error details object\n */\n error_data?: {\n /**\n * Describes the error details\n */\n details: string;\n };\n }>;\n\n /**\n * Button object for button messages\n */\n button?: {\n /**\n * The payload for the button\n */\n payload: string;\n /**\n * Button text\n */\n text: string;\n };\n\n /**\n * The original message data as received from the webhook\n */\n originalData: any;\n}\n\n/**\n * Represents a non-message event received through the webhook\n */\nexport interface WebhookEvent {\n /**\n * The field type of the event\n */\n field: string;\n\n /**\n * The event data\n */\n value: any;\n}\n\n/**\n * Handler function for processing messages\n */\nexport type MessageHandler = (message: WebhookMessage) => void | Promise<void>;\n\n/**\n * Handler function for processing events\n */\nexport type EventHandler = (event: WebhookEvent) => void | Promise<void>;\n\n/**\n * Message types that can be received through the webhook\n */\nexport enum MessageType {\n TEXT = 'text',\n IMAGE = 'image',\n AUDIO = 'audio',\n VIDEO = 'video',\n DOCUMENT = 'document',\n STICKER = 'sticker',\n LOCATION = 'location',\n CONTACTS = 'contacts',\n BUTTON = 'button',\n INTERACTIVE = 'interactive',\n ORDER = 'order',\n SYSTEM = 'system',\n UNKNOWN = 'unknown',\n}\n\n/**\n * Statuses that can be received in status updates\n */\nexport enum MessageStatus {\n DELIVERED = 'delivered',\n READ = 'read',\n SENT = 'sent',\n}\n\n/**\n * Event fields that can be received through the webhook\n */\nexport enum EventField {\n MESSAGES = 'messages',\n STATUSES = 'statuses',\n MESSAGE_TEMPLATE_STATUS_UPDATE = 'message_template_status_update',\n PHONE_NUMBER_QUALITY_UPDATE = 'phone_number_quality_update',\n PHONE_NUMBER_NAME_UPDATE = 'phone_number_name_update',\n UNKNOWN = 'unknown',\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,kBAAAC,EAAA,gBAAAC,IAAA,eAAAC,EAAAL,GAwaO,IAAKI,OACRA,EAAA,KAAO,OACPA,EAAA,MAAQ,QACRA,EAAA,MAAQ,QACRA,EAAA,MAAQ,QACRA,EAAA,SAAW,WACXA,EAAA,QAAU,UACVA,EAAA,SAAW,WACXA,EAAA,SAAW,WACXA,EAAA,OAAS,SACTA,EAAA,YAAc,cACdA,EAAA,MAAQ,QACRA,EAAA,OAAS,SACTA,EAAA,QAAU,UAbFA,OAAA,IAmBAD,OACRA,EAAA,UAAY,YACZA,EAAA,KAAO,OACPA,EAAA,KAAO,OAHCA,OAAA,IASAD,OACRA,EAAA,SAAW,WACXA,EAAA,SAAW,WACXA,EAAA,+BAAiC,iCACjCA,EAAA,4BAA8B,8BAC9BA,EAAA,yBAA2B,2BAC3BA,EAAA,QAAU,UANFA,OAAA","names":["webhook_exports","__export","EventField","MessageStatus","MessageType","__toCommonJS"]}
@@ -0,0 +1,2 @@
1
+ var n=(t=>(t.TEXT="text",t.IMAGE="image",t.AUDIO="audio",t.VIDEO="video",t.DOCUMENT="document",t.STICKER="sticker",t.LOCATION="location",t.CONTACTS="contacts",t.BUTTON="button",t.INTERACTIVE="interactive",t.ORDER="order",t.SYSTEM="system",t.UNKNOWN="unknown",t))(n||{}),e=(i=>(i.DELIVERED="delivered",i.READ="read",i.SENT="sent",i))(e||{}),s=(r=>(r.MESSAGES="messages",r.STATUSES="statuses",r.MESSAGE_TEMPLATE_STATUS_UPDATE="message_template_status_update",r.PHONE_NUMBER_QUALITY_UPDATE="phone_number_quality_update",r.PHONE_NUMBER_NAME_UPDATE="phone_number_name_update",r.UNKNOWN="unknown",r))(s||{});export{s as EventField,e as MessageStatus,n as MessageType};
2
+ //# sourceMappingURL=webhook.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/webhook.ts"],"sourcesContent":["/**\n * Represents a message received through the webhook\n * Based on Meta's documentation: https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/components#messages-object\n */\nexport interface WebhookMessage {\n /**\n * The message ID\n */\n id: string;\n\n /**\n * The sender's phone number\n */\n from: string;\n\n /**\n * The timestamp of the message\n */\n timestamp: string;\n\n /**\n * The type of message (text, image, etc.)\n */\n type: MessageType;\n\n /**\n * The phone number ID that received the message\n */\n phoneNumberId: string;\n\n /**\n * Text object for text messages\n */\n text?: {\n /**\n * The text content of the message\n */\n body: string;\n };\n\n /**\n * Image object for image messages\n */\n image?: {\n /**\n * The image caption (if provided)\n */\n caption?: string;\n /**\n * The SHA256 hash of the image\n */\n sha256?: string;\n /**\n * The ID for the image\n */\n id: string;\n /**\n * The MIME type of the image\n */\n mime_type: string;\n };\n\n /**\n * Video object for video messages\n */\n video?: {\n /**\n * The video caption (if provided)\n */\n caption?: string;\n /**\n * The SHA256 hash of the video\n */\n sha256?: string;\n /**\n * The ID for the video\n */\n id: string;\n /**\n * The MIME type of the video\n */\n mime_type: string;\n };\n\n /**\n * Audio object for audio messages\n */\n audio?: {\n /**\n * The ID for the audio file\n */\n id: string;\n /**\n * The MIME type of the audio file\n */\n mime_type: string;\n /**\n * Whether the audio is a voice message\n */\n voice?: boolean;\n };\n\n /**\n * Document object for document messages\n */\n document?: {\n /**\n * The document caption (if provided)\n */\n caption?: string;\n /**\n * The document filename\n */\n filename: string;\n /**\n * The SHA256 hash of the document\n */\n sha256?: string;\n /**\n * The ID for the document\n */\n id: string;\n /**\n * The MIME type of the document\n */\n mime_type: string;\n };\n\n /**\n * Sticker object for sticker messages\n */\n sticker?: {\n /**\n * The ID for the sticker\n */\n id: string;\n /**\n * Whether this is an animated sticker\n */\n animated: boolean;\n /**\n * The MIME type of the sticker\n */\n mime_type: string;\n };\n\n /**\n * Contacts object for contact messages\n */\n contacts?: Array<{\n /**\n * The contact's name\n */\n name: {\n formatted_name: string;\n first_name?: string;\n last_name?: string;\n middle_name?: string;\n suffix?: string;\n prefix?: string;\n };\n /**\n * The contact's phone numbers\n */\n phones?: Array<{\n phone: string;\n type?: string;\n wa_id?: string;\n }>;\n /**\n * The contact's emails\n */\n emails?: Array<{\n email: string;\n type?: string;\n }>;\n /**\n * The contact's addresses\n */\n addresses?: Array<{\n street?: string;\n city?: string;\n state?: string;\n zip?: string;\n country?: string;\n country_code?: string;\n type?: string;\n }>;\n /**\n * The contact's organizations\n */\n org?: {\n company?: string;\n department?: string;\n title?: string;\n };\n /**\n * The contact's URLs\n */\n urls?: Array<{\n url: string;\n type?: string;\n }>;\n /**\n * The contact's birthday (YYYY-MM-DD format)\n */\n birthday?: string;\n }>;\n\n /**\n * Location object for location messages\n */\n location?: {\n /**\n * Latitude of the location\n */\n latitude: number;\n /**\n * Longitude of the location\n */\n longitude: number;\n /**\n * Name of the location\n */\n name?: string;\n /**\n * Address of the location\n */\n address?: string;\n };\n\n /**\n * Interactive object for interactive messages\n */\n interactive?: {\n /**\n * Type of the interactive message\n */\n type: string;\n /**\n * ID for the button that was clicked\n */\n button_reply?: {\n id: string;\n title: string;\n };\n /**\n * ID for the list item that was selected\n */\n list_reply?: {\n id: string;\n title: string;\n description?: string;\n };\n };\n\n /**\n * System object for system messages (like user phone number changes)\n */\n system?: {\n /**\n * The type of system update\n */\n type: string;\n /**\n * User's identity if the update is a customer identity change\n */\n identity?: string;\n /**\n * Old and new phone numbers if the update is a phone number change\n */\n customer?: {\n /**\n * The previous phone number\n */\n previous_wa_id: string;\n /**\n * The new phone number\n */\n wa_id: string;\n };\n };\n\n /**\n * Order object for order messages\n */\n order?: {\n /**\n * Catalog ID\n */\n catalog_id: string;\n /**\n * Product items in the order\n */\n product_items: Array<{\n /**\n * Product ID\n */\n product_retailer_id: string;\n /**\n * Quantity of the product\n */\n quantity: number;\n /**\n * Item price\n */\n item_price: number;\n /**\n * Currency code\n */\n currency: string;\n }>;\n /**\n * Text message included with the order\n */\n text?: string;\n };\n\n /**\n * Context object, included when a user replies or interacts\n */\n context?: {\n /**\n * ID of the message being replied to or interacted with\n */\n message_id: string;\n /**\n * ID of the forwarded message, if applicable\n */\n forwarded?: boolean;\n /**\n * Frequently forwarded status\n */\n frequently_forwarded?: boolean;\n /**\n * Original message information if the message was referred\n */\n referred_product?: {\n /**\n * Catalog ID\n */\n catalog_id: string;\n /**\n * Product ID\n */\n product_retailer_id: string;\n };\n };\n\n /**\n * Errors array, if the message had errors\n */\n errors?: Array<{\n /**\n * Error code\n */\n code: number;\n /**\n * Error title\n */\n title: string;\n /**\n * Error message\n */\n message: string;\n /**\n * Error details object\n */\n error_data?: {\n /**\n * Describes the error details\n */\n details: string;\n };\n }>;\n\n /**\n * Button object for button messages\n */\n button?: {\n /**\n * The payload for the button\n */\n payload: string;\n /**\n * Button text\n */\n text: string;\n };\n\n /**\n * The original message data as received from the webhook\n */\n originalData: any;\n}\n\n/**\n * Represents a non-message event received through the webhook\n */\nexport interface WebhookEvent {\n /**\n * The field type of the event\n */\n field: string;\n\n /**\n * The event data\n */\n value: any;\n}\n\n/**\n * Handler function for processing messages\n */\nexport type MessageHandler = (message: WebhookMessage) => void | Promise<void>;\n\n/**\n * Handler function for processing events\n */\nexport type EventHandler = (event: WebhookEvent) => void | Promise<void>;\n\n/**\n * Message types that can be received through the webhook\n */\nexport enum MessageType {\n TEXT = 'text',\n IMAGE = 'image',\n AUDIO = 'audio',\n VIDEO = 'video',\n DOCUMENT = 'document',\n STICKER = 'sticker',\n LOCATION = 'location',\n CONTACTS = 'contacts',\n BUTTON = 'button',\n INTERACTIVE = 'interactive',\n ORDER = 'order',\n SYSTEM = 'system',\n UNKNOWN = 'unknown',\n}\n\n/**\n * Statuses that can be received in status updates\n */\nexport enum MessageStatus {\n DELIVERED = 'delivered',\n READ = 'read',\n SENT = 'sent',\n}\n\n/**\n * Event fields that can be received through the webhook\n */\nexport enum EventField {\n MESSAGES = 'messages',\n STATUSES = 'statuses',\n MESSAGE_TEMPLATE_STATUS_UPDATE = 'message_template_status_update',\n PHONE_NUMBER_QUALITY_UPDATE = 'phone_number_quality_update',\n PHONE_NUMBER_NAME_UPDATE = 'phone_number_name_update',\n UNKNOWN = 'unknown',\n}\n"],"mappings":"AAwaO,IAAKA,OACRA,EAAA,KAAO,OACPA,EAAA,MAAQ,QACRA,EAAA,MAAQ,QACRA,EAAA,MAAQ,QACRA,EAAA,SAAW,WACXA,EAAA,QAAU,UACVA,EAAA,SAAW,WACXA,EAAA,SAAW,WACXA,EAAA,OAAS,SACTA,EAAA,YAAc,cACdA,EAAA,MAAQ,QACRA,EAAA,OAAS,SACTA,EAAA,QAAU,UAbFA,OAAA,IAmBAC,OACRA,EAAA,UAAY,YACZA,EAAA,KAAO,OACPA,EAAA,KAAO,OAHCA,OAAA,IASAC,OACRA,EAAA,SAAW,WACXA,EAAA,SAAW,WACXA,EAAA,+BAAiC,iCACjCA,EAAA,4BAA8B,8BAC9BA,EAAA,yBAA2B,2BAC3BA,EAAA,QAAU,UANFA,OAAA","names":["MessageType","MessageStatus","EventField"]}
@@ -0,0 +1,143 @@
1
+ import { MessageType, WebhookMessage } from '../types/webhook.mjs';
2
+
3
+ /**
4
+ * Filters for message handling, inspired by PyWa
5
+ */
6
+ declare const filters: {
7
+ /**
8
+ * Filters messages by type
9
+ * @param type Message type to filter for
10
+ * @returns A filter function
11
+ */
12
+ type: (type: MessageType | string) => ((message: WebhookMessage) => boolean);
13
+ /**
14
+ * Filters text messages
15
+ * @param message Message to check
16
+ * @returns True if the message is a text message
17
+ */
18
+ text: (message: WebhookMessage) => boolean;
19
+ /**
20
+ * Filters image messages
21
+ * @param message Message to check
22
+ * @returns True if the message is an image message
23
+ */
24
+ image: (message: WebhookMessage) => boolean;
25
+ /**
26
+ * Filters audio messages
27
+ * @param message Message to check
28
+ * @returns True if the message is an audio message
29
+ */
30
+ audio: (message: WebhookMessage) => boolean;
31
+ /**
32
+ * Filters video messages
33
+ * @param message Message to check
34
+ * @returns True if the message is a video message
35
+ */
36
+ video: (message: WebhookMessage) => boolean;
37
+ /**
38
+ * Filters document messages
39
+ * @param message Message to check
40
+ * @returns True if the message is a document message
41
+ */
42
+ document: (message: WebhookMessage) => boolean;
43
+ /**
44
+ * Filters sticker messages
45
+ * @param message Message to check
46
+ * @returns True if the message is a sticker message
47
+ */
48
+ sticker: (message: WebhookMessage) => boolean;
49
+ /**
50
+ * Filters location messages
51
+ * @param message Message to check
52
+ * @returns True if the message is a location message
53
+ */
54
+ location: (message: WebhookMessage) => boolean;
55
+ /**
56
+ * Filters contact messages
57
+ * @param message Message to check
58
+ * @returns True if the message is a contacts message
59
+ */
60
+ contacts: (message: WebhookMessage) => boolean;
61
+ /**
62
+ * Filters button messages
63
+ * @param message Message to check
64
+ * @returns True if the message is a button message
65
+ */
66
+ button: (message: WebhookMessage) => boolean;
67
+ /**
68
+ * Filters interactive messages
69
+ * @param message Message to check
70
+ * @returns True if the message is an interactive message
71
+ */
72
+ interactive: (message: WebhookMessage) => boolean;
73
+ /**
74
+ * Filters system messages
75
+ * @param message Message to check
76
+ * @returns True if the message is a system message
77
+ */
78
+ system: (message: WebhookMessage) => boolean;
79
+ /**
80
+ * Filters order messages
81
+ * @param message Message to check
82
+ * @returns True if the message is an order message
83
+ */
84
+ order: (message: WebhookMessage) => boolean;
85
+ /**
86
+ * Matches text content against a pattern
87
+ * @param patterns String or regular expression or array of patterns to match against
88
+ * @returns A filter function
89
+ */
90
+ matches: (patterns: string | RegExp | (string | RegExp)[]) => ((message: WebhookMessage) => boolean);
91
+ /**
92
+ * Checks if a message is a reply to another message
93
+ * @returns A filter function that returns true if the message is a reply
94
+ */
95
+ isReply: (message: WebhookMessage) => boolean;
96
+ /**
97
+ * Checks if a message is a reply to a specific message
98
+ * @param messageId The ID of the original message to check for
99
+ * @returns A filter function that returns true if the message is a reply to the specified message
100
+ */
101
+ isReplyTo: (messageId: string) => ((message: WebhookMessage) => boolean);
102
+ /**
103
+ * Checks if a message is forwarded
104
+ * @returns A filter function that returns true if the message is forwarded
105
+ */
106
+ isForwarded: (message: WebhookMessage) => boolean;
107
+ /**
108
+ * Checks if a message is frequently forwarded
109
+ * @returns A filter function that returns true if the message is frequently forwarded
110
+ */
111
+ isFrequentlyForwarded: (message: WebhookMessage) => boolean;
112
+ /**
113
+ * Combines multiple filters with AND logic
114
+ * @param filterFunctions Array of filter functions to combine
115
+ * @returns A filter function that returns true only if all filters return true
116
+ */
117
+ and: (...filterFunctions: ((message: WebhookMessage) => boolean)[]) => ((message: WebhookMessage) => boolean);
118
+ /**
119
+ * Combines multiple filters with OR logic
120
+ * @param filterFunctions Array of filter functions to combine
121
+ * @returns A filter function that returns true if any filter returns true
122
+ */
123
+ or: (...filterFunctions: ((message: WebhookMessage) => boolean)[]) => ((message: WebhookMessage) => boolean);
124
+ /**
125
+ * Negates a filter
126
+ * @param filterFunction Filter function to negate
127
+ * @returns A filter function that returns the opposite of the input filter
128
+ */
129
+ not: (filterFunction: (message: WebhookMessage) => boolean) => ((message: WebhookMessage) => boolean);
130
+ /**
131
+ * Filters messages from a specific sender
132
+ * @param from Sender phone number to filter for
133
+ * @returns A filter function
134
+ */
135
+ from: (from: string) => ((message: WebhookMessage) => boolean);
136
+ /**
137
+ * Filter function that accepts all messages
138
+ * @returns Always returns true
139
+ */
140
+ all: () => ((message: WebhookMessage) => boolean);
141
+ };
142
+
143
+ export { filters };