@warriorteam/messenger-sdk 1.2.0 → 1.3.0
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.
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1826 -11
- package/dist/index.d.ts +1826 -11
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -34,23 +34,23 @@ interface Recipient {
|
|
|
34
34
|
last_name: string;
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
interface QuickReply {
|
|
37
|
+
interface QuickReply$1 {
|
|
38
38
|
content_type: 'text' | 'user_phone_number' | 'user_email';
|
|
39
39
|
title?: string;
|
|
40
40
|
payload?: string;
|
|
41
41
|
image_url?: string;
|
|
42
42
|
}
|
|
43
|
-
interface Message {
|
|
43
|
+
interface Message$1 {
|
|
44
44
|
text?: string;
|
|
45
45
|
attachment?: Attachment;
|
|
46
|
-
quick_replies?: QuickReply[];
|
|
46
|
+
quick_replies?: QuickReply$1[];
|
|
47
47
|
metadata?: string;
|
|
48
48
|
}
|
|
49
49
|
interface Attachment {
|
|
50
50
|
type: 'image' | 'audio' | 'video' | 'file' | 'template';
|
|
51
|
-
payload: AttachmentPayload | TemplatePayload;
|
|
51
|
+
payload: AttachmentPayload$1 | TemplatePayload;
|
|
52
52
|
}
|
|
53
|
-
interface AttachmentPayload {
|
|
53
|
+
interface AttachmentPayload$1 {
|
|
54
54
|
url?: string;
|
|
55
55
|
attachment_id?: string;
|
|
56
56
|
is_reusable?: boolean;
|
|
@@ -66,7 +66,7 @@ type MessagingType = 'RESPONSE' | 'UPDATE' | 'MESSAGE_TAG';
|
|
|
66
66
|
interface SendMessageRequest {
|
|
67
67
|
recipient: Recipient;
|
|
68
68
|
messaging_type: MessagingType;
|
|
69
|
-
message?: Message;
|
|
69
|
+
message?: Message$1;
|
|
70
70
|
sender_action?: SenderAction;
|
|
71
71
|
notification_type?: 'REGULAR' | 'SILENT_PUSH' | 'NO_PUSH';
|
|
72
72
|
tag?: string;
|
|
@@ -88,9 +88,9 @@ interface ErrorResponse {
|
|
|
88
88
|
error: MessengerError;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
type AttachmentType = 'image' | 'audio' | 'video' | 'file';
|
|
91
|
+
type AttachmentType$1 = 'image' | 'audio' | 'video' | 'file';
|
|
92
92
|
interface AttachmentUploadRequest {
|
|
93
|
-
type: AttachmentType;
|
|
93
|
+
type: AttachmentType$1;
|
|
94
94
|
url: string;
|
|
95
95
|
is_reusable?: boolean;
|
|
96
96
|
}
|
|
@@ -111,7 +111,7 @@ declare class SendAPI {
|
|
|
111
111
|
*/
|
|
112
112
|
attachment(options: {
|
|
113
113
|
recipient: Recipient;
|
|
114
|
-
type: AttachmentType;
|
|
114
|
+
type: AttachmentType$1;
|
|
115
115
|
attachment_id: string;
|
|
116
116
|
messaging_type?: 'RESPONSE' | 'UPDATE' | 'MESSAGE_TAG';
|
|
117
117
|
}, apiOptions?: APIOptions): Promise<SendMessageResponse>;
|
|
@@ -120,7 +120,7 @@ declare class SendAPI {
|
|
|
120
120
|
*/
|
|
121
121
|
attachmentFromUrl(options: {
|
|
122
122
|
recipient: Recipient;
|
|
123
|
-
type: AttachmentType;
|
|
123
|
+
type: AttachmentType$1;
|
|
124
124
|
url: string;
|
|
125
125
|
messaging_type?: 'RESPONSE' | 'UPDATE' | 'MESSAGE_TAG';
|
|
126
126
|
}, apiOptions?: APIOptions): Promise<SendMessageResponse>;
|
|
@@ -335,6 +335,1821 @@ declare class Messenger {
|
|
|
335
335
|
private validateConfig;
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
+
/**
|
|
339
|
+
* Facebook Messenger Platform - Message Edits Webhook Types
|
|
340
|
+
*
|
|
341
|
+
* These types represent the webhook event structure for message_edits events.
|
|
342
|
+
* Triggered when a user edits a previously sent message.
|
|
343
|
+
*
|
|
344
|
+
* @see https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/message-edits/
|
|
345
|
+
*/
|
|
346
|
+
/**
|
|
347
|
+
* Represents the sender information in a message edit webhook event
|
|
348
|
+
*/
|
|
349
|
+
interface MessageEditSender {
|
|
350
|
+
/** Page-scoped ID (PSID) of the user who sent the message */
|
|
351
|
+
id: string;
|
|
352
|
+
/**
|
|
353
|
+
* User reference provided by the chat plugin, if applicable.
|
|
354
|
+
* Only present for chat plugin events.
|
|
355
|
+
*/
|
|
356
|
+
user_ref?: string;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Represents the recipient information in a message edit webhook event
|
|
360
|
+
*/
|
|
361
|
+
interface MessageEditRecipient {
|
|
362
|
+
/** Page ID that received the message */
|
|
363
|
+
id: string;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Represents the edited message information
|
|
367
|
+
*/
|
|
368
|
+
interface MessageEdit {
|
|
369
|
+
/**
|
|
370
|
+
* Unique message identifier for the edited message
|
|
371
|
+
*/
|
|
372
|
+
mid: string;
|
|
373
|
+
/**
|
|
374
|
+
* New message content after the edit.
|
|
375
|
+
* Contains the updated text of the message.
|
|
376
|
+
*/
|
|
377
|
+
text: string;
|
|
378
|
+
/**
|
|
379
|
+
* Number of times the message has been edited.
|
|
380
|
+
* Maximum value is 5 (client-side constraint).
|
|
381
|
+
*/
|
|
382
|
+
num_edit: number;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Main webhook event structure for message edits
|
|
386
|
+
*
|
|
387
|
+
* This event is triggered when a user edits a previously sent message.
|
|
388
|
+
* The webhook provides the updated message content and edit count.
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```json
|
|
392
|
+
* {
|
|
393
|
+
* "sender": {
|
|
394
|
+
* "id": "1234567890123456"
|
|
395
|
+
* },
|
|
396
|
+
* "recipient": {
|
|
397
|
+
* "id": "9876543210987654"
|
|
398
|
+
* },
|
|
399
|
+
* "timestamp": 1458668856463,
|
|
400
|
+
* "message_edit": {
|
|
401
|
+
* "mid": "mid.1458668856218:ed81099e15d3f4f233",
|
|
402
|
+
* "text": "This is the updated message content",
|
|
403
|
+
* "num_edit": 2
|
|
404
|
+
* }
|
|
405
|
+
* }
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
interface MessageEditWebhookEvent {
|
|
409
|
+
/** Information about the user who edited the message */
|
|
410
|
+
sender: MessageEditSender;
|
|
411
|
+
/** Information about the page that received the message */
|
|
412
|
+
recipient: MessageEditRecipient;
|
|
413
|
+
/**
|
|
414
|
+
* Timestamp when the edit occurred (in milliseconds since epoch).
|
|
415
|
+
* Represents the time the edit was made, not the original message time.
|
|
416
|
+
*/
|
|
417
|
+
timestamp: number;
|
|
418
|
+
/** Details about the edited message */
|
|
419
|
+
message_edit: MessageEdit;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Complete webhook payload structure that includes the message edit event
|
|
423
|
+
* along with other webhook metadata
|
|
424
|
+
*/
|
|
425
|
+
interface MessageEditWebhookPayload {
|
|
426
|
+
/** The webhook object type - always "page" for Messenger */
|
|
427
|
+
object: 'page';
|
|
428
|
+
/** Array of webhook entries containing the actual events */
|
|
429
|
+
entry: Array<{
|
|
430
|
+
/** Page ID */
|
|
431
|
+
id: string;
|
|
432
|
+
/** Timestamp of the webhook entry */
|
|
433
|
+
time: number;
|
|
434
|
+
/** Array of messaging events - contains the message edit event */
|
|
435
|
+
messaging: MessageEditWebhookEvent[];
|
|
436
|
+
}>;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Type guard to check if a webhook event is a message edit event
|
|
440
|
+
*
|
|
441
|
+
* @param event - The webhook event to check
|
|
442
|
+
* @returns True if the event contains a message_edit property
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```typescript
|
|
446
|
+
* if (isMessageEditEvent(event)) {
|
|
447
|
+
* // TypeScript now knows event has message_edit property
|
|
448
|
+
* console.log(`Message edited ${event.message_edit.num_edit} times`);
|
|
449
|
+
* }
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
declare function isMessageEditEvent(event: any): event is MessageEditWebhookEvent;
|
|
453
|
+
/**
|
|
454
|
+
* Utility type for common message edit properties that might be used in processing
|
|
455
|
+
*/
|
|
456
|
+
interface MessageEditProcessingContext {
|
|
457
|
+
/** The edited message ID */
|
|
458
|
+
messageId: string;
|
|
459
|
+
/** The user who made the edit */
|
|
460
|
+
senderId: string;
|
|
461
|
+
/** The page that received the edit */
|
|
462
|
+
recipientId: string;
|
|
463
|
+
/** Updated message content */
|
|
464
|
+
updatedText: string;
|
|
465
|
+
/** Number of edits made */
|
|
466
|
+
editCount: number;
|
|
467
|
+
/** When the edit occurred */
|
|
468
|
+
editTimestamp: number;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Helper function to extract processing context from a message edit event
|
|
472
|
+
*
|
|
473
|
+
* @param event - The message edit webhook event
|
|
474
|
+
* @returns Simplified processing context
|
|
475
|
+
*
|
|
476
|
+
* @example
|
|
477
|
+
* ```typescript
|
|
478
|
+
* const context = extractMessageEditContext(webhookEvent);
|
|
479
|
+
* console.log(`User ${context.senderId} edited message to: "${context.updatedText}"`);
|
|
480
|
+
* ```
|
|
481
|
+
*/
|
|
482
|
+
declare function extractMessageEditContext(event: MessageEditWebhookEvent): MessageEditProcessingContext;
|
|
483
|
+
/**
|
|
484
|
+
* Constants related to message editing limits and constraints
|
|
485
|
+
*/
|
|
486
|
+
declare const MESSAGE_EDIT_CONSTANTS: {
|
|
487
|
+
/** Maximum number of edits allowed per message */
|
|
488
|
+
readonly MAX_EDITS: 5;
|
|
489
|
+
/** Webhook event type identifier */
|
|
490
|
+
readonly EVENT_TYPE: "message_edit";
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Facebook Messenger Platform Message Reactions Webhook Types
|
|
495
|
+
*
|
|
496
|
+
* These types define the structure of webhook events received when users
|
|
497
|
+
* react to messages in Messenger conversations.
|
|
498
|
+
*
|
|
499
|
+
* @see https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/message-reactions
|
|
500
|
+
*/
|
|
501
|
+
/**
|
|
502
|
+
* Types of reactions that can be applied to messages in Messenger.
|
|
503
|
+
* These are the predefined reaction types supported by Facebook.
|
|
504
|
+
*/
|
|
505
|
+
declare enum MessageReactionType {
|
|
506
|
+
/** Standard like reaction */
|
|
507
|
+
LIKE = "like",
|
|
508
|
+
/** Dislike reaction */
|
|
509
|
+
DISLIKE = "dislike",
|
|
510
|
+
/** Love reaction (heart) */
|
|
511
|
+
LOVE = "love",
|
|
512
|
+
/** Sad reaction */
|
|
513
|
+
SAD = "sad",
|
|
514
|
+
/** Angry reaction */
|
|
515
|
+
ANGRY = "angry",
|
|
516
|
+
/** Wow/surprised reaction */
|
|
517
|
+
WOW = "wow",
|
|
518
|
+
/** Smile/laugh reaction */
|
|
519
|
+
SMILE = "smile",
|
|
520
|
+
/** Other/unrecognized emoji reactions */
|
|
521
|
+
OTHER = "other"
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Actions that can be performed on message reactions.
|
|
525
|
+
*/
|
|
526
|
+
declare enum MessageReactionAction {
|
|
527
|
+
/** Adding a reaction to a message */
|
|
528
|
+
REACT = "react",
|
|
529
|
+
/** Removing a reaction from a message */
|
|
530
|
+
UNREACT = "unreact"
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Represents the sender of the reaction.
|
|
534
|
+
* Contains the Page-Scoped User ID (PSID) of the user who reacted.
|
|
535
|
+
*/
|
|
536
|
+
interface MessageReactionSender {
|
|
537
|
+
/** Page-Scoped User ID (PSID) of the user who reacted */
|
|
538
|
+
id: string;
|
|
539
|
+
/**
|
|
540
|
+
* User reference for chat plugin events (optional)
|
|
541
|
+
* Used when the reaction comes from a chat plugin integration
|
|
542
|
+
*/
|
|
543
|
+
user_ref?: string;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Represents the recipient (page) that received the reaction.
|
|
547
|
+
*/
|
|
548
|
+
interface MessageReactionRecipient {
|
|
549
|
+
/** Page ID of the Facebook page that received the reaction */
|
|
550
|
+
id: string;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Contains the detailed information about the reaction.
|
|
554
|
+
*/
|
|
555
|
+
interface MessageReactionData {
|
|
556
|
+
/**
|
|
557
|
+
* The type of reaction applied to the message.
|
|
558
|
+
* Can be one of the predefined types or "other" for unrecognized emojis.
|
|
559
|
+
*/
|
|
560
|
+
reaction: MessageReactionType;
|
|
561
|
+
/**
|
|
562
|
+
* The UTF-8 emoji representation of the reaction (optional).
|
|
563
|
+
* Example: "\u{2764}\u{FE0F}" for heart emoji
|
|
564
|
+
*/
|
|
565
|
+
emoji?: string;
|
|
566
|
+
/**
|
|
567
|
+
* The action performed - either adding or removing the reaction.
|
|
568
|
+
*/
|
|
569
|
+
action: MessageReactionAction;
|
|
570
|
+
/**
|
|
571
|
+
* The message ID that the reaction was applied to.
|
|
572
|
+
* This corresponds to the 'mid' field of the original message.
|
|
573
|
+
*/
|
|
574
|
+
mid: string;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Complete webhook event structure for message reactions.
|
|
578
|
+
* This is the main payload received when a user reacts to a message.
|
|
579
|
+
*/
|
|
580
|
+
interface MessageReactionWebhookEvent {
|
|
581
|
+
/** Information about the user who performed the reaction */
|
|
582
|
+
sender: MessageReactionSender;
|
|
583
|
+
/** Information about the page that received the reaction */
|
|
584
|
+
recipient: MessageReactionRecipient;
|
|
585
|
+
/**
|
|
586
|
+
* Unix timestamp (in milliseconds) when the reaction occurred.
|
|
587
|
+
* Example: 1458668856463
|
|
588
|
+
*/
|
|
589
|
+
timestamp: number;
|
|
590
|
+
/** Detailed information about the reaction */
|
|
591
|
+
reaction: MessageReactionData;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* The complete webhook payload containing the message reaction event.
|
|
595
|
+
* This matches the structure of the webhook POST request body.
|
|
596
|
+
*/
|
|
597
|
+
interface MessageReactionWebhookPayload {
|
|
598
|
+
/** The page object containing the reaction events */
|
|
599
|
+
object: 'page';
|
|
600
|
+
/** Array of page entries, each containing reaction events */
|
|
601
|
+
entry: Array<{
|
|
602
|
+
/** Page ID */
|
|
603
|
+
id: string;
|
|
604
|
+
/** Unix timestamp when the webhook was triggered */
|
|
605
|
+
time: number;
|
|
606
|
+
/** Array of messaging events containing the reactions */
|
|
607
|
+
messaging: MessageReactionWebhookEvent[];
|
|
608
|
+
}>;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* Context object for processing message reaction webhooks.
|
|
612
|
+
* Useful for handlers that need additional processing information.
|
|
613
|
+
*/
|
|
614
|
+
interface MessageReactionProcessingContext {
|
|
615
|
+
/** The original webhook event */
|
|
616
|
+
event: MessageReactionWebhookEvent;
|
|
617
|
+
/** Page ID that received the reaction */
|
|
618
|
+
pageId: string;
|
|
619
|
+
/** User ID who performed the reaction */
|
|
620
|
+
userId: string;
|
|
621
|
+
/** ID of the message that was reacted to */
|
|
622
|
+
messageId: string;
|
|
623
|
+
/** Whether this is a new reaction (true) or removal (false) */
|
|
624
|
+
isReactionAdded: boolean;
|
|
625
|
+
/** The type of reaction */
|
|
626
|
+
reactionType: MessageReactionType;
|
|
627
|
+
/** Raw emoji string if available */
|
|
628
|
+
emoji?: string;
|
|
629
|
+
/** Timestamp when the reaction occurred */
|
|
630
|
+
timestamp: Date;
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Helper type for reaction statistics and aggregation.
|
|
634
|
+
* Useful for tracking reaction counts on messages.
|
|
635
|
+
*/
|
|
636
|
+
interface MessageReactionStats {
|
|
637
|
+
/** The message ID these stats apply to */
|
|
638
|
+
messageId: string;
|
|
639
|
+
/** Count of each reaction type */
|
|
640
|
+
reactions: {
|
|
641
|
+
[K in MessageReactionType]?: number;
|
|
642
|
+
};
|
|
643
|
+
/** Total number of reactions */
|
|
644
|
+
totalReactions: number;
|
|
645
|
+
/** Last updated timestamp */
|
|
646
|
+
lastUpdated: Date;
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Configuration options for handling message reaction webhooks.
|
|
650
|
+
*/
|
|
651
|
+
interface MessageReactionWebhookConfig {
|
|
652
|
+
/** Whether to track reaction statistics */
|
|
653
|
+
enableStats?: boolean;
|
|
654
|
+
/** Whether to handle emoji reactions beyond predefined types */
|
|
655
|
+
handleCustomEmojis?: boolean;
|
|
656
|
+
/** Maximum age of reactions to process (in milliseconds) */
|
|
657
|
+
maxReactionAge?: number;
|
|
658
|
+
/** Whether to validate webhook signatures */
|
|
659
|
+
validateSignature?: boolean;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Facebook Messenger Platform - Message Reads Webhook Types
|
|
664
|
+
*
|
|
665
|
+
* These types represent the webhook event structure for message_reads events.
|
|
666
|
+
* Triggered when a user reads messages sent by a Page.
|
|
667
|
+
*
|
|
668
|
+
* The message_reads webhook event indicates that all messages up to a certain
|
|
669
|
+
* watermark timestamp have been read by the recipient.
|
|
670
|
+
*
|
|
671
|
+
* @see https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/message-reads/
|
|
672
|
+
*/
|
|
673
|
+
/**
|
|
674
|
+
* Represents the sender information in a message reads webhook event
|
|
675
|
+
*/
|
|
676
|
+
interface MessageReadsSender {
|
|
677
|
+
/** Page-scoped ID (PSID) of the user who read the messages */
|
|
678
|
+
id: string;
|
|
679
|
+
/**
|
|
680
|
+
* User reference provided by the chat plugin, if applicable.
|
|
681
|
+
* Only present for chat plugin events.
|
|
682
|
+
*/
|
|
683
|
+
user_ref?: string;
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* Represents the recipient information in a message reads webhook event
|
|
687
|
+
*/
|
|
688
|
+
interface MessageReadsRecipient {
|
|
689
|
+
/** Page ID that sent the original messages */
|
|
690
|
+
id: string;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Represents the read receipt information
|
|
694
|
+
*/
|
|
695
|
+
interface MessageRead {
|
|
696
|
+
/**
|
|
697
|
+
* Watermark timestamp indicating all messages up to this point have been read.
|
|
698
|
+
* This is a Unix timestamp in milliseconds.
|
|
699
|
+
* All messages with a timestamp less than or equal to this value have been read.
|
|
700
|
+
*/
|
|
701
|
+
watermark: number;
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Main webhook event structure for message reads
|
|
705
|
+
*
|
|
706
|
+
* This event is triggered when a user reads messages sent by a Page.
|
|
707
|
+
* The watermark indicates the timestamp up to which all messages have been read.
|
|
708
|
+
*
|
|
709
|
+
* @example
|
|
710
|
+
* ```json
|
|
711
|
+
* {
|
|
712
|
+
* "sender": {
|
|
713
|
+
* "id": "1234567890123456"
|
|
714
|
+
* },
|
|
715
|
+
* "recipient": {
|
|
716
|
+
* "id": "9876543210987654"
|
|
717
|
+
* },
|
|
718
|
+
* "timestamp": 1458668856463,
|
|
719
|
+
* "read": {
|
|
720
|
+
* "watermark": 1458668856253
|
|
721
|
+
* }
|
|
722
|
+
* }
|
|
723
|
+
* ```
|
|
724
|
+
*/
|
|
725
|
+
interface MessageReadsWebhookEvent {
|
|
726
|
+
/** Information about the user who read the messages */
|
|
727
|
+
sender: MessageReadsSender;
|
|
728
|
+
/** Information about the page that sent the messages */
|
|
729
|
+
recipient: MessageReadsRecipient;
|
|
730
|
+
/**
|
|
731
|
+
* Timestamp when the read event occurred (in milliseconds since epoch).
|
|
732
|
+
* Represents when the read receipt was generated.
|
|
733
|
+
*/
|
|
734
|
+
timestamp: number;
|
|
735
|
+
/** Read receipt information containing the watermark */
|
|
736
|
+
read: MessageRead;
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Complete webhook payload structure that includes the message reads event
|
|
740
|
+
* along with other webhook metadata
|
|
741
|
+
*/
|
|
742
|
+
interface MessageReadsWebhookPayload {
|
|
743
|
+
/** The webhook object type - always "page" for Messenger */
|
|
744
|
+
object: 'page';
|
|
745
|
+
/** Array of webhook entries containing the actual events */
|
|
746
|
+
entry: Array<{
|
|
747
|
+
/** Page ID */
|
|
748
|
+
id: string;
|
|
749
|
+
/** Timestamp of the webhook entry */
|
|
750
|
+
time: number;
|
|
751
|
+
/** Array of messaging events - contains the message reads event */
|
|
752
|
+
messaging: MessageReadsWebhookEvent[];
|
|
753
|
+
}>;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Type guard to check if a webhook event is a message reads event
|
|
757
|
+
*
|
|
758
|
+
* @param event - The webhook event to check
|
|
759
|
+
* @returns True if the event contains a read property
|
|
760
|
+
*
|
|
761
|
+
* @example
|
|
762
|
+
* ```typescript
|
|
763
|
+
* if (isMessageReadsEvent(event)) {
|
|
764
|
+
* // TypeScript now knows event has read property
|
|
765
|
+
* console.log(`Messages read up to timestamp: ${event.read.watermark}`);
|
|
766
|
+
* }
|
|
767
|
+
* ```
|
|
768
|
+
*/
|
|
769
|
+
declare function isMessageReadsEvent(event: any): event is MessageReadsWebhookEvent;
|
|
770
|
+
/**
|
|
771
|
+
* Utility type for extracting just the read data from a webhook event
|
|
772
|
+
*/
|
|
773
|
+
type MessageReadData = MessageRead;
|
|
774
|
+
/**
|
|
775
|
+
* Utility type for common message reads properties that might be used in processing
|
|
776
|
+
*/
|
|
777
|
+
interface MessageReadsProcessingContext {
|
|
778
|
+
/** The user who read the messages */
|
|
779
|
+
senderId: string;
|
|
780
|
+
/** The page that sent the messages */
|
|
781
|
+
recipientId: string;
|
|
782
|
+
/** Timestamp up to which all messages have been read */
|
|
783
|
+
watermarkTimestamp: number;
|
|
784
|
+
/** When the read event occurred */
|
|
785
|
+
readTimestamp: number;
|
|
786
|
+
/**
|
|
787
|
+
* Human-readable datetime for the watermark timestamp.
|
|
788
|
+
* Useful for logging and debugging.
|
|
789
|
+
*/
|
|
790
|
+
watermarkDate: Date;
|
|
791
|
+
/**
|
|
792
|
+
* Human-readable datetime for the read event timestamp.
|
|
793
|
+
* Useful for logging and debugging.
|
|
794
|
+
*/
|
|
795
|
+
readDate: Date;
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Helper function to extract processing context from a message reads event
|
|
799
|
+
*
|
|
800
|
+
* @param event - The message reads webhook event
|
|
801
|
+
* @returns Simplified processing context with additional computed fields
|
|
802
|
+
*
|
|
803
|
+
* @example
|
|
804
|
+
* ```typescript
|
|
805
|
+
* const context = extractMessageReadsContext(webhookEvent);
|
|
806
|
+
* console.log(`User ${context.senderId} read messages up to ${context.watermarkDate.toISOString()}`);
|
|
807
|
+
* ```
|
|
808
|
+
*/
|
|
809
|
+
declare function extractMessageReadsContext(event: MessageReadsWebhookEvent): MessageReadsProcessingContext;
|
|
810
|
+
/**
|
|
811
|
+
* Helper function to check if a specific message timestamp was read
|
|
812
|
+
*
|
|
813
|
+
* @param messageTimestamp - The timestamp of the message to check
|
|
814
|
+
* @param watermark - The watermark timestamp from the read event
|
|
815
|
+
* @returns True if the message with the given timestamp has been read
|
|
816
|
+
*
|
|
817
|
+
* @example
|
|
818
|
+
* ```typescript
|
|
819
|
+
* const messageTime = 1458668855000;
|
|
820
|
+
* const watermark = 1458668856253;
|
|
821
|
+
*
|
|
822
|
+
* if (isMessageRead(messageTime, watermark)) {
|
|
823
|
+
* console.log('This message has been read');
|
|
824
|
+
* }
|
|
825
|
+
* ```
|
|
826
|
+
*/
|
|
827
|
+
declare function isMessageRead(messageTimestamp: number, watermark: number): boolean;
|
|
828
|
+
/**
|
|
829
|
+
* Helper function to determine which messages in a list have been read
|
|
830
|
+
*
|
|
831
|
+
* @param messages - Array of messages with timestamp property
|
|
832
|
+
* @param watermark - The watermark timestamp from the read event
|
|
833
|
+
* @returns Array of messages that have been read
|
|
834
|
+
*
|
|
835
|
+
* @example
|
|
836
|
+
* ```typescript
|
|
837
|
+
* const messages = [
|
|
838
|
+
* { id: '1', timestamp: 1458668855000, text: 'Hello' },
|
|
839
|
+
* { id: '2', timestamp: 1458668857000, text: 'World' }
|
|
840
|
+
* ];
|
|
841
|
+
* const watermark = 1458668856253;
|
|
842
|
+
*
|
|
843
|
+
* const readMessages = getReadMessages(messages, watermark);
|
|
844
|
+
* // Returns only the first message as it's before the watermark
|
|
845
|
+
* ```
|
|
846
|
+
*/
|
|
847
|
+
declare function getReadMessages<T extends {
|
|
848
|
+
timestamp: number;
|
|
849
|
+
}>(messages: T[], watermark: number): T[];
|
|
850
|
+
/**
|
|
851
|
+
* Helper function to get the count of read messages from a list
|
|
852
|
+
*
|
|
853
|
+
* @param messages - Array of messages with timestamp property
|
|
854
|
+
* @param watermark - The watermark timestamp from the read event
|
|
855
|
+
* @returns Number of messages that have been read
|
|
856
|
+
*
|
|
857
|
+
* @example
|
|
858
|
+
* ```typescript
|
|
859
|
+
* const messages = [
|
|
860
|
+
* { id: '1', timestamp: 1458668855000 },
|
|
861
|
+
* { id: '2', timestamp: 1458668857000 }
|
|
862
|
+
* ];
|
|
863
|
+
* const watermark = 1458668856253;
|
|
864
|
+
*
|
|
865
|
+
* const readCount = getReadMessageCount(messages, watermark);
|
|
866
|
+
* // Returns 1
|
|
867
|
+
* ```
|
|
868
|
+
*/
|
|
869
|
+
declare function getReadMessageCount<T extends {
|
|
870
|
+
timestamp: number;
|
|
871
|
+
}>(messages: T[], watermark: number): number;
|
|
872
|
+
/**
|
|
873
|
+
* Constants related to message reads functionality
|
|
874
|
+
*/
|
|
875
|
+
declare const MESSAGE_READS_CONSTANTS: {
|
|
876
|
+
/** Webhook event type identifier */
|
|
877
|
+
readonly EVENT_TYPE: "message_reads";
|
|
878
|
+
/**
|
|
879
|
+
* Property name in the webhook event that contains read data.
|
|
880
|
+
* Used for type guards and event identification.
|
|
881
|
+
*/
|
|
882
|
+
readonly READ_PROPERTY: "read";
|
|
883
|
+
};
|
|
884
|
+
/**
|
|
885
|
+
* Type for the watermark timestamp
|
|
886
|
+
* Represents a Unix timestamp in milliseconds indicating read status
|
|
887
|
+
*/
|
|
888
|
+
type WatermarkTimestamp = number;
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Facebook Messenger Platform - Messaging Postbacks Webhook Types
|
|
892
|
+
*
|
|
893
|
+
* These types represent the webhook event structure for messaging_postbacks events.
|
|
894
|
+
* Triggered when a user clicks on a postback button, Get Started button, or persistent menu item.
|
|
895
|
+
*
|
|
896
|
+
* @see https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/messaging_postbacks
|
|
897
|
+
*/
|
|
898
|
+
/**
|
|
899
|
+
* Represents the sender information in a messaging postback webhook event
|
|
900
|
+
*/
|
|
901
|
+
interface PostbackSender {
|
|
902
|
+
/**
|
|
903
|
+
* Page-scoped ID (PSID) of the user who triggered the postback.
|
|
904
|
+
* This is the unique identifier for the user within the context of your page.
|
|
905
|
+
*/
|
|
906
|
+
id?: string;
|
|
907
|
+
/**
|
|
908
|
+
* User reference provided by the chat plugin, if applicable.
|
|
909
|
+
* Only present for chat plugin events where the user hasn't been identified yet.
|
|
910
|
+
*/
|
|
911
|
+
user_ref?: string;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Represents the recipient information in a messaging postback webhook event
|
|
915
|
+
*/
|
|
916
|
+
interface PostbackRecipient {
|
|
917
|
+
/** Facebook Page ID that received the postback */
|
|
918
|
+
id: string;
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Represents referral information for postbacks that originated from external sources
|
|
922
|
+
*
|
|
923
|
+
* This object is included when a postback is triggered as part of a conversation
|
|
924
|
+
* that was started via m.me links, Click to Messenger ads, Messenger QR codes,
|
|
925
|
+
* or the Welcome Screen.
|
|
926
|
+
*/
|
|
927
|
+
interface PostbackReferral {
|
|
928
|
+
/**
|
|
929
|
+
* Arbitrary data that was included in the original referral.
|
|
930
|
+
* This is the custom parameter you set when creating the referral link.
|
|
931
|
+
*/
|
|
932
|
+
ref?: string;
|
|
933
|
+
/**
|
|
934
|
+
* Source of the referral. Indicates how the conversation was initiated.
|
|
935
|
+
* Common values include:
|
|
936
|
+
* - "SHORTLINK" - from m.me links
|
|
937
|
+
* - "ADS" - from Click to Messenger ads
|
|
938
|
+
* - "MESSENGER_CODE" - from Messenger QR codes
|
|
939
|
+
*/
|
|
940
|
+
source?: string;
|
|
941
|
+
/**
|
|
942
|
+
* Type of referral action that initiated the conversation.
|
|
943
|
+
* Common value is "OPEN_THREAD" for most referral types.
|
|
944
|
+
*/
|
|
945
|
+
type?: string;
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Represents the postback data in a messaging postback webhook event
|
|
949
|
+
*/
|
|
950
|
+
interface PostbackData {
|
|
951
|
+
/**
|
|
952
|
+
* Message ID associated with the postback.
|
|
953
|
+
* Unique identifier for the message that contained the postback button.
|
|
954
|
+
*/
|
|
955
|
+
mid?: string;
|
|
956
|
+
/**
|
|
957
|
+
* Title of the postback button that was clicked.
|
|
958
|
+
* This is the user-visible text that was displayed on the button.
|
|
959
|
+
*/
|
|
960
|
+
title?: string;
|
|
961
|
+
/**
|
|
962
|
+
* Developer-defined payload that was associated with the postback button.
|
|
963
|
+
* This contains the custom data you specified when creating the button.
|
|
964
|
+
* Maximum length is 1000 characters.
|
|
965
|
+
*/
|
|
966
|
+
payload: string;
|
|
967
|
+
/**
|
|
968
|
+
* Referral information if the postback is part of a referred conversation.
|
|
969
|
+
* Only present when the conversation was initiated through external sources
|
|
970
|
+
* like m.me links, ads, QR codes, or Welcome Screen.
|
|
971
|
+
*/
|
|
972
|
+
referral?: PostbackReferral;
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Main webhook event structure for messaging postbacks
|
|
976
|
+
*
|
|
977
|
+
* This event is triggered when a user interacts with postback buttons,
|
|
978
|
+
* including regular postback buttons, Get Started button, and persistent menu items.
|
|
979
|
+
*
|
|
980
|
+
* @example
|
|
981
|
+
* Basic postback from a button click:
|
|
982
|
+
* ```json
|
|
983
|
+
* {
|
|
984
|
+
* "sender": {
|
|
985
|
+
* "id": "1234567890123456"
|
|
986
|
+
* },
|
|
987
|
+
* "recipient": {
|
|
988
|
+
* "id": "9876543210987654"
|
|
989
|
+
* },
|
|
990
|
+
* "timestamp": 1527459824,
|
|
991
|
+
* "postback": {
|
|
992
|
+
* "mid": "m_AG5Hz2Uq7tuwNEhXfYYKj8mJEM_QPpz5jdHtHaW",
|
|
993
|
+
* "title": "Get Started",
|
|
994
|
+
* "payload": "GET_STARTED_PAYLOAD"
|
|
995
|
+
* }
|
|
996
|
+
* }
|
|
997
|
+
* ```
|
|
998
|
+
*
|
|
999
|
+
* @example
|
|
1000
|
+
* Postback with referral data from m.me link:
|
|
1001
|
+
* ```json
|
|
1002
|
+
* {
|
|
1003
|
+
* "sender": {
|
|
1004
|
+
* "user_ref": "unique_ref_param"
|
|
1005
|
+
* },
|
|
1006
|
+
* "recipient": {
|
|
1007
|
+
* "id": "9876543210987654"
|
|
1008
|
+
* },
|
|
1009
|
+
* "timestamp": 1527459824,
|
|
1010
|
+
* "postback": {
|
|
1011
|
+
* "title": "Contact Sales",
|
|
1012
|
+
* "payload": "CONTACT_SALES",
|
|
1013
|
+
* "referral": {
|
|
1014
|
+
* "ref": "landing_page_ad_campaign",
|
|
1015
|
+
* "source": "SHORTLINK",
|
|
1016
|
+
* "type": "OPEN_THREAD"
|
|
1017
|
+
* }
|
|
1018
|
+
* }
|
|
1019
|
+
* }
|
|
1020
|
+
* ```
|
|
1021
|
+
*/
|
|
1022
|
+
interface MessagingPostbackWebhookEvent {
|
|
1023
|
+
/** Information about the user who triggered the postback */
|
|
1024
|
+
sender: PostbackSender;
|
|
1025
|
+
/** Information about the page that received the postback */
|
|
1026
|
+
recipient: PostbackRecipient;
|
|
1027
|
+
/**
|
|
1028
|
+
* Unix timestamp when the postback was triggered (in milliseconds since epoch).
|
|
1029
|
+
* Represents when the user clicked the button, not when the webhook was sent.
|
|
1030
|
+
*/
|
|
1031
|
+
timestamp: number;
|
|
1032
|
+
/** Details about the postback that was triggered */
|
|
1033
|
+
postback: PostbackData;
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Complete webhook payload structure that includes the messaging postback event
|
|
1037
|
+
* along with other webhook metadata
|
|
1038
|
+
*/
|
|
1039
|
+
interface MessagingPostbackWebhookPayload {
|
|
1040
|
+
/** The webhook object type - always "page" for Messenger */
|
|
1041
|
+
object: 'page';
|
|
1042
|
+
/** Array of webhook entries containing the actual events */
|
|
1043
|
+
entry: Array<{
|
|
1044
|
+
/** Page ID */
|
|
1045
|
+
id: string;
|
|
1046
|
+
/** Timestamp of the webhook entry */
|
|
1047
|
+
time: number;
|
|
1048
|
+
/** Array of messaging events - contains the postback event */
|
|
1049
|
+
messaging: MessagingPostbackWebhookEvent[];
|
|
1050
|
+
}>;
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* Type guard to check if a webhook event is a messaging postback event
|
|
1054
|
+
*
|
|
1055
|
+
* @param event - The webhook event to check
|
|
1056
|
+
* @returns True if the event contains a postback property
|
|
1057
|
+
*
|
|
1058
|
+
* @example
|
|
1059
|
+
* ```typescript
|
|
1060
|
+
* if (isMessagingPostbackEvent(event)) {
|
|
1061
|
+
* // TypeScript now knows event has postback property
|
|
1062
|
+
* console.log(`User clicked: ${event.postback.title}`);
|
|
1063
|
+
* console.log(`Payload: ${event.postback.payload}`);
|
|
1064
|
+
* }
|
|
1065
|
+
* ```
|
|
1066
|
+
*/
|
|
1067
|
+
declare function isMessagingPostbackEvent(event: any): event is MessagingPostbackWebhookEvent;
|
|
1068
|
+
/**
|
|
1069
|
+
* Type guard to check if a postback event includes referral data
|
|
1070
|
+
*
|
|
1071
|
+
* @param event - The messaging postback event to check
|
|
1072
|
+
* @returns True if the event contains referral information
|
|
1073
|
+
*
|
|
1074
|
+
* @example
|
|
1075
|
+
* ```typescript
|
|
1076
|
+
* if (hasReferralData(event)) {
|
|
1077
|
+
* // Handle referred conversation
|
|
1078
|
+
* console.log(`Referred from: ${event.postback.referral.source}`);
|
|
1079
|
+
* console.log(`Ref parameter: ${event.postback.referral.ref}`);
|
|
1080
|
+
* }
|
|
1081
|
+
* ```
|
|
1082
|
+
*/
|
|
1083
|
+
declare function hasReferralData(event: MessagingPostbackWebhookEvent): event is MessagingPostbackWebhookEvent & {
|
|
1084
|
+
postback: PostbackData & {
|
|
1085
|
+
referral: PostbackReferral;
|
|
1086
|
+
};
|
|
1087
|
+
};
|
|
1088
|
+
/**
|
|
1089
|
+
* Type guard to check if sender is identified (has PSID) vs anonymous (has user_ref)
|
|
1090
|
+
*
|
|
1091
|
+
* @param sender - The sender object to check
|
|
1092
|
+
* @returns True if sender has a PSID (is identified)
|
|
1093
|
+
*
|
|
1094
|
+
* @example
|
|
1095
|
+
* ```typescript
|
|
1096
|
+
* if (isIdentifiedSender(event.sender)) {
|
|
1097
|
+
* // User has been identified and has a PSID
|
|
1098
|
+
* console.log(`User PSID: ${event.sender.id}`);
|
|
1099
|
+
* } else {
|
|
1100
|
+
* // Anonymous user with user_ref (likely from chat plugin)
|
|
1101
|
+
* console.log(`Anonymous user ref: ${event.sender.user_ref}`);
|
|
1102
|
+
* }
|
|
1103
|
+
* ```
|
|
1104
|
+
*/
|
|
1105
|
+
declare function isIdentifiedSender(sender: PostbackSender): sender is PostbackSender & {
|
|
1106
|
+
id: string;
|
|
1107
|
+
};
|
|
1108
|
+
/**
|
|
1109
|
+
* Utility type for extracting just the postback data from a webhook event
|
|
1110
|
+
*/
|
|
1111
|
+
type PostbackEventData = PostbackData;
|
|
1112
|
+
/**
|
|
1113
|
+
* Utility type for common postback properties that might be used in processing
|
|
1114
|
+
*/
|
|
1115
|
+
interface PostbackProcessingContext {
|
|
1116
|
+
/** The postback payload data */
|
|
1117
|
+
payload: string;
|
|
1118
|
+
/** The user who triggered the postback (PSID or user_ref) */
|
|
1119
|
+
senderId?: string;
|
|
1120
|
+
/** User reference for anonymous users */
|
|
1121
|
+
userRef?: string;
|
|
1122
|
+
/** The page that received the postback */
|
|
1123
|
+
recipientId: string;
|
|
1124
|
+
/** Button title if available */
|
|
1125
|
+
buttonTitle?: string;
|
|
1126
|
+
/** Message ID if available */
|
|
1127
|
+
messageId?: string;
|
|
1128
|
+
/** When the postback occurred */
|
|
1129
|
+
timestamp: number;
|
|
1130
|
+
/** Referral context if present */
|
|
1131
|
+
referralContext?: {
|
|
1132
|
+
ref?: string;
|
|
1133
|
+
source?: string;
|
|
1134
|
+
type?: string;
|
|
1135
|
+
};
|
|
1136
|
+
/** Whether this is from a referred conversation */
|
|
1137
|
+
isReferred: boolean;
|
|
1138
|
+
/** Whether the sender is identified (has PSID) */
|
|
1139
|
+
isIdentifiedUser: boolean;
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* Helper function to extract processing context from a messaging postback event
|
|
1143
|
+
*
|
|
1144
|
+
* @param event - The messaging postback webhook event
|
|
1145
|
+
* @returns Simplified processing context with all relevant data
|
|
1146
|
+
*
|
|
1147
|
+
* @example
|
|
1148
|
+
* ```typescript
|
|
1149
|
+
* const context = extractPostbackContext(webhookEvent);
|
|
1150
|
+
*
|
|
1151
|
+
* if (context.isReferred) {
|
|
1152
|
+
* console.log(`New conversation from ${context.referralContext?.source}`);
|
|
1153
|
+
* }
|
|
1154
|
+
*
|
|
1155
|
+
* if (context.isIdentifiedUser) {
|
|
1156
|
+
* console.log(`Known user ${context.senderId} clicked: ${context.payload}`);
|
|
1157
|
+
* } else {
|
|
1158
|
+
* console.log(`Anonymous user ${context.userRef} clicked: ${context.payload}`);
|
|
1159
|
+
* }
|
|
1160
|
+
* ```
|
|
1161
|
+
*/
|
|
1162
|
+
declare function extractPostbackContext(event: MessagingPostbackWebhookEvent): PostbackProcessingContext;
|
|
1163
|
+
/**
|
|
1164
|
+
* Common postback payload patterns used in Messenger bots
|
|
1165
|
+
*/
|
|
1166
|
+
declare const COMMON_POSTBACK_PAYLOADS: {
|
|
1167
|
+
/** Get Started button payload */
|
|
1168
|
+
readonly GET_STARTED: "GET_STARTED";
|
|
1169
|
+
/** Main menu navigation */
|
|
1170
|
+
readonly MAIN_MENU: "MAIN_MENU";
|
|
1171
|
+
/** Help/Support options */
|
|
1172
|
+
readonly HELP: "HELP";
|
|
1173
|
+
readonly SUPPORT: "SUPPORT";
|
|
1174
|
+
/** Contact information */
|
|
1175
|
+
readonly CONTACT: "CONTACT";
|
|
1176
|
+
readonly CONTACT_SALES: "CONTACT_SALES";
|
|
1177
|
+
readonly CONTACT_SUPPORT: "CONTACT_SUPPORT";
|
|
1178
|
+
/** Navigation actions */
|
|
1179
|
+
readonly BACK: "BACK";
|
|
1180
|
+
readonly NEXT: "NEXT";
|
|
1181
|
+
readonly CANCEL: "CANCEL";
|
|
1182
|
+
/** User preferences */
|
|
1183
|
+
readonly SETTINGS: "SETTINGS";
|
|
1184
|
+
readonly PREFERENCES: "PREFERENCES";
|
|
1185
|
+
};
|
|
1186
|
+
/**
|
|
1187
|
+
* Constants related to postback events and constraints
|
|
1188
|
+
*/
|
|
1189
|
+
declare const POSTBACK_CONSTANTS: {
|
|
1190
|
+
/** Maximum payload length in characters */
|
|
1191
|
+
readonly MAX_PAYLOAD_LENGTH: 1000;
|
|
1192
|
+
/** Webhook event type identifier */
|
|
1193
|
+
readonly EVENT_TYPE: "postback";
|
|
1194
|
+
/** Common referral sources */
|
|
1195
|
+
readonly REFERRAL_SOURCES: {
|
|
1196
|
+
readonly SHORTLINK: "SHORTLINK";
|
|
1197
|
+
readonly ADS: "ADS";
|
|
1198
|
+
readonly MESSENGER_CODE: "MESSENGER_CODE";
|
|
1199
|
+
};
|
|
1200
|
+
/** Common referral types */
|
|
1201
|
+
readonly REFERRAL_TYPES: {
|
|
1202
|
+
readonly OPEN_THREAD: "OPEN_THREAD";
|
|
1203
|
+
};
|
|
1204
|
+
};
|
|
1205
|
+
/**
|
|
1206
|
+
* Type for postback payload values - can be custom strings or common patterns
|
|
1207
|
+
*/
|
|
1208
|
+
type PostbackPayload = string | typeof COMMON_POSTBACK_PAYLOADS[keyof typeof COMMON_POSTBACK_PAYLOADS];
|
|
1209
|
+
/**
|
|
1210
|
+
* Type for referral sources
|
|
1211
|
+
*/
|
|
1212
|
+
type ReferralSource$1 = typeof POSTBACK_CONSTANTS.REFERRAL_SOURCES[keyof typeof POSTBACK_CONSTANTS.REFERRAL_SOURCES] | string;
|
|
1213
|
+
/**
|
|
1214
|
+
* Type for referral types
|
|
1215
|
+
*/
|
|
1216
|
+
type ReferralType$1 = typeof POSTBACK_CONSTANTS.REFERRAL_TYPES[keyof typeof POSTBACK_CONSTANTS.REFERRAL_TYPES] | string;
|
|
1217
|
+
|
|
1218
|
+
/**
|
|
1219
|
+
* Facebook Messenger Platform - Customer Feedback Webhook Types
|
|
1220
|
+
*
|
|
1221
|
+
* These types represent the webhook event structure for messaging_feedback events.
|
|
1222
|
+
* Triggered when a user submits feedback through a Customer Feedback Template.
|
|
1223
|
+
*
|
|
1224
|
+
* @see https://developers.facebook.com/docs/messenger-platform/send-messages/templates/customer-feedback-template
|
|
1225
|
+
*/
|
|
1226
|
+
/**
|
|
1227
|
+
* Available feedback types for customer feedback templates
|
|
1228
|
+
*/
|
|
1229
|
+
declare enum FeedbackType {
|
|
1230
|
+
/** Customer Satisfaction - Score range 1-5 */
|
|
1231
|
+
CSAT = "csat",
|
|
1232
|
+
/** Net Promoter Score - Score range 0-10 */
|
|
1233
|
+
NPS = "nps",
|
|
1234
|
+
/** Customer Effort Score - Score range 1-7 */
|
|
1235
|
+
CES = "ces"
|
|
1236
|
+
}
|
|
1237
|
+
/**
|
|
1238
|
+
* Available display options for CSAT feedback type
|
|
1239
|
+
*/
|
|
1240
|
+
declare enum CSATDisplayOption {
|
|
1241
|
+
/** Numeric scale from 1 to 5 */
|
|
1242
|
+
ONE_TO_FIVE = "one_to_five",
|
|
1243
|
+
/** Five star rating display */
|
|
1244
|
+
FIVE_STARS = "five_stars",
|
|
1245
|
+
/** Five emoji rating display */
|
|
1246
|
+
FIVE_EMOJIS = "five_emojis"
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Available display options for NPS feedback type
|
|
1250
|
+
*/
|
|
1251
|
+
declare enum NPSDisplayOption {
|
|
1252
|
+
/** Numeric scale from 0 to 10 */
|
|
1253
|
+
ZERO_TO_TEN = "zero_to_ten"
|
|
1254
|
+
}
|
|
1255
|
+
/**
|
|
1256
|
+
* Available display options for CES feedback type
|
|
1257
|
+
*/
|
|
1258
|
+
declare enum CESDisplayOption {
|
|
1259
|
+
/** Numeric scale from 1 to 7 */
|
|
1260
|
+
ONE_TO_SEVEN = "one_to_seven"
|
|
1261
|
+
}
|
|
1262
|
+
/**
|
|
1263
|
+
* Follow-up feedback type for optional text input
|
|
1264
|
+
*/
|
|
1265
|
+
declare enum FollowUpType {
|
|
1266
|
+
/** Free-form text input (max 400 characters) */
|
|
1267
|
+
FREE_FORM = "free_form"
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Represents the sender information in a messaging feedback webhook event
|
|
1271
|
+
*/
|
|
1272
|
+
interface MessagingFeedbackSender {
|
|
1273
|
+
/** Page-scoped ID (PSID) of the user who submitted the feedback */
|
|
1274
|
+
id: string;
|
|
1275
|
+
/**
|
|
1276
|
+
* User reference provided by the chat plugin, if applicable.
|
|
1277
|
+
* Only present for chat plugin events.
|
|
1278
|
+
*/
|
|
1279
|
+
user_ref?: string;
|
|
1280
|
+
}
|
|
1281
|
+
/**
|
|
1282
|
+
* Represents the recipient information in a messaging feedback webhook event
|
|
1283
|
+
*/
|
|
1284
|
+
interface MessagingFeedbackRecipient {
|
|
1285
|
+
/** Page ID that received the feedback */
|
|
1286
|
+
id: string;
|
|
1287
|
+
}
|
|
1288
|
+
/**
|
|
1289
|
+
* Represents optional follow-up feedback data
|
|
1290
|
+
*/
|
|
1291
|
+
interface FeedbackFollowUp {
|
|
1292
|
+
/** Type of follow-up feedback - currently only supports free_form */
|
|
1293
|
+
type: FollowUpType.FREE_FORM;
|
|
1294
|
+
/**
|
|
1295
|
+
* User-provided text feedback.
|
|
1296
|
+
* Limited to 400 characters maximum.
|
|
1297
|
+
*/
|
|
1298
|
+
payload: string;
|
|
1299
|
+
}
|
|
1300
|
+
/**
|
|
1301
|
+
* Represents individual question feedback data within a screen
|
|
1302
|
+
*/
|
|
1303
|
+
interface FeedbackQuestion {
|
|
1304
|
+
/**
|
|
1305
|
+
* Type of feedback question (CSAT, NPS, or CES).
|
|
1306
|
+
* Determines the scoring range and display format.
|
|
1307
|
+
*/
|
|
1308
|
+
type: FeedbackType;
|
|
1309
|
+
/**
|
|
1310
|
+
* Numeric score provided by the user.
|
|
1311
|
+
* Range depends on feedback type:
|
|
1312
|
+
* - CSAT: 1-5
|
|
1313
|
+
* - NPS: 0-10
|
|
1314
|
+
* - CES: 1-7
|
|
1315
|
+
*/
|
|
1316
|
+
payload: string;
|
|
1317
|
+
/**
|
|
1318
|
+
* Optional follow-up text feedback from the user.
|
|
1319
|
+
* Only present if the template included a text input field.
|
|
1320
|
+
*/
|
|
1321
|
+
follow_up?: FeedbackFollowUp;
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Represents a feedback screen containing questions and responses
|
|
1325
|
+
*/
|
|
1326
|
+
interface FeedbackScreen {
|
|
1327
|
+
/**
|
|
1328
|
+
* Screen identifier within the feedback template.
|
|
1329
|
+
* Typically 0 for single-screen templates.
|
|
1330
|
+
*/
|
|
1331
|
+
screen_id: number;
|
|
1332
|
+
/**
|
|
1333
|
+
* Map of question IDs to their corresponding feedback responses.
|
|
1334
|
+
* Question IDs are defined when creating the feedback template.
|
|
1335
|
+
*/
|
|
1336
|
+
questions: Record<string, FeedbackQuestion>;
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* Main messaging feedback data structure
|
|
1340
|
+
*/
|
|
1341
|
+
interface MessagingFeedbackData {
|
|
1342
|
+
/**
|
|
1343
|
+
* Array of feedback screens with user responses.
|
|
1344
|
+
* Each screen contains questions and their answers.
|
|
1345
|
+
*/
|
|
1346
|
+
feedback_screens: FeedbackScreen[];
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* Main webhook event structure for messaging feedback
|
|
1350
|
+
*
|
|
1351
|
+
* This event is triggered when a user submits feedback through a
|
|
1352
|
+
* Customer Feedback Template. The webhook provides the user's
|
|
1353
|
+
* scores and optional text feedback.
|
|
1354
|
+
*
|
|
1355
|
+
* @example
|
|
1356
|
+
* ```json
|
|
1357
|
+
* {
|
|
1358
|
+
* "sender": {
|
|
1359
|
+
* "id": "1234567890123456"
|
|
1360
|
+
* },
|
|
1361
|
+
* "recipient": {
|
|
1362
|
+
* "id": "9876543210987654"
|
|
1363
|
+
* },
|
|
1364
|
+
* "timestamp": 1458668856463,
|
|
1365
|
+
* "messaging_feedback": {
|
|
1366
|
+
* "feedback_screens": [{
|
|
1367
|
+
* "screen_id": 0,
|
|
1368
|
+
* "questions": {
|
|
1369
|
+
* "satisfaction_q1": {
|
|
1370
|
+
* "type": "csat",
|
|
1371
|
+
* "payload": "4",
|
|
1372
|
+
* "follow_up": {
|
|
1373
|
+
* "type": "free_form",
|
|
1374
|
+
* "payload": "Good service overall!"
|
|
1375
|
+
* }
|
|
1376
|
+
* }
|
|
1377
|
+
* }
|
|
1378
|
+
* }]
|
|
1379
|
+
* }
|
|
1380
|
+
* }
|
|
1381
|
+
* ```
|
|
1382
|
+
*/
|
|
1383
|
+
interface MessagingFeedbackWebhookEvent {
|
|
1384
|
+
/** Information about the user who submitted the feedback */
|
|
1385
|
+
sender: MessagingFeedbackSender;
|
|
1386
|
+
/** Information about the page that received the feedback */
|
|
1387
|
+
recipient: MessagingFeedbackRecipient;
|
|
1388
|
+
/**
|
|
1389
|
+
* Timestamp when the feedback was submitted (in milliseconds since epoch).
|
|
1390
|
+
* Represents when the user completed and submitted the feedback form.
|
|
1391
|
+
*/
|
|
1392
|
+
timestamp: number;
|
|
1393
|
+
/** The actual feedback data containing user responses */
|
|
1394
|
+
messaging_feedback: MessagingFeedbackData;
|
|
1395
|
+
}
|
|
1396
|
+
/**
|
|
1397
|
+
* Complete webhook payload structure that includes the messaging feedback event
|
|
1398
|
+
* along with other webhook metadata
|
|
1399
|
+
*/
|
|
1400
|
+
interface MessagingFeedbackWebhookPayload {
|
|
1401
|
+
/** The webhook object type - always "page" for Messenger */
|
|
1402
|
+
object: 'page';
|
|
1403
|
+
/** Array of webhook entries containing the actual events */
|
|
1404
|
+
entry: Array<{
|
|
1405
|
+
/** Page ID */
|
|
1406
|
+
id: string;
|
|
1407
|
+
/** Timestamp of the webhook entry */
|
|
1408
|
+
time: number;
|
|
1409
|
+
/** Array of messaging events - contains the feedback event */
|
|
1410
|
+
messaging: MessagingFeedbackWebhookEvent[];
|
|
1411
|
+
}>;
|
|
1412
|
+
}
|
|
1413
|
+
/**
|
|
1414
|
+
* Type guard to check if a webhook event is a messaging feedback event
|
|
1415
|
+
*
|
|
1416
|
+
* @param event - The webhook event to check
|
|
1417
|
+
* @returns True if the event contains a messaging_feedback property
|
|
1418
|
+
*
|
|
1419
|
+
* @example
|
|
1420
|
+
* ```typescript
|
|
1421
|
+
* if (isMessagingFeedbackEvent(event)) {
|
|
1422
|
+
* // TypeScript now knows event has messaging_feedback property
|
|
1423
|
+
* console.log(`Received feedback with ${event.messaging_feedback.feedback_screens.length} screens`);
|
|
1424
|
+
* }
|
|
1425
|
+
* ```
|
|
1426
|
+
*/
|
|
1427
|
+
declare function isMessagingFeedbackEvent(event: any): event is MessagingFeedbackWebhookEvent;
|
|
1428
|
+
/**
|
|
1429
|
+
* Utility type for common feedback properties that might be used in processing
|
|
1430
|
+
*/
|
|
1431
|
+
interface MessagingFeedbackProcessingContext {
|
|
1432
|
+
/** The user who submitted the feedback */
|
|
1433
|
+
senderId: string;
|
|
1434
|
+
/** The page that received the feedback */
|
|
1435
|
+
recipientId: string;
|
|
1436
|
+
/** When the feedback was submitted */
|
|
1437
|
+
submissionTimestamp: number;
|
|
1438
|
+
/** Total number of feedback screens */
|
|
1439
|
+
screenCount: number;
|
|
1440
|
+
/** All question responses flattened from all screens */
|
|
1441
|
+
allResponses: Array<{
|
|
1442
|
+
questionId: string;
|
|
1443
|
+
feedbackType: FeedbackType;
|
|
1444
|
+
score: number;
|
|
1445
|
+
textFeedback?: string;
|
|
1446
|
+
screenId: number;
|
|
1447
|
+
}>;
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* Helper function to extract processing context from a messaging feedback event
|
|
1451
|
+
*
|
|
1452
|
+
* @param event - The messaging feedback webhook event
|
|
1453
|
+
* @returns Simplified processing context with flattened responses
|
|
1454
|
+
*
|
|
1455
|
+
* @example
|
|
1456
|
+
* ```typescript
|
|
1457
|
+
* const context = extractMessagingFeedbackContext(webhookEvent);
|
|
1458
|
+
* console.log(`User ${context.senderId} submitted ${context.allResponses.length} feedback responses`);
|
|
1459
|
+
* context.allResponses.forEach(response => {
|
|
1460
|
+
* console.log(`${response.questionId}: ${response.score}/10 (${response.feedbackType})`);
|
|
1461
|
+
* });
|
|
1462
|
+
* ```
|
|
1463
|
+
*/
|
|
1464
|
+
declare function extractMessagingFeedbackContext(event: MessagingFeedbackWebhookEvent): MessagingFeedbackProcessingContext;
|
|
1465
|
+
/**
|
|
1466
|
+
* Helper function to get feedback scores by type from an event
|
|
1467
|
+
*
|
|
1468
|
+
* @param event - The messaging feedback webhook event
|
|
1469
|
+
* @returns Map of feedback types to their scores
|
|
1470
|
+
*
|
|
1471
|
+
* @example
|
|
1472
|
+
* ```typescript
|
|
1473
|
+
* const scores = getFeedbackScoresByType(webhookEvent);
|
|
1474
|
+
* const csatScore = scores.get(FeedbackType.CSAT); // number | undefined
|
|
1475
|
+
* const npsScore = scores.get(FeedbackType.NPS); // number | undefined
|
|
1476
|
+
* ```
|
|
1477
|
+
*/
|
|
1478
|
+
declare function getFeedbackScoresByType(event: MessagingFeedbackWebhookEvent): Map<FeedbackType, number[]>;
|
|
1479
|
+
/**
|
|
1480
|
+
* Helper function to extract all text feedback from an event
|
|
1481
|
+
*
|
|
1482
|
+
* @param event - The messaging feedback webhook event
|
|
1483
|
+
* @returns Array of text feedback strings
|
|
1484
|
+
*
|
|
1485
|
+
* @example
|
|
1486
|
+
* ```typescript
|
|
1487
|
+
* const textFeedback = extractTextFeedback(webhookEvent);
|
|
1488
|
+
* textFeedback.forEach(feedback => {
|
|
1489
|
+
* console.log(`User comment: "${feedback}"`);
|
|
1490
|
+
* });
|
|
1491
|
+
* ```
|
|
1492
|
+
*/
|
|
1493
|
+
declare function extractTextFeedback(event: MessagingFeedbackWebhookEvent): string[];
|
|
1494
|
+
/**
|
|
1495
|
+
* Constants related to customer feedback constraints and limits
|
|
1496
|
+
*/
|
|
1497
|
+
declare const MESSAGING_FEEDBACK_CONSTANTS: {
|
|
1498
|
+
/** Maximum characters allowed in free-form text feedback */
|
|
1499
|
+
readonly MAX_TEXT_FEEDBACK_LENGTH: 400;
|
|
1500
|
+
/** Score ranges for different feedback types */
|
|
1501
|
+
readonly SCORE_RANGES: {
|
|
1502
|
+
readonly csat: {
|
|
1503
|
+
readonly min: 1;
|
|
1504
|
+
readonly max: 5;
|
|
1505
|
+
};
|
|
1506
|
+
readonly nps: {
|
|
1507
|
+
readonly min: 0;
|
|
1508
|
+
readonly max: 10;
|
|
1509
|
+
};
|
|
1510
|
+
readonly ces: {
|
|
1511
|
+
readonly min: 1;
|
|
1512
|
+
readonly max: 7;
|
|
1513
|
+
};
|
|
1514
|
+
};
|
|
1515
|
+
/** Template expiry constraints */
|
|
1516
|
+
readonly TEMPLATE_EXPIRY: {
|
|
1517
|
+
/** Minimum expiry days */
|
|
1518
|
+
readonly MIN_DAYS: 1;
|
|
1519
|
+
/** Maximum expiry days */
|
|
1520
|
+
readonly MAX_DAYS: 7;
|
|
1521
|
+
/** Default expiry days */
|
|
1522
|
+
readonly DEFAULT_DAYS: 1;
|
|
1523
|
+
};
|
|
1524
|
+
/** Question ID constraints */
|
|
1525
|
+
readonly QUESTION_ID: {
|
|
1526
|
+
/** Maximum length for question IDs */
|
|
1527
|
+
readonly MAX_LENGTH: 80;
|
|
1528
|
+
/** Valid characters pattern (alphanumeric) */
|
|
1529
|
+
readonly VALID_PATTERN: RegExp;
|
|
1530
|
+
};
|
|
1531
|
+
/** Template limits */
|
|
1532
|
+
readonly TEMPLATE_LIMITS: {
|
|
1533
|
+
/** Maximum number of titles per template */
|
|
1534
|
+
readonly MAX_TITLES: 1;
|
|
1535
|
+
/** Maximum number of scoring components per template */
|
|
1536
|
+
readonly MAX_SCORING_COMPONENTS: 1;
|
|
1537
|
+
};
|
|
1538
|
+
/** Webhook event type identifier */
|
|
1539
|
+
readonly EVENT_TYPE: "messaging_feedback";
|
|
1540
|
+
};
|
|
1541
|
+
/**
|
|
1542
|
+
* Validation helper to check if a score is valid for a given feedback type
|
|
1543
|
+
*
|
|
1544
|
+
* @param feedbackType - The type of feedback being validated
|
|
1545
|
+
* @param score - The score to validate
|
|
1546
|
+
* @returns True if the score is within the valid range for the feedback type
|
|
1547
|
+
*
|
|
1548
|
+
* @example
|
|
1549
|
+
* ```typescript
|
|
1550
|
+
* const isValid = isValidFeedbackScore(FeedbackType.CSAT, 4); // true
|
|
1551
|
+
* const isInvalid = isValidFeedbackScore(FeedbackType.NPS, 15); // false
|
|
1552
|
+
* ```
|
|
1553
|
+
*/
|
|
1554
|
+
declare function isValidFeedbackScore(feedbackType: FeedbackType, score: number): boolean;
|
|
1555
|
+
/**
|
|
1556
|
+
* Validation helper to check if a question ID is valid
|
|
1557
|
+
*
|
|
1558
|
+
* @param questionId - The question ID to validate
|
|
1559
|
+
* @returns True if the question ID meets the format requirements
|
|
1560
|
+
*
|
|
1561
|
+
* @example
|
|
1562
|
+
* ```typescript
|
|
1563
|
+
* const isValid = isValidQuestionId('satisfaction_q1'); // true
|
|
1564
|
+
* const isInvalid = isValidQuestionId('invalid-id!'); // false
|
|
1565
|
+
* ```
|
|
1566
|
+
*/
|
|
1567
|
+
declare function isValidQuestionId(questionId: string): boolean;
|
|
1568
|
+
/**
|
|
1569
|
+
* Validation helper to check if text feedback is within character limits
|
|
1570
|
+
*
|
|
1571
|
+
* @param textFeedback - The text feedback to validate
|
|
1572
|
+
* @returns True if the text is within the character limit
|
|
1573
|
+
*
|
|
1574
|
+
* @example
|
|
1575
|
+
* ```typescript
|
|
1576
|
+
* const isValid = isValidTextFeedback('Great service!'); // true
|
|
1577
|
+
* const isInvalid = isValidTextFeedback('a'.repeat(500)); // false
|
|
1578
|
+
* ```
|
|
1579
|
+
*/
|
|
1580
|
+
declare function isValidTextFeedback(textFeedback: string): boolean;
|
|
1581
|
+
|
|
1582
|
+
/**
|
|
1583
|
+
* Facebook Messenger Platform - Messages Webhook Types
|
|
1584
|
+
*
|
|
1585
|
+
* These types represent the webhook event structure for messages events.
|
|
1586
|
+
* Triggered when a user sends a message to your page.
|
|
1587
|
+
*
|
|
1588
|
+
* @see https://developers.facebook.com/docs/messenger-platform/reference/webhook-events/messages
|
|
1589
|
+
*/
|
|
1590
|
+
/**
|
|
1591
|
+
* Enumeration of attachment types supported by the Messenger Platform
|
|
1592
|
+
*/
|
|
1593
|
+
declare enum AttachmentType {
|
|
1594
|
+
AUDIO = "audio",
|
|
1595
|
+
FILE = "file",
|
|
1596
|
+
IMAGE = "image",
|
|
1597
|
+
VIDEO = "video",
|
|
1598
|
+
FALLBACK = "fallback",
|
|
1599
|
+
REEL = "reel",
|
|
1600
|
+
IG_REEL = "ig_reel"
|
|
1601
|
+
}
|
|
1602
|
+
/**
|
|
1603
|
+
* Enumeration of referral types for message referrals
|
|
1604
|
+
*/
|
|
1605
|
+
declare enum ReferralType {
|
|
1606
|
+
OPEN_THREAD = "OPEN_THREAD",
|
|
1607
|
+
PRODUCT = "product",
|
|
1608
|
+
ADS = "ads"
|
|
1609
|
+
}
|
|
1610
|
+
/**
|
|
1611
|
+
* Enumeration of referral sources
|
|
1612
|
+
*/
|
|
1613
|
+
declare enum ReferralSource {
|
|
1614
|
+
MESSENGER_CODE = "MESSENGER_CODE",
|
|
1615
|
+
DISCOVER_TAB = "DISCOVER_TAB",
|
|
1616
|
+
ADS = "ADS",
|
|
1617
|
+
SHORTLINK = "SHORTLINK",
|
|
1618
|
+
CUSTOMER_CHAT_PLUGIN = "CUSTOMER_CHAT_PLUGIN"
|
|
1619
|
+
}
|
|
1620
|
+
/**
|
|
1621
|
+
* Represents the sender information in a message webhook event
|
|
1622
|
+
*/
|
|
1623
|
+
interface MessageSender {
|
|
1624
|
+
/** Page-scoped ID (PSID) of the user who sent the message */
|
|
1625
|
+
id: string;
|
|
1626
|
+
/**
|
|
1627
|
+
* User reference provided by the chat plugin, if applicable.
|
|
1628
|
+
* Only present for chat plugin events.
|
|
1629
|
+
*/
|
|
1630
|
+
user_ref?: string;
|
|
1631
|
+
}
|
|
1632
|
+
/**
|
|
1633
|
+
* Represents the recipient information in a message webhook event
|
|
1634
|
+
*/
|
|
1635
|
+
interface MessageRecipient {
|
|
1636
|
+
/** Page ID that received the message */
|
|
1637
|
+
id: string;
|
|
1638
|
+
}
|
|
1639
|
+
/**
|
|
1640
|
+
* Represents a quick reply payload in a message
|
|
1641
|
+
*/
|
|
1642
|
+
interface QuickReply {
|
|
1643
|
+
/**
|
|
1644
|
+
* The payload string that was defined when the quick reply was sent.
|
|
1645
|
+
* Maximum 1000 characters.
|
|
1646
|
+
*/
|
|
1647
|
+
payload: string;
|
|
1648
|
+
}
|
|
1649
|
+
/**
|
|
1650
|
+
* Represents the reply-to information when a message is a reply
|
|
1651
|
+
*/
|
|
1652
|
+
interface ReplyTo {
|
|
1653
|
+
/**
|
|
1654
|
+
* Message ID of the message being replied to
|
|
1655
|
+
*/
|
|
1656
|
+
mid: string;
|
|
1657
|
+
}
|
|
1658
|
+
/**
|
|
1659
|
+
* Base attachment payload interface
|
|
1660
|
+
*/
|
|
1661
|
+
interface BaseAttachmentPayload {
|
|
1662
|
+
/** URL to the attachment file */
|
|
1663
|
+
url: string;
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Attachment payload for media files (audio, image, video, file)
|
|
1667
|
+
*/
|
|
1668
|
+
interface MediaAttachmentPayload extends BaseAttachmentPayload {
|
|
1669
|
+
/** URL to the attachment file */
|
|
1670
|
+
url: string;
|
|
1671
|
+
/** Title of the attachment, if available */
|
|
1672
|
+
title?: string;
|
|
1673
|
+
}
|
|
1674
|
+
/**
|
|
1675
|
+
* Attachment payload for sticker attachments
|
|
1676
|
+
*/
|
|
1677
|
+
interface StickerAttachmentPayload extends BaseAttachmentPayload {
|
|
1678
|
+
/** URL to the sticker image */
|
|
1679
|
+
url: string;
|
|
1680
|
+
/** Sticker ID for the sent sticker */
|
|
1681
|
+
sticker_id: number;
|
|
1682
|
+
}
|
|
1683
|
+
/**
|
|
1684
|
+
* Attachment payload for reel attachments (Instagram Reels, Facebook Reels)
|
|
1685
|
+
*/
|
|
1686
|
+
interface ReelAttachmentPayload extends BaseAttachmentPayload {
|
|
1687
|
+
/** URL to the reel */
|
|
1688
|
+
url: string;
|
|
1689
|
+
/** Video ID of the reel */
|
|
1690
|
+
reel_video_id?: number;
|
|
1691
|
+
}
|
|
1692
|
+
/**
|
|
1693
|
+
* Attachment payload for fallback attachments
|
|
1694
|
+
*/
|
|
1695
|
+
interface FallbackAttachmentPayload extends BaseAttachmentPayload {
|
|
1696
|
+
/** URL to the attachment */
|
|
1697
|
+
url: string;
|
|
1698
|
+
/** Title of the fallback attachment */
|
|
1699
|
+
title?: string;
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Union type for all possible attachment payload types
|
|
1703
|
+
*/
|
|
1704
|
+
type AttachmentPayload = MediaAttachmentPayload | StickerAttachmentPayload | ReelAttachmentPayload | FallbackAttachmentPayload;
|
|
1705
|
+
/**
|
|
1706
|
+
* Represents an attachment in a message
|
|
1707
|
+
*/
|
|
1708
|
+
interface MessageAttachment {
|
|
1709
|
+
/** The type of attachment */
|
|
1710
|
+
type: AttachmentType;
|
|
1711
|
+
/** The attachment payload containing the actual attachment data */
|
|
1712
|
+
payload: AttachmentPayload;
|
|
1713
|
+
}
|
|
1714
|
+
/**
|
|
1715
|
+
* Represents referral data in a message (for referral campaigns, ads, etc.)
|
|
1716
|
+
*/
|
|
1717
|
+
interface MessageReferral {
|
|
1718
|
+
/** The source of the referral */
|
|
1719
|
+
source: ReferralSource;
|
|
1720
|
+
/** The type of referral */
|
|
1721
|
+
type: ReferralType;
|
|
1722
|
+
/**
|
|
1723
|
+
* The optional ref parameter passed in the referral.
|
|
1724
|
+
* Maximum 250 characters.
|
|
1725
|
+
*/
|
|
1726
|
+
ref?: string;
|
|
1727
|
+
/**
|
|
1728
|
+
* URL of the website where the referral was triggered.
|
|
1729
|
+
* Only present for CUSTOMER_CHAT_PLUGIN source.
|
|
1730
|
+
*/
|
|
1731
|
+
referer_uri?: string;
|
|
1732
|
+
/**
|
|
1733
|
+
* Indicates whether the referral is from a guest user.
|
|
1734
|
+
* Only present for CUSTOMER_CHAT_PLUGIN source.
|
|
1735
|
+
*/
|
|
1736
|
+
is_guest_user?: boolean;
|
|
1737
|
+
/**
|
|
1738
|
+
* Product information for product referrals.
|
|
1739
|
+
* Only present when type is 'product'.
|
|
1740
|
+
*/
|
|
1741
|
+
product?: {
|
|
1742
|
+
/** Product ID */
|
|
1743
|
+
id: string;
|
|
1744
|
+
};
|
|
1745
|
+
/**
|
|
1746
|
+
* Ad information for ad referrals.
|
|
1747
|
+
* Only present when type is 'ads'.
|
|
1748
|
+
*/
|
|
1749
|
+
ads?: {
|
|
1750
|
+
/** Ad ID */
|
|
1751
|
+
id: string;
|
|
1752
|
+
/** Ad title */
|
|
1753
|
+
title?: string;
|
|
1754
|
+
/** Ad image URL */
|
|
1755
|
+
image_url?: string;
|
|
1756
|
+
};
|
|
1757
|
+
}
|
|
1758
|
+
/**
|
|
1759
|
+
* Represents a command in a message (for bot commands)
|
|
1760
|
+
*/
|
|
1761
|
+
interface MessageCommand {
|
|
1762
|
+
/** The name of the command */
|
|
1763
|
+
name: string;
|
|
1764
|
+
}
|
|
1765
|
+
/**
|
|
1766
|
+
* Represents the main message content in a webhook event
|
|
1767
|
+
*/
|
|
1768
|
+
interface Message {
|
|
1769
|
+
/**
|
|
1770
|
+
* Unique message identifier
|
|
1771
|
+
*/
|
|
1772
|
+
mid: string;
|
|
1773
|
+
/**
|
|
1774
|
+
* Text content of the message.
|
|
1775
|
+
* Present for text messages and messages with quick replies.
|
|
1776
|
+
* Maximum 2000 UTF-8 characters.
|
|
1777
|
+
*/
|
|
1778
|
+
text?: string;
|
|
1779
|
+
/**
|
|
1780
|
+
* Quick reply payload, if the message was sent as a response to a quick reply.
|
|
1781
|
+
* Only present when the user taps a quick reply button.
|
|
1782
|
+
*/
|
|
1783
|
+
quick_reply?: QuickReply;
|
|
1784
|
+
/**
|
|
1785
|
+
* Reply-to information, if this message is a reply to another message.
|
|
1786
|
+
* Only present when the user replies to a specific message.
|
|
1787
|
+
*/
|
|
1788
|
+
reply_to?: ReplyTo;
|
|
1789
|
+
/**
|
|
1790
|
+
* Array of attachments sent with the message.
|
|
1791
|
+
* Can include images, audio, video, files, location, etc.
|
|
1792
|
+
*/
|
|
1793
|
+
attachments?: MessageAttachment[];
|
|
1794
|
+
/**
|
|
1795
|
+
* Referral information, if the message came from a referral.
|
|
1796
|
+
* Present when users click on ads, m.me links, etc.
|
|
1797
|
+
*/
|
|
1798
|
+
referral?: MessageReferral;
|
|
1799
|
+
/**
|
|
1800
|
+
* Array of commands, if the message contains bot commands.
|
|
1801
|
+
* Present when users send commands like /start, /help, etc.
|
|
1802
|
+
*/
|
|
1803
|
+
commands?: MessageCommand[];
|
|
1804
|
+
}
|
|
1805
|
+
/**
|
|
1806
|
+
* Main webhook event structure for messages
|
|
1807
|
+
*
|
|
1808
|
+
* This event is triggered when a user sends a message to your page.
|
|
1809
|
+
* The webhook provides the message content and metadata.
|
|
1810
|
+
*
|
|
1811
|
+
* @example Text message:
|
|
1812
|
+
* ```json
|
|
1813
|
+
* {
|
|
1814
|
+
* "sender": {
|
|
1815
|
+
* "id": "1234567890123456"
|
|
1816
|
+
* },
|
|
1817
|
+
* "recipient": {
|
|
1818
|
+
* "id": "9876543210987654"
|
|
1819
|
+
* },
|
|
1820
|
+
* "timestamp": 1458668856463,
|
|
1821
|
+
* "message": {
|
|
1822
|
+
* "mid": "mid.1458668856218:ed81099e15d3f4f233",
|
|
1823
|
+
* "text": "Hello, world!"
|
|
1824
|
+
* }
|
|
1825
|
+
* }
|
|
1826
|
+
* ```
|
|
1827
|
+
*
|
|
1828
|
+
* @example Message with attachment:
|
|
1829
|
+
* ```json
|
|
1830
|
+
* {
|
|
1831
|
+
* "sender": {
|
|
1832
|
+
* "id": "1234567890123456"
|
|
1833
|
+
* },
|
|
1834
|
+
* "recipient": {
|
|
1835
|
+
* "id": "9876543210987654"
|
|
1836
|
+
* },
|
|
1837
|
+
* "timestamp": 1458668856463,
|
|
1838
|
+
* "message": {
|
|
1839
|
+
* "mid": "mid.1458668856218:ed81099e15d3f4f233",
|
|
1840
|
+
* "attachments": [
|
|
1841
|
+
* {
|
|
1842
|
+
* "type": "image",
|
|
1843
|
+
* "payload": {
|
|
1844
|
+
* "url": "https://scontent.xx.fbcdn.net/v/image.jpg"
|
|
1845
|
+
* }
|
|
1846
|
+
* }
|
|
1847
|
+
* ]
|
|
1848
|
+
* }
|
|
1849
|
+
* }
|
|
1850
|
+
* ```
|
|
1851
|
+
*
|
|
1852
|
+
* @example Message with quick reply:
|
|
1853
|
+
* ```json
|
|
1854
|
+
* {
|
|
1855
|
+
* "sender": {
|
|
1856
|
+
* "id": "1234567890123456"
|
|
1857
|
+
* },
|
|
1858
|
+
* "recipient": {
|
|
1859
|
+
* "id": "9876543210987654"
|
|
1860
|
+
* },
|
|
1861
|
+
* "timestamp": 1458668856463,
|
|
1862
|
+
* "message": {
|
|
1863
|
+
* "mid": "mid.1458668856218:ed81099e15d3f4f233",
|
|
1864
|
+
* "text": "Yes",
|
|
1865
|
+
* "quick_reply": {
|
|
1866
|
+
* "payload": "YES_PAYLOAD"
|
|
1867
|
+
* }
|
|
1868
|
+
* }
|
|
1869
|
+
* }
|
|
1870
|
+
* ```
|
|
1871
|
+
*/
|
|
1872
|
+
interface MessageWebhookEvent {
|
|
1873
|
+
/** Information about the user who sent the message */
|
|
1874
|
+
sender: MessageSender;
|
|
1875
|
+
/** Information about the page that received the message */
|
|
1876
|
+
recipient: MessageRecipient;
|
|
1877
|
+
/**
|
|
1878
|
+
* Timestamp when the message was sent (in milliseconds since epoch).
|
|
1879
|
+
* Note: This represents when the message was sent, not when it was received.
|
|
1880
|
+
*/
|
|
1881
|
+
timestamp: number;
|
|
1882
|
+
/** The message content and metadata */
|
|
1883
|
+
message: Message;
|
|
1884
|
+
}
|
|
1885
|
+
/**
|
|
1886
|
+
* Complete webhook payload structure that includes the message event
|
|
1887
|
+
* along with other webhook metadata
|
|
1888
|
+
*/
|
|
1889
|
+
interface MessageWebhookPayload {
|
|
1890
|
+
/** The webhook object type - always "page" for Messenger */
|
|
1891
|
+
object: 'page';
|
|
1892
|
+
/** Array of webhook entries containing the actual events */
|
|
1893
|
+
entry: Array<{
|
|
1894
|
+
/** Page ID */
|
|
1895
|
+
id: string;
|
|
1896
|
+
/** Timestamp of the webhook entry */
|
|
1897
|
+
time: number;
|
|
1898
|
+
/** Array of messaging events - contains the message event */
|
|
1899
|
+
messaging: MessageWebhookEvent[];
|
|
1900
|
+
}>;
|
|
1901
|
+
}
|
|
1902
|
+
/**
|
|
1903
|
+
* Type guard to check if a webhook event is a message event
|
|
1904
|
+
*
|
|
1905
|
+
* @param event - The webhook event to check
|
|
1906
|
+
* @returns True if the event contains a message property
|
|
1907
|
+
*
|
|
1908
|
+
* @example
|
|
1909
|
+
* ```typescript
|
|
1910
|
+
* if (isMessageEvent(event)) {
|
|
1911
|
+
* // TypeScript now knows event has message property
|
|
1912
|
+
* console.log(`Received message: ${event.message.text || '[attachment]'}`);
|
|
1913
|
+
* }
|
|
1914
|
+
* ```
|
|
1915
|
+
*/
|
|
1916
|
+
declare function isMessageEvent(event: any): event is MessageWebhookEvent;
|
|
1917
|
+
/**
|
|
1918
|
+
* Type guard to check if a message has text content
|
|
1919
|
+
*
|
|
1920
|
+
* @param message - The message to check
|
|
1921
|
+
* @returns True if the message has text content
|
|
1922
|
+
*/
|
|
1923
|
+
declare function isTextMessage(message: Message): message is Message & {
|
|
1924
|
+
text: string;
|
|
1925
|
+
};
|
|
1926
|
+
/**
|
|
1927
|
+
* Type guard to check if a message has attachments
|
|
1928
|
+
*
|
|
1929
|
+
* @param message - The message to check
|
|
1930
|
+
* @returns True if the message has attachments
|
|
1931
|
+
*/
|
|
1932
|
+
declare function hasAttachments(message: Message): message is Message & {
|
|
1933
|
+
attachments: MessageAttachment[];
|
|
1934
|
+
};
|
|
1935
|
+
/**
|
|
1936
|
+
* Type guard to check if a message has a quick reply
|
|
1937
|
+
*
|
|
1938
|
+
* @param message - The message to check
|
|
1939
|
+
* @returns True if the message has a quick reply
|
|
1940
|
+
*/
|
|
1941
|
+
declare function hasQuickReply(message: Message): message is Message & {
|
|
1942
|
+
quick_reply: QuickReply;
|
|
1943
|
+
};
|
|
1944
|
+
/**
|
|
1945
|
+
* Type guard to check if a message is a reply to another message
|
|
1946
|
+
*
|
|
1947
|
+
* @param message - The message to check
|
|
1948
|
+
* @returns True if the message is a reply
|
|
1949
|
+
*/
|
|
1950
|
+
declare function isReplyMessage(message: Message): message is Message & {
|
|
1951
|
+
reply_to: ReplyTo;
|
|
1952
|
+
};
|
|
1953
|
+
/**
|
|
1954
|
+
* Type guard to check if a message has referral data
|
|
1955
|
+
*
|
|
1956
|
+
* @param message - The message to check
|
|
1957
|
+
* @returns True if the message has referral data
|
|
1958
|
+
*/
|
|
1959
|
+
declare function hasReferral(message: Message): message is Message & {
|
|
1960
|
+
referral: MessageReferral;
|
|
1961
|
+
};
|
|
1962
|
+
/**
|
|
1963
|
+
* Type guard to check if an attachment is a specific type
|
|
1964
|
+
*
|
|
1965
|
+
* @param attachment - The attachment to check
|
|
1966
|
+
* @param type - The attachment type to check for
|
|
1967
|
+
* @returns True if the attachment is of the specified type
|
|
1968
|
+
*/
|
|
1969
|
+
declare function isAttachmentType<T extends AttachmentType>(attachment: MessageAttachment, type: T): attachment is MessageAttachment & {
|
|
1970
|
+
type: T;
|
|
1971
|
+
};
|
|
1972
|
+
/**
|
|
1973
|
+
* Utility type for common message properties that might be used in processing
|
|
1974
|
+
*/
|
|
1975
|
+
interface MessageProcessingContext {
|
|
1976
|
+
/** The message ID */
|
|
1977
|
+
messageId: string;
|
|
1978
|
+
/** The user who sent the message */
|
|
1979
|
+
senderId: string;
|
|
1980
|
+
/** The page that received the message */
|
|
1981
|
+
recipientId: string;
|
|
1982
|
+
/** Message text content, if available */
|
|
1983
|
+
text?: string;
|
|
1984
|
+
/** Whether the message has attachments */
|
|
1985
|
+
hasAttachments: boolean;
|
|
1986
|
+
/** Whether the message is a quick reply */
|
|
1987
|
+
isQuickReply: boolean;
|
|
1988
|
+
/** Whether the message is a reply to another message */
|
|
1989
|
+
isReply: boolean;
|
|
1990
|
+
/** Whether the message has referral data */
|
|
1991
|
+
hasReferral: boolean;
|
|
1992
|
+
/** When the message was sent */
|
|
1993
|
+
timestamp: number;
|
|
1994
|
+
/** Quick reply payload, if available */
|
|
1995
|
+
quickReplyPayload?: string;
|
|
1996
|
+
/** Replied message ID, if this is a reply */
|
|
1997
|
+
repliedToMessageId?: string;
|
|
1998
|
+
}
|
|
1999
|
+
/**
|
|
2000
|
+
* Helper function to extract processing context from a message event
|
|
2001
|
+
*
|
|
2002
|
+
* @param event - The message webhook event
|
|
2003
|
+
* @returns Simplified processing context
|
|
2004
|
+
*
|
|
2005
|
+
* @example
|
|
2006
|
+
* ```typescript
|
|
2007
|
+
* const context = extractMessageContext(webhookEvent);
|
|
2008
|
+
* console.log(`User ${context.senderId} sent: "${context.text || '[attachment]'}"`);
|
|
2009
|
+
* if (context.isQuickReply) {
|
|
2010
|
+
* console.log(`Quick reply payload: ${context.quickReplyPayload}`);
|
|
2011
|
+
* }
|
|
2012
|
+
* ```
|
|
2013
|
+
*/
|
|
2014
|
+
declare function extractMessageContext(event: MessageWebhookEvent): MessageProcessingContext;
|
|
2015
|
+
/**
|
|
2016
|
+
* Helper function to get attachments of a specific type from a message
|
|
2017
|
+
*
|
|
2018
|
+
* @param message - The message to extract attachments from
|
|
2019
|
+
* @param type - The attachment type to filter by
|
|
2020
|
+
* @returns Array of attachments of the specified type
|
|
2021
|
+
*
|
|
2022
|
+
* @example
|
|
2023
|
+
* ```typescript
|
|
2024
|
+
* const images = getAttachmentsByType(message, AttachmentType.IMAGE);
|
|
2025
|
+
* console.log(`Message contains ${images.length} image(s)`);
|
|
2026
|
+
* ```
|
|
2027
|
+
*/
|
|
2028
|
+
declare function getAttachmentsByType<T extends AttachmentType>(message: Message, type: T): Array<MessageAttachment & {
|
|
2029
|
+
type: T;
|
|
2030
|
+
}>;
|
|
2031
|
+
/**
|
|
2032
|
+
* Helper function to extract all URLs from message attachments
|
|
2033
|
+
*
|
|
2034
|
+
* @param message - The message to extract URLs from
|
|
2035
|
+
* @returns Array of attachment URLs
|
|
2036
|
+
*
|
|
2037
|
+
* @example
|
|
2038
|
+
* ```typescript
|
|
2039
|
+
* const urls = getAttachmentUrls(message);
|
|
2040
|
+
* console.log(`Message contains ${urls.length} attachment(s)`);
|
|
2041
|
+
* ```
|
|
2042
|
+
*/
|
|
2043
|
+
declare function getAttachmentUrls(message: Message): string[];
|
|
2044
|
+
/**
|
|
2045
|
+
* Constants related to message limits and constraints
|
|
2046
|
+
*/
|
|
2047
|
+
declare const MESSAGE_CONSTANTS: {
|
|
2048
|
+
/** Maximum length of message text */
|
|
2049
|
+
readonly MAX_TEXT_LENGTH: 2000;
|
|
2050
|
+
/** Maximum length of quick reply payload */
|
|
2051
|
+
readonly MAX_QUICK_REPLY_PAYLOAD_LENGTH: 1000;
|
|
2052
|
+
/** Maximum length of referral ref parameter */
|
|
2053
|
+
readonly MAX_REFERRAL_REF_LENGTH: 250;
|
|
2054
|
+
/** Webhook event type identifier */
|
|
2055
|
+
readonly EVENT_TYPE: "message";
|
|
2056
|
+
};
|
|
2057
|
+
/**
|
|
2058
|
+
* Common attachment MIME types for validation
|
|
2059
|
+
*/
|
|
2060
|
+
declare const ATTACHMENT_MIME_TYPES: {
|
|
2061
|
+
readonly image: readonly ["image/jpeg", "image/png", "image/gif", "image/webp"];
|
|
2062
|
+
readonly video: readonly ["video/mp4", "video/avi", "video/quicktime", "video/webm"];
|
|
2063
|
+
readonly audio: readonly ["audio/mpeg", "audio/mp4", "audio/wav", "audio/ogg"];
|
|
2064
|
+
readonly file: readonly ["application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "text/plain"];
|
|
2065
|
+
};
|
|
2066
|
+
|
|
2067
|
+
/**
|
|
2068
|
+
* Facebook Messenger Webhook Events
|
|
2069
|
+
*
|
|
2070
|
+
* This file provides unified types for all webhook events supported by the Messenger Platform.
|
|
2071
|
+
* It includes a discriminated union type that allows TypeScript to narrow the event type
|
|
2072
|
+
* based on the event properties.
|
|
2073
|
+
*
|
|
2074
|
+
* @module webhooks/webhook-events
|
|
2075
|
+
*/
|
|
2076
|
+
|
|
2077
|
+
/**
|
|
2078
|
+
* Union type of all possible webhook events
|
|
2079
|
+
*/
|
|
2080
|
+
type MessengerWebhookEvent = MessageEditWebhookEvent | MessageReactionWebhookEvent | MessageWebhookEvent | MessageReadsWebhookEvent | MessagingFeedbackWebhookEvent | MessagingPostbackWebhookEvent;
|
|
2081
|
+
/**
|
|
2082
|
+
* Union type of all possible webhook payloads
|
|
2083
|
+
*/
|
|
2084
|
+
type MessengerWebhookPayload = MessageEditWebhookPayload | MessageReactionWebhookPayload | MessageWebhookPayload | MessageReadsWebhookPayload | MessagingFeedbackWebhookPayload | MessagingPostbackWebhookPayload;
|
|
2085
|
+
/**
|
|
2086
|
+
* Generic webhook entry structure
|
|
2087
|
+
*/
|
|
2088
|
+
interface WebhookEntry {
|
|
2089
|
+
/** Unique ID of the page */
|
|
2090
|
+
id: string;
|
|
2091
|
+
/** Time of update (epoch time in milliseconds) */
|
|
2092
|
+
time: number;
|
|
2093
|
+
/** Array of messaging events */
|
|
2094
|
+
messaging: MessengerWebhookEvent[];
|
|
2095
|
+
}
|
|
2096
|
+
/**
|
|
2097
|
+
* Generic webhook payload structure
|
|
2098
|
+
*/
|
|
2099
|
+
interface GenericWebhookPayload {
|
|
2100
|
+
/** Always 'page' for Messenger webhooks */
|
|
2101
|
+
object: 'page';
|
|
2102
|
+
/** Array of entry objects */
|
|
2103
|
+
entry: WebhookEntry[];
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Webhook event types enum
|
|
2107
|
+
*/
|
|
2108
|
+
declare enum WebhookEventType {
|
|
2109
|
+
MESSAGE = "message",
|
|
2110
|
+
MESSAGE_EDIT = "message_edit",
|
|
2111
|
+
MESSAGE_REACTION = "reaction",
|
|
2112
|
+
MESSAGE_READ = "read",
|
|
2113
|
+
MESSAGING_FEEDBACK = "messaging_feedback",
|
|
2114
|
+
MESSAGING_POSTBACK = "postback"
|
|
2115
|
+
}
|
|
2116
|
+
/**
|
|
2117
|
+
* Type guard to check webhook event type
|
|
2118
|
+
*/
|
|
2119
|
+
declare function getWebhookEventType(event: MessengerWebhookEvent): WebhookEventType | null;
|
|
2120
|
+
/**
|
|
2121
|
+
* Extract all events from a webhook payload
|
|
2122
|
+
*/
|
|
2123
|
+
declare function extractWebhookEvents(payload: GenericWebhookPayload): MessengerWebhookEvent[];
|
|
2124
|
+
/**
|
|
2125
|
+
* Process webhook events by type
|
|
2126
|
+
*/
|
|
2127
|
+
interface WebhookEventHandlers {
|
|
2128
|
+
onMessage?: (event: MessageWebhookEvent) => void | Promise<void>;
|
|
2129
|
+
onMessageEdit?: (event: MessageEditWebhookEvent) => void | Promise<void>;
|
|
2130
|
+
onMessageReaction?: (event: MessageReactionWebhookEvent) => void | Promise<void>;
|
|
2131
|
+
onMessageRead?: (event: MessageReadsWebhookEvent) => void | Promise<void>;
|
|
2132
|
+
onMessagingFeedback?: (event: MessagingFeedbackWebhookEvent) => void | Promise<void>;
|
|
2133
|
+
onMessagingPostback?: (event: MessagingPostbackWebhookEvent) => void | Promise<void>;
|
|
2134
|
+
onUnknown?: (event: any) => void | Promise<void>;
|
|
2135
|
+
}
|
|
2136
|
+
/**
|
|
2137
|
+
* Process webhook events with type-safe handlers
|
|
2138
|
+
*/
|
|
2139
|
+
declare function processWebhookEvents(payload: GenericWebhookPayload, handlers: WebhookEventHandlers): Promise<void>;
|
|
2140
|
+
/**
|
|
2141
|
+
* Webhook verification parameters
|
|
2142
|
+
*/
|
|
2143
|
+
interface WebhookVerificationParams {
|
|
2144
|
+
'hub.mode': string;
|
|
2145
|
+
'hub.verify_token': string;
|
|
2146
|
+
'hub.challenge': string;
|
|
2147
|
+
}
|
|
2148
|
+
/**
|
|
2149
|
+
* Verify webhook subscription
|
|
2150
|
+
*/
|
|
2151
|
+
declare function verifyWebhookSubscription(params: WebhookVerificationParams, verifyToken: string): string | null;
|
|
2152
|
+
|
|
338
2153
|
declare class MessengerAPIError extends Error {
|
|
339
2154
|
readonly code: number;
|
|
340
2155
|
readonly type: string;
|
|
@@ -385,4 +2200,4 @@ declare const TEMPLATE_LIMITS: {
|
|
|
385
2200
|
readonly MEDIA_BUTTONS_MAX_COUNT: 3;
|
|
386
2201
|
};
|
|
387
2202
|
|
|
388
|
-
export { ATTACHMENT_LIMITS, type AttachmentType, type AttachmentUploadRequest, type AttachmentUploadResponse, AttachmentsAPI, type Button, type ButtonTemplatePayload, type DefaultAction, type ErrorResponse, type GenericTemplateElement, type GenericTemplatePayload, type GetProfileRequest, MESSAGE_LIMITS, type MediaTemplateElement, type MediaTemplatePayload, type Message, MessageValidationError, type MessagingType, Messenger, MessengerAPIError, type MessengerConfig, MessengerConfigError, type MessengerError, MessengerNetworkError, MessengerTimeoutError, type ModerateConversationsRequest, type ModerateConversationsResponse, ModerationAPI, type ModerationAction, type ProductTemplateElement, type ProductTemplatePayload, ProfileAPI, type ProfileField, type QuickReply, type Recipient, SendAPI, type SendMessageRequest, type SendMessageResponse, type SenderAction, TEMPLATE_LIMITS, TemplateValidationError, TemplatesAPI, type UserId, type UserProfile };
|
|
2203
|
+
export { ATTACHMENT_LIMITS, ATTACHMENT_MIME_TYPES, type AttachmentPayload, type AttachmentType$1 as AttachmentType, type AttachmentUploadRequest, type AttachmentUploadResponse, AttachmentsAPI, type Button, type ButtonTemplatePayload, CESDisplayOption, COMMON_POSTBACK_PAYLOADS, CSATDisplayOption, type DefaultAction, type ErrorResponse, type FallbackAttachmentPayload, type FeedbackFollowUp, type FeedbackQuestion, type FeedbackScreen, FeedbackType, FollowUpType, type GenericTemplateElement, type GenericTemplatePayload, type GenericWebhookPayload, type GetProfileRequest, MESSAGE_CONSTANTS, MESSAGE_EDIT_CONSTANTS, MESSAGE_LIMITS, MESSAGE_READS_CONSTANTS, MESSAGING_FEEDBACK_CONSTANTS, type MediaAttachmentPayload, type MediaTemplateElement, type MediaTemplatePayload, type Message$1 as Message, type MessageAttachment, type MessageCommand, type MessageEdit, type MessageEditProcessingContext, type MessageEditRecipient, type MessageEditSender, type MessageEditWebhookEvent, type MessageEditWebhookPayload, type MessageProcessingContext, MessageReactionAction, type MessageReactionData, type MessageReactionProcessingContext, type MessageReactionRecipient, type MessageReactionSender, type MessageReactionStats, MessageReactionType, type MessageReactionWebhookConfig, type MessageReactionWebhookEvent, type MessageReactionWebhookPayload, type MessageReadData, type MessageReadsProcessingContext, type MessageReadsWebhookEvent, type MessageReadsWebhookPayload, type MessageRecipient, type MessageReferral, ReferralSource as MessageReferralSource, ReferralType as MessageReferralType, type MessageSender, MessageValidationError, type MessageWebhookEvent, type MessageWebhookPayload, type MessagingFeedbackData, type MessagingFeedbackProcessingContext, type MessagingFeedbackWebhookEvent, type MessagingFeedbackWebhookPayload, type MessagingPostbackWebhookEvent, type MessagingPostbackWebhookPayload, type MessagingType, Messenger, MessengerAPIError, type MessengerConfig, MessengerConfigError, type MessengerError, MessengerNetworkError, MessengerTimeoutError, type MessengerWebhookEvent, type MessengerWebhookPayload, type ModerateConversationsRequest, type ModerateConversationsResponse, ModerationAPI, type ModerationAction, NPSDisplayOption, POSTBACK_CONSTANTS, type PostbackData, type PostbackEventData, type PostbackPayload, type PostbackProcessingContext, type PostbackRecipient, type PostbackReferral, type PostbackSender, type ProductTemplateElement, type ProductTemplatePayload, ProfileAPI, type ProfileField, type QuickReply$1 as QuickReply, type Recipient, type ReelAttachmentPayload, type ReferralSource$1 as ReferralSource, type ReferralType$1 as ReferralType, type ReplyTo, SendAPI, type SendMessageRequest, type SendMessageResponse, type SenderAction, type StickerAttachmentPayload, TEMPLATE_LIMITS, TemplateValidationError, TemplatesAPI, type UserId, type UserProfile, type WatermarkTimestamp, AttachmentType as WebhookAttachmentType, type WebhookEntry, type WebhookEventHandlers, WebhookEventType, type Message as WebhookMessage, type QuickReply as WebhookQuickReply, type WebhookVerificationParams, extractMessageContext, extractMessageEditContext, extractMessageReadsContext, extractMessagingFeedbackContext, extractPostbackContext, extractTextFeedback, extractWebhookEvents, getAttachmentUrls, getAttachmentsByType, getFeedbackScoresByType, getReadMessageCount, getReadMessages, getWebhookEventType, hasAttachments, hasQuickReply, hasReferral, hasReferralData, isAttachmentType, isIdentifiedSender, isMessageEditEvent, isMessageEvent, isMessageRead, isMessageReadsEvent, isMessagingFeedbackEvent, isMessagingPostbackEvent, isReplyMessage, isTextMessage, isValidFeedbackScore, isValidQuestionId, isValidTextFeedback, processWebhookEvents, verifyWebhookSubscription };
|