@warriorteam/messenger-sdk 1.4.1 → 1.4.2
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 +59 -1
- package/dist/index.d.ts +59 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1979,6 +1979,26 @@ type MessengerWebhookPayload = MessageEditWebhookPayload | MessageReactionWebhoo
|
|
|
1979
1979
|
* ```
|
|
1980
1980
|
*/
|
|
1981
1981
|
declare function getWebhookEventType(event: MessengerWebhookEvent | any): WebhookEventType | null;
|
|
1982
|
+
/**
|
|
1983
|
+
* Extract event types from a complete webhook payload.
|
|
1984
|
+
* This is the correct function to use when processing the full webhook payload.
|
|
1985
|
+
*
|
|
1986
|
+
* @param payload - The complete webhook payload from Facebook
|
|
1987
|
+
* @returns Array of unique event types found in the payload
|
|
1988
|
+
*
|
|
1989
|
+
* @example
|
|
1990
|
+
* ```typescript
|
|
1991
|
+
* app.post('/webhook', (req, res) => {
|
|
1992
|
+
* const payload = req.body;
|
|
1993
|
+
* const eventTypes = getWebhookPayloadEventTypes(payload);
|
|
1994
|
+
*
|
|
1995
|
+
* if (eventTypes.includes(WebhookEventType.MESSAGE)) {
|
|
1996
|
+
* // Process message events
|
|
1997
|
+
* }
|
|
1998
|
+
* });
|
|
1999
|
+
* ```
|
|
2000
|
+
*/
|
|
2001
|
+
declare function getWebhookPayloadEventTypes(payload: WebhookPayload): WebhookEventType[];
|
|
1982
2002
|
/**
|
|
1983
2003
|
* Extract all events from a webhook payload.
|
|
1984
2004
|
* This properly extracts individual events from the nested structure.
|
|
@@ -2035,6 +2055,13 @@ interface WebhookVerificationParams {
|
|
|
2035
2055
|
'hub.verify_token': string;
|
|
2036
2056
|
'hub.challenge': string;
|
|
2037
2057
|
}
|
|
2058
|
+
/**
|
|
2059
|
+
* Webhook signature verification result
|
|
2060
|
+
*/
|
|
2061
|
+
interface WebhookSignatureVerificationResult {
|
|
2062
|
+
isValid: boolean;
|
|
2063
|
+
error?: string;
|
|
2064
|
+
}
|
|
2038
2065
|
/**
|
|
2039
2066
|
* Verify webhook subscription during initial setup
|
|
2040
2067
|
*
|
|
@@ -2055,6 +2082,37 @@ interface WebhookVerificationParams {
|
|
|
2055
2082
|
* ```
|
|
2056
2083
|
*/
|
|
2057
2084
|
declare function verifyWebhookSubscription(params: WebhookVerificationParams, verifyToken: string): string | null;
|
|
2085
|
+
/**
|
|
2086
|
+
* Verify webhook signature from Facebook
|
|
2087
|
+
*
|
|
2088
|
+
* **Note**: This function requires Node.js crypto module and is only supported in server-side environments.
|
|
2089
|
+
* For browser environments, you should handle signature verification on your backend.
|
|
2090
|
+
*
|
|
2091
|
+
* @param rawBody - The raw request body as Buffer
|
|
2092
|
+
* @param signature - The X-Hub-Signature-256 header value from Facebook
|
|
2093
|
+
* @param appSecret - Your Facebook app secret
|
|
2094
|
+
* @returns Promise that resolves to verification result with validity and optional error message
|
|
2095
|
+
*
|
|
2096
|
+
* @example
|
|
2097
|
+
* ```typescript
|
|
2098
|
+
* import express from 'express';
|
|
2099
|
+
* import { verifyWebhookSignature } from '@warriorteam/messenger-sdk';
|
|
2100
|
+
*
|
|
2101
|
+
* app.post('/webhook', express.raw({type: 'application/json'}), async (req, res) => {
|
|
2102
|
+
* const signature = req.get('X-Hub-Signature-256');
|
|
2103
|
+
* const result = await verifyWebhookSignature(req.body, signature, process.env.APP_SECRET);
|
|
2104
|
+
*
|
|
2105
|
+
* if (!result.isValid) {
|
|
2106
|
+
* return res.status(401).json({error: result.error});
|
|
2107
|
+
* }
|
|
2108
|
+
*
|
|
2109
|
+
* // Process webhook...
|
|
2110
|
+
* const payload = JSON.parse(req.body.toString());
|
|
2111
|
+
* // Handle webhook events...
|
|
2112
|
+
* });
|
|
2113
|
+
* ```
|
|
2114
|
+
*/
|
|
2115
|
+
declare function verifyWebhookSignature(rawBody: Buffer, signature: string | undefined, appSecret: string): Promise<WebhookSignatureVerificationResult>;
|
|
2058
2116
|
|
|
2059
2117
|
declare class MessengerAPIError extends Error {
|
|
2060
2118
|
readonly code: number;
|
|
@@ -2106,4 +2164,4 @@ declare const TEMPLATE_LIMITS: {
|
|
|
2106
2164
|
readonly MEDIA_BUTTONS_MAX_COUNT: 3;
|
|
2107
2165
|
};
|
|
2108
2166
|
|
|
2109
|
-
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 WebhookPayload as 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 WebhookRecipient as MessageEditRecipient, type WebhookSender as MessageEditSender, type MessageEditWebhookEvent, type MessageEditWebhookPayload, type MessageProcessingContext, MessageReactionAction, type MessageReactionData, type MessageReactionProcessingContext, type WebhookRecipient as MessageReactionRecipient, type WebhookSender as MessageReactionSender, type MessageReactionStats, MessageReactionType, type MessageReactionWebhookConfig, type MessageReactionWebhookEvent, type MessageReactionWebhookPayload, type MessageReadData, type MessageReadsProcessingContext, type MessageReadsWebhookEvent, type MessageReadsWebhookPayload, type WebhookRecipient as MessageRecipient, type MessageReferral, ReferralSource as MessageReferralSource, ReferralType as MessageReferralType, type WebhookSender as 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 WebhookRecipient as PostbackRecipient, type PostbackReferral, type WebhookSender as 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 };
|
|
2167
|
+
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 WebhookPayload as 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 WebhookRecipient as MessageEditRecipient, type WebhookSender as MessageEditSender, type MessageEditWebhookEvent, type MessageEditWebhookPayload, type MessageProcessingContext, MessageReactionAction, type MessageReactionData, type MessageReactionProcessingContext, type WebhookRecipient as MessageReactionRecipient, type WebhookSender as MessageReactionSender, type MessageReactionStats, MessageReactionType, type MessageReactionWebhookConfig, type MessageReactionWebhookEvent, type MessageReactionWebhookPayload, type MessageReadData, type MessageReadsProcessingContext, type MessageReadsWebhookEvent, type MessageReadsWebhookPayload, type WebhookRecipient as MessageRecipient, type MessageReferral, ReferralSource as MessageReferralSource, ReferralType as MessageReferralType, type WebhookSender as 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 WebhookRecipient as PostbackRecipient, type PostbackReferral, type WebhookSender as 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 WebhookSignatureVerificationResult, type WebhookVerificationParams, extractMessageContext, extractMessageEditContext, extractMessageReadsContext, extractMessagingFeedbackContext, extractPostbackContext, extractTextFeedback, extractWebhookEvents, getAttachmentUrls, getAttachmentsByType, getFeedbackScoresByType, getReadMessageCount, getReadMessages, getWebhookEventType, getWebhookPayloadEventTypes, hasAttachments, hasQuickReply, hasReferral, hasReferralData, isAttachmentType, isIdentifiedSender, isMessageEditEvent, isMessageEvent, isMessageRead, isMessageReadsEvent, isMessagingFeedbackEvent, isMessagingPostbackEvent, isReplyMessage, isTextMessage, isValidFeedbackScore, isValidQuestionId, isValidTextFeedback, processWebhookEvents, verifyWebhookSignature, verifyWebhookSubscription };
|
package/dist/index.d.ts
CHANGED
|
@@ -1979,6 +1979,26 @@ type MessengerWebhookPayload = MessageEditWebhookPayload | MessageReactionWebhoo
|
|
|
1979
1979
|
* ```
|
|
1980
1980
|
*/
|
|
1981
1981
|
declare function getWebhookEventType(event: MessengerWebhookEvent | any): WebhookEventType | null;
|
|
1982
|
+
/**
|
|
1983
|
+
* Extract event types from a complete webhook payload.
|
|
1984
|
+
* This is the correct function to use when processing the full webhook payload.
|
|
1985
|
+
*
|
|
1986
|
+
* @param payload - The complete webhook payload from Facebook
|
|
1987
|
+
* @returns Array of unique event types found in the payload
|
|
1988
|
+
*
|
|
1989
|
+
* @example
|
|
1990
|
+
* ```typescript
|
|
1991
|
+
* app.post('/webhook', (req, res) => {
|
|
1992
|
+
* const payload = req.body;
|
|
1993
|
+
* const eventTypes = getWebhookPayloadEventTypes(payload);
|
|
1994
|
+
*
|
|
1995
|
+
* if (eventTypes.includes(WebhookEventType.MESSAGE)) {
|
|
1996
|
+
* // Process message events
|
|
1997
|
+
* }
|
|
1998
|
+
* });
|
|
1999
|
+
* ```
|
|
2000
|
+
*/
|
|
2001
|
+
declare function getWebhookPayloadEventTypes(payload: WebhookPayload): WebhookEventType[];
|
|
1982
2002
|
/**
|
|
1983
2003
|
* Extract all events from a webhook payload.
|
|
1984
2004
|
* This properly extracts individual events from the nested structure.
|
|
@@ -2035,6 +2055,13 @@ interface WebhookVerificationParams {
|
|
|
2035
2055
|
'hub.verify_token': string;
|
|
2036
2056
|
'hub.challenge': string;
|
|
2037
2057
|
}
|
|
2058
|
+
/**
|
|
2059
|
+
* Webhook signature verification result
|
|
2060
|
+
*/
|
|
2061
|
+
interface WebhookSignatureVerificationResult {
|
|
2062
|
+
isValid: boolean;
|
|
2063
|
+
error?: string;
|
|
2064
|
+
}
|
|
2038
2065
|
/**
|
|
2039
2066
|
* Verify webhook subscription during initial setup
|
|
2040
2067
|
*
|
|
@@ -2055,6 +2082,37 @@ interface WebhookVerificationParams {
|
|
|
2055
2082
|
* ```
|
|
2056
2083
|
*/
|
|
2057
2084
|
declare function verifyWebhookSubscription(params: WebhookVerificationParams, verifyToken: string): string | null;
|
|
2085
|
+
/**
|
|
2086
|
+
* Verify webhook signature from Facebook
|
|
2087
|
+
*
|
|
2088
|
+
* **Note**: This function requires Node.js crypto module and is only supported in server-side environments.
|
|
2089
|
+
* For browser environments, you should handle signature verification on your backend.
|
|
2090
|
+
*
|
|
2091
|
+
* @param rawBody - The raw request body as Buffer
|
|
2092
|
+
* @param signature - The X-Hub-Signature-256 header value from Facebook
|
|
2093
|
+
* @param appSecret - Your Facebook app secret
|
|
2094
|
+
* @returns Promise that resolves to verification result with validity and optional error message
|
|
2095
|
+
*
|
|
2096
|
+
* @example
|
|
2097
|
+
* ```typescript
|
|
2098
|
+
* import express from 'express';
|
|
2099
|
+
* import { verifyWebhookSignature } from '@warriorteam/messenger-sdk';
|
|
2100
|
+
*
|
|
2101
|
+
* app.post('/webhook', express.raw({type: 'application/json'}), async (req, res) => {
|
|
2102
|
+
* const signature = req.get('X-Hub-Signature-256');
|
|
2103
|
+
* const result = await verifyWebhookSignature(req.body, signature, process.env.APP_SECRET);
|
|
2104
|
+
*
|
|
2105
|
+
* if (!result.isValid) {
|
|
2106
|
+
* return res.status(401).json({error: result.error});
|
|
2107
|
+
* }
|
|
2108
|
+
*
|
|
2109
|
+
* // Process webhook...
|
|
2110
|
+
* const payload = JSON.parse(req.body.toString());
|
|
2111
|
+
* // Handle webhook events...
|
|
2112
|
+
* });
|
|
2113
|
+
* ```
|
|
2114
|
+
*/
|
|
2115
|
+
declare function verifyWebhookSignature(rawBody: Buffer, signature: string | undefined, appSecret: string): Promise<WebhookSignatureVerificationResult>;
|
|
2058
2116
|
|
|
2059
2117
|
declare class MessengerAPIError extends Error {
|
|
2060
2118
|
readonly code: number;
|
|
@@ -2106,4 +2164,4 @@ declare const TEMPLATE_LIMITS: {
|
|
|
2106
2164
|
readonly MEDIA_BUTTONS_MAX_COUNT: 3;
|
|
2107
2165
|
};
|
|
2108
2166
|
|
|
2109
|
-
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 WebhookPayload as 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 WebhookRecipient as MessageEditRecipient, type WebhookSender as MessageEditSender, type MessageEditWebhookEvent, type MessageEditWebhookPayload, type MessageProcessingContext, MessageReactionAction, type MessageReactionData, type MessageReactionProcessingContext, type WebhookRecipient as MessageReactionRecipient, type WebhookSender as MessageReactionSender, type MessageReactionStats, MessageReactionType, type MessageReactionWebhookConfig, type MessageReactionWebhookEvent, type MessageReactionWebhookPayload, type MessageReadData, type MessageReadsProcessingContext, type MessageReadsWebhookEvent, type MessageReadsWebhookPayload, type WebhookRecipient as MessageRecipient, type MessageReferral, ReferralSource as MessageReferralSource, ReferralType as MessageReferralType, type WebhookSender as 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 WebhookRecipient as PostbackRecipient, type PostbackReferral, type WebhookSender as 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 };
|
|
2167
|
+
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 WebhookPayload as 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 WebhookRecipient as MessageEditRecipient, type WebhookSender as MessageEditSender, type MessageEditWebhookEvent, type MessageEditWebhookPayload, type MessageProcessingContext, MessageReactionAction, type MessageReactionData, type MessageReactionProcessingContext, type WebhookRecipient as MessageReactionRecipient, type WebhookSender as MessageReactionSender, type MessageReactionStats, MessageReactionType, type MessageReactionWebhookConfig, type MessageReactionWebhookEvent, type MessageReactionWebhookPayload, type MessageReadData, type MessageReadsProcessingContext, type MessageReadsWebhookEvent, type MessageReadsWebhookPayload, type WebhookRecipient as MessageRecipient, type MessageReferral, ReferralSource as MessageReferralSource, ReferralType as MessageReferralType, type WebhookSender as 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 WebhookRecipient as PostbackRecipient, type PostbackReferral, type WebhookSender as 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 WebhookSignatureVerificationResult, type WebhookVerificationParams, extractMessageContext, extractMessageEditContext, extractMessageReadsContext, extractMessagingFeedbackContext, extractPostbackContext, extractTextFeedback, extractWebhookEvents, getAttachmentUrls, getAttachmentsByType, getFeedbackScoresByType, getReadMessageCount, getReadMessages, getWebhookEventType, getWebhookPayloadEventTypes, hasAttachments, hasQuickReply, hasReferral, hasReferralData, isAttachmentType, isIdentifiedSender, isMessageEditEvent, isMessageEvent, isMessageRead, isMessageReadsEvent, isMessagingFeedbackEvent, isMessagingPostbackEvent, isReplyMessage, isTextMessage, isValidFeedbackScore, isValidQuestionId, isValidTextFeedback, processWebhookEvents, verifyWebhookSignature, verifyWebhookSubscription };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var q="v23.0",X="https://graph.facebook.com";var c={MESSAGES:"/me/messages",MESSAGE_ATTACHMENTS:"/me/message_attachments",MODERATE_CONVERSATIONS:"/me/moderate_conversations"},_={TEXT_MESSAGE_MAX_CHARS:2e3},re={IMAGE_MAX_SIZE:8*1024*1024,OTHER_MAX_SIZE:25*1024*1024,VIDEO_TIMEOUT:75,OTHER_TIMEOUT:10},i={GENERIC_ELEMENTS_MAX:10,GENERIC_TITLE_MAX_CHARS:80,GENERIC_SUBTITLE_MAX_CHARS:80,BUTTON_TEXT_MAX_CHARS:640,BUTTONS_MAX_COUNT:3,BUTTON_TITLE_MAX_CHARS:20,POSTBACK_PAYLOAD_MAX_CHARS:1e3,MEDIA_ELEMENTS_COUNT:1,MEDIA_BUTTONS_MAX_COUNT:3};var l=class extends Error{code;type;subcode;fbtrace_id;statusCode;response;constructor(e,s,o){super(e.message),this.name="MessengerAPIError",this.code=e.code,this.type=e.type,this.subcode=e.error_subcode,this.fbtrace_id=e.fbtrace_id,this.statusCode=s,this.response=o;}},b=class extends Error{cause;constructor(e,s){super(e),this.name="MessengerNetworkError",this.cause=s;}},h=class extends Error{timeout;constructor(e){super(`Request timed out after ${e}ms`),this.name="MessengerTimeoutError",this.timeout=e;}},m=class extends Error{constructor(e){super(e),this.name="MessengerConfigError";}};var P=class{config;constructor(e){this.config={accessToken:e.accessToken,version:e.version,baseUrl:e.baseUrl||X,timeout:e.timeout||3e4,maxRetries:e.maxRetries||3};}async request(e){let s=this.buildUrl(e.path,e.query,e.accessToken),o;for(let a=0;a<=this.config.maxRetries;a++)try{let n=await this.makeRequest(s,e);return await this.handleResponse(n)}catch(n){if(o=n,n instanceof l&&n.statusCode>=400&&n.statusCode<500||a===this.config.maxRetries)throw n;await this.delay(1e3*(a+1));}throw o||new Error("Unknown error occurred")}buildUrl(e,s,o){let a=new URL(`${this.config.baseUrl}/${this.config.version}${e}`),n=o||this.config.accessToken;if(!n)throw new Error("Access token is required. Provide it in constructor or method options.");return a.searchParams.append("access_token",n),s&&Object.entries(s).forEach(([p,g])=>{a.searchParams.append(p,String(g));}),a.toString()}async makeRequest(e,s){let o=new AbortController,a=setTimeout(()=>o.abort(),this.config.timeout);try{let n={method:s.method,headers:{"Content-Type":"application/json"},signal:o.signal};return s.body&&(n.body=JSON.stringify(s.body)),await fetch(e,n)}catch(n){throw n instanceof Error?n.name==="AbortError"?new h(this.config.timeout):new b(`Network request failed: ${n.message}`,n):n}finally{clearTimeout(a);}}async handleResponse(e){let o=e.headers.get("content-type")?.includes("application/json");if(!e.ok)if(o){let a=await e.json();throw new l(a.error,e.status,a)}else {let a=await e.text();throw new l({message:a||`HTTP ${e.status} ${e.statusText}`,type:"http_error",code:e.status,fbtrace_id:""},e.status,a)}return o?await e.json():await e.text()}delay(e){return new Promise(s=>setTimeout(s,e))}};var u=class extends Error{constructor(e){super(e),this.name="MessageValidationError";}};function j(t){if(!t||t.trim()==="")throw new u("Text message cannot be empty");if(t.length>_.TEXT_MESSAGE_MAX_CHARS)throw new u(`Text message cannot exceed ${_.TEXT_MESSAGE_MAX_CHARS} characters`)}var f=class{constructor(e){this.httpClient=e;}async message(e,s){return e.message?.text&&j(e.message.text),this.httpClient.request({method:"POST",path:c.MESSAGES,body:e,accessToken:s?.accessToken})}async action(e,s,o){return this.httpClient.request({method:"POST",path:c.MESSAGES,body:{recipient:{id:e},messaging_type:"RESPONSE",sender_action:s},accessToken:o?.accessToken})}async typingOn(e,s){return this.action(e,"typing_on",s)}async typingOff(e,s){return this.action(e,"typing_off",s)}async markSeen(e,s){return this.action(e,"mark_seen",s)}async attachment(e,s){return this.message({recipient:e.recipient,messaging_type:e.messaging_type??"RESPONSE",message:{attachment:{type:e.type,payload:{attachment_id:e.attachment_id}}}},s)}async attachmentFromUrl(e,s){return this.message({recipient:e.recipient,messaging_type:e.messaging_type??"RESPONSE",message:{attachment:{type:e.type,payload:{url:e.url}}}},s)}};var y=class{constructor(e){this.httpClient=e;}async upload(e,s){let o={message:{attachment:{type:e.type,payload:{url:e.url,is_reusable:e.is_reusable??true}}}};return this.httpClient.request({method:"POST",path:c.MESSAGE_ATTACHMENTS,body:o,accessToken:s?.accessToken})}};var T=class{constructor(e){this.httpClient=e;}async moderate(e,s){return this.httpClient.request({method:"POST",path:c.MODERATE_CONVERSATIONS,body:e,accessToken:s?.accessToken})}async blockUser(e,s){let o=Array.isArray(e)?e.map(a=>({id:a})):[{id:e}];return this.moderate({user_ids:o,actions:["block_user"]},s)}async unblockUser(e,s){let o=Array.isArray(e)?e.map(a=>({id:a})):[{id:e}];return this.moderate({user_ids:o,actions:["unblock_user"]},s)}async banUser(e,s){let o=Array.isArray(e)?e.map(a=>({id:a})):[{id:e}];return this.moderate({user_ids:o,actions:["ban_user"]},s)}async unbanUser(e,s){let o=Array.isArray(e)?e.map(a=>({id:a})):[{id:e}];return this.moderate({user_ids:o,actions:["unban_user"]},s)}async moveToSpam(e,s){let o=Array.isArray(e)?e.map(a=>({id:a})):[{id:e}];return this.moderate({user_ids:o,actions:["move_to_spam"]},s)}async blockAndSpam(e,s){let o=Array.isArray(e)?e.map(a=>({id:a})):[{id:e}];return this.moderate({user_ids:o,actions:["block_user","move_to_spam"]},s)}};var r=class extends Error{constructor(e){super(e),this.name="TemplateValidationError";}};function V(t){if(t.length===0)throw new r("Generic template must have at least 1 element");if(t.length>i.GENERIC_ELEMENTS_MAX)throw new r(`Generic template cannot have more than ${i.GENERIC_ELEMENTS_MAX} elements`);t.forEach((e,s)=>{ge(e,s);});}function ge(t,e){if(!t.title||t.title.trim()==="")throw new r(`Element ${e}: title is required`);if(t.title.length>i.GENERIC_TITLE_MAX_CHARS)throw new r(`Element ${e}: title cannot exceed ${i.GENERIC_TITLE_MAX_CHARS} characters`);if(t.subtitle&&t.subtitle.length>i.GENERIC_SUBTITLE_MAX_CHARS)throw new r(`Element ${e}: subtitle cannot exceed ${i.GENERIC_SUBTITLE_MAX_CHARS} characters`);if(t.image_url&&!M(t.image_url))throw new r(`Element ${e}: image_url must be HTTPS`);if(t.buttons&&C(t.buttons,`Element ${e}`),!!!(t.subtitle||t.image_url||t.default_action||t.buttons&&t.buttons.length>0))throw new r(`Element ${e}: must have at least one additional property beyond title`)}function $(t,e){if(!t||t.trim()==="")throw new r("Button template text is required");if(t.length>i.BUTTON_TEXT_MAX_CHARS)throw new r(`Button template text cannot exceed ${i.BUTTON_TEXT_MAX_CHARS} characters`);if(e.length===0)throw new r("Button template must have at least 1 button");C(e,"Button template");}function K(t){if(!t.media_type)throw new r("Media template element must have media_type");if(!t.url&&!t.attachment_id)throw new r("Media template element must have either url or attachment_id");if(t.url&&t.attachment_id)throw new r("Media template element cannot have both url and attachment_id");if(t.url&&!M(t.url))throw new r("Media template url must be HTTPS");if(t.buttons){if(t.buttons.length>i.MEDIA_BUTTONS_MAX_COUNT)throw new r(`Media template cannot have more than ${i.MEDIA_BUTTONS_MAX_COUNT} buttons`);C(t.buttons,"Media template");}}function C(t,e){if(t.length>i.BUTTONS_MAX_COUNT)throw new r(`${e} cannot have more than ${i.BUTTONS_MAX_COUNT} buttons`);t.forEach((s,o)=>{de(s,`${e} button ${o}`);});}function de(t,e){if(!t.type)throw new r(`${e}: type is required`);if(t.type!=="account_unlink"&&(!t.title||t.title.trim()===""))throw new r(`${e}: title is required for ${t.type} buttons`);if(t.title&&t.title.length>i.BUTTON_TITLE_MAX_CHARS)throw new r(`${e}: title cannot exceed ${i.BUTTON_TITLE_MAX_CHARS} characters`);switch(t.type){case "web_url":if(!t.url)throw new r(`${e}: url is required for web_url buttons`);if(!M(t.url))throw new r(`${e}: url must be HTTPS for web_url buttons`);break;case "postback":if(!t.payload)throw new r(`${e}: payload is required for postback buttons`);if(t.payload.length>i.POSTBACK_PAYLOAD_MAX_CHARS)throw new r(`${e}: payload cannot exceed ${i.POSTBACK_PAYLOAD_MAX_CHARS} characters`);break;case "phone_number":if(!t.payload)throw new r(`${e}: payload is required for phone_number buttons`);if(!t.payload.startsWith("+"))throw new r(`${e}: phone_number payload must start with + (e.g., +1234567890)`);break;case "game_play":break;case "account_link":if(!t.url)throw new r(`${e}: url is required for account_link buttons`);if(!M(t.url))throw new r(`${e}: url must be HTTPS for account_link buttons`);break;}if(t.type==="web_url"&&t.messenger_extensions&&t.fallback_url&&!M(t.fallback_url))throw new r(`${e}: fallback_url must be HTTPS`)}function M(t){try{return new URL(t).protocol==="https:"}catch{return false}}var k=class{constructor(e){this.httpClient=e;}async generic(e,s){V(e.elements);let o={template_type:"generic",elements:e.elements,image_aspect_ratio:e.image_aspect_ratio},a={recipient:e.recipient,messaging_type:e.messaging_type||"UPDATE",message:{attachment:{type:"template",payload:o}},notification_type:e.notification_type,tag:e.tag};return this.httpClient.request({method:"POST",path:c.MESSAGES,body:a,accessToken:s?.accessToken})}async button(e,s){$(e.text,e.buttons);let o={template_type:"button",text:e.text,buttons:e.buttons},a={recipient:e.recipient,messaging_type:e.messaging_type||"UPDATE",message:{attachment:{type:"template",payload:o}},notification_type:e.notification_type,tag:e.tag};return this.httpClient.request({method:"POST",path:c.MESSAGES,body:a,accessToken:s?.accessToken})}async media(e,s){K(e.element);let o={template_type:"media",elements:[e.element]},a={recipient:e.recipient,messaging_type:e.messaging_type||"UPDATE",message:{attachment:{type:"template",payload:o}},notification_type:e.notification_type,tag:e.tag};return this.httpClient.request({method:"POST",path:c.MESSAGES,body:a,accessToken:s?.accessToken})}async product(e,s){let o={template_type:"product",elements:e.elements},a={recipient:e.recipient,messaging_type:e.messaging_type||"UPDATE",message:{attachment:{type:"template",payload:o}},notification_type:e.notification_type,tag:e.tag};return this.httpClient.request({method:"POST",path:c.MESSAGES,body:a,accessToken:s?.accessToken})}};var S=class{constructor(e){this.httpClient=e;}async get(e,s){let{psid:o,fields:a=["first_name","last_name"]}=e,n=new URLSearchParams({fields:a.join(",")});return this.httpClient.request({method:"GET",path:`/${o}?${n.toString()}`,body:void 0,accessToken:s?.accessToken})}async getBasic(e,s){return this.get({psid:e,fields:["first_name","last_name","profile_pic"]},s)}async getFull(e,s){return this.get({psid:e,fields:["id","name","first_name","last_name","profile_pic","locale","timezone","gender"]},s)}async getName(e,s){return this.get({psid:e,fields:["first_name","last_name"]},s)}async getProfilePicture(e,s){return this.get({psid:e,fields:["profile_pic"]},s)}};var v=class{send;attachments;moderation;templates;profile;httpClient;constructor(e={}){this.validateConfig(e);let s={accessToken:e.accessToken,version:e.version||q,baseUrl:e.baseUrl,timeout:e.timeout,maxRetries:e.maxRetries};this.httpClient=new P(s),this.send=new f(this.httpClient),this.attachments=new y(this.httpClient),this.moderation=new T(this.httpClient),this.templates=new k(this.httpClient),this.profile=new S(this.httpClient);}validateConfig(e){if(e.accessToken!==void 0&&(typeof e.accessToken!="string"||e.accessToken.trim()===""))throw new m("Access token must be a non-empty string");if(e.version&&typeof e.version!="string")throw new m("API version must be a string");if(e.timeout&&(typeof e.timeout!="number"||e.timeout<=0))throw new m("Timeout must be a positive number");if(e.maxRetries&&(typeof e.maxRetries!="number"||e.maxRetries<0))throw new m("Max retries must be a non-negative number")}};var A=(p=>(p.MESSAGE="message",p.MESSAGE_EDIT="message_edit",p.MESSAGE_REACTION="reaction",p.MESSAGE_READ="read",p.MESSAGING_FEEDBACK="messaging_feedback",p.MESSAGING_POSTBACK="postback",p))(A||{});function me(t){return typeof t.id=="string"&&t.id.length>0}function Y(t){let e=[];if(t.object==="page"&&Array.isArray(t.entry))for(let s of t.entry)Array.isArray(s.messaging)&&e.push(...s.messaging);return e}function R(t){let e=me(t.sender);return {senderId:t.sender.id,userRef:t.sender.user_ref,recipientId:t.recipient.id,timestamp:t.timestamp,isIdentifiedUser:e,eventDate:new Date(t.timestamp)}}function le(t){return t&&typeof t=="object"&&"message_edit"in t}function Ee(t){return {...R(t),messageId:t.message_edit.mid,updatedText:t.message_edit.text,editCount:t.message_edit.num_edit}}var be={MAX_EDITS:5,EVENT_TYPE:"message_edit"};var W=(d=>(d.LIKE="like",d.DISLIKE="dislike",d.LOVE="love",d.SAD="sad",d.ANGRY="angry",d.WOW="wow",d.SMILE="smile",d.OTHER="other",d))(W||{}),I=(s=>(s.REACT="react",s.UNREACT="unreact",s))(I||{});function he(t){return t&&typeof t=="object"&&"read"in t}function ue(t){return {senderId:t.sender.id,recipientId:t.recipient.id,watermarkTimestamp:t.read.watermark,readTimestamp:t.timestamp,watermarkDate:new Date(t.read.watermark),readDate:new Date(t.timestamp)}}function Q(t,e){return t<=e}function z(t,e){return t.filter(s=>Q(s.timestamp,e))}function fe(t,e){return z(t,e).length}var ye={EVENT_TYPE:"message_reads",READ_PROPERTY:"read"};function Te(t){return t&&typeof t=="object"&&"postback"in t}function Z(t){return t.postback&&"referral"in t.postback&&t.postback.referral!=null}function J(t){return t&&typeof t.id=="string"&&t.id.length>0}function Me(t){let e=Z(t),s=J(t.sender);return {payload:t.postback.payload,senderId:t.sender.id,userRef:t.sender.user_ref,recipientId:t.recipient.id,buttonTitle:t.postback.title,messageId:t.postback.mid,timestamp:t.timestamp,referralContext:e?{ref:t.postback.referral.ref,source:t.postback.referral.source,type:t.postback.referral.type}:void 0,isReferred:e,isIdentifiedUser:s}}var ke={GET_STARTED:"GET_STARTED",MAIN_MENU:"MAIN_MENU",HELP:"HELP",SUPPORT:"SUPPORT",CONTACT:"CONTACT",CONTACT_SALES:"CONTACT_SALES",CONTACT_SUPPORT:"CONTACT_SUPPORT",BACK:"BACK",NEXT:"NEXT",CANCEL:"CANCEL",SETTINGS:"SETTINGS",PREFERENCES:"PREFERENCES"},Se={MAX_PAYLOAD_LENGTH:1e3,EVENT_TYPE:"postback",REFERRAL_SOURCES:{SHORTLINK:"SHORTLINK",ADS:"ADS",MESSENGER_CODE:"MESSENGER_CODE"},REFERRAL_TYPES:{OPEN_THREAD:"OPEN_THREAD"}};var O=(o=>(o.CSAT="csat",o.NPS="nps",o.CES="ces",o))(O||{}),N=(o=>(o.ONE_TO_FIVE="one_to_five",o.FIVE_STARS="five_stars",o.FIVE_EMOJIS="five_emojis",o))(N||{}),w=(e=>(e.ZERO_TO_TEN="zero_to_ten",e))(w||{}),G=(e=>(e.ONE_TO_SEVEN="one_to_seven",e))(G||{}),D=(e=>(e.FREE_FORM="free_form",e))(D||{});function Ae(t){return t&&typeof t=="object"&&"messaging_feedback"in t}function _e(t){let e=[];return t.messaging_feedback.feedback_screens.forEach(s=>{Object.entries(s.questions).forEach(([o,a])=>{e.push({questionId:o,feedbackType:a.type,score:parseInt(a.payload,10),textFeedback:a.follow_up?.payload,screenId:s.screen_id});});}),{senderId:t.sender.id,recipientId:t.recipient.id,submissionTimestamp:t.timestamp,screenCount:t.messaging_feedback.feedback_screens.length,allResponses:e}}function Pe(t){let e=new Map;return t.messaging_feedback.feedback_screens.forEach(s=>{Object.values(s.questions).forEach(o=>{let a=parseInt(o.payload,10),n=e.get(o.type)||[];e.set(o.type,[...n,a]);});}),e}function Re(t){let e=[];return t.messaging_feedback.feedback_screens.forEach(s=>{Object.values(s.questions).forEach(o=>{o.follow_up?.payload&&e.push(o.follow_up.payload);});}),e}var E={MAX_TEXT_FEEDBACK_LENGTH:400,SCORE_RANGES:{csat:{min:1,max:5},nps:{min:0,max:10},ces:{min:1,max:7}},TEMPLATE_EXPIRY:{MIN_DAYS:1,MAX_DAYS:7,DEFAULT_DAYS:1},QUESTION_ID:{MAX_LENGTH:80,VALID_PATTERN:/^[a-zA-Z0-9_]+$/},TEMPLATE_LIMITS:{MAX_TITLES:1,MAX_SCORING_COMPONENTS:1},EVENT_TYPE:"messaging_feedback"};function xe(t,e){let s=E.SCORE_RANGES[t];return Number.isInteger(e)&&e>=s.min&&e<=s.max}function Ce(t){return t.length<=E.QUESTION_ID.MAX_LENGTH&&E.QUESTION_ID.VALID_PATTERN.test(t)}function ve(t){return t.length<=E.MAX_TEXT_FEEDBACK_LENGTH}var U=(g=>(g.AUDIO="audio",g.FILE="file",g.IMAGE="image",g.VIDEO="video",g.FALLBACK="fallback",g.REEL="reel",g.IG_REEL="ig_reel",g))(U||{}),F=(o=>(o.OPEN_THREAD="OPEN_THREAD",o.PRODUCT="product",o.ADS="ads",o))(F||{}),B=(n=>(n.MESSENGER_CODE="MESSENGER_CODE",n.DISCOVER_TAB="DISCOVER_TAB",n.ADS="ADS",n.SHORTLINK="SHORTLINK",n.CUSTOMER_CHAT_PLUGIN="CUSTOMER_CHAT_PLUGIN",n))(B||{});function We(t){return t&&typeof t=="object"&&"message"in t}function Ie(t){return typeof t.text=="string"&&t.text.length>0}function x(t){return Array.isArray(t.attachments)&&t.attachments.length>0}function ee(t){return t.quick_reply!==void 0}function te(t){return t.reply_to!==void 0}function se(t){return t.referral!==void 0}function oe(t,e){return t.type===e}function Oe(t){let{message:e}=t;return {...R(t),messageId:e.mid,text:e.text,hasAttachments:x(e),isQuickReply:ee(e),isReply:te(e),hasReferral:se(e),quickReplyPayload:e.quick_reply?.payload,repliedToMessageId:e.reply_to?.mid}}function Ne(t,e){return x(t)?t.attachments.filter(s=>oe(s,e)):[]}function we(t){return x(t)?t.attachments.map(e=>e.payload.url):[]}var Ge={MAX_TEXT_LENGTH:2e3,MAX_QUICK_REPLY_PAYLOAD_LENGTH:1e3,MAX_REFERRAL_REF_LENGTH:250,EVENT_TYPE:"message"},De={image:["image/jpeg","image/png","image/gif","image/webp"],video:["video/mp4","video/avi","video/quicktime","video/webm"],audio:["audio/mpeg","audio/mp4","audio/wav","audio/ogg"],file:["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/plain"]};function L(t){return !t||typeof t!="object"?null:"type"in t&&Object.values(A).includes(t.type)?t.type:"message"in t?"message":"message_edit"in t?"message_edit":"reaction"in t?"reaction":"read"in t?"read":"messaging_feedback"in t?"messaging_feedback":"postback"in t?"postback":null}function H(t){return Y(t)}function Ue(t){let e=L(t);return e?"type"in t?t:{...t,type:e}:null}async function ae(t,e){let s=H(t);for(let o of s){let a=Ue(o);if(!a){e.onUnknown&&await e.onUnknown(o);continue}switch(a.type){case "message":e.onMessage&&await e.onMessage(a);break;case "message_edit":e.onMessageEdit&&await e.onMessageEdit(a);break;case "reaction":e.onMessageReaction&&await e.onMessageReaction(a);break;case "read":e.onMessageRead&&await e.onMessageRead(a);break;case "messaging_feedback":e.onMessagingFeedback&&await e.onMessagingFeedback(a);break;case "postback":e.onMessagingPostback&&await e.onMessagingPostback(a);break;default:let n=a;e.onUnknown&&await e.onUnknown(n);break}}}function ne(t,e){return t["hub.mode"]==="subscribe"&&t["hub.verify_token"]===e?t["hub.challenge"]:null}
|
|
2
|
-
export{
|
|
1
|
+
var q="v23.0",X="https://graph.facebook.com";var g={MESSAGES:"/me/messages",MESSAGE_ATTACHMENTS:"/me/message_attachments",MODERATE_CONVERSATIONS:"/me/moderate_conversations"},_={TEXT_MESSAGE_MAX_CHARS:2e3},ce={IMAGE_MAX_SIZE:8*1024*1024,OTHER_MAX_SIZE:25*1024*1024,VIDEO_TIMEOUT:75,OTHER_TIMEOUT:10},i={GENERIC_ELEMENTS_MAX:10,GENERIC_TITLE_MAX_CHARS:80,GENERIC_SUBTITLE_MAX_CHARS:80,BUTTON_TEXT_MAX_CHARS:640,BUTTONS_MAX_COUNT:3,BUTTON_TITLE_MAX_CHARS:20,POSTBACK_PAYLOAD_MAX_CHARS:1e3,MEDIA_ELEMENTS_COUNT:1,MEDIA_BUTTONS_MAX_COUNT:3};var l=class extends Error{code;type;subcode;fbtrace_id;statusCode;response;constructor(e,s,o){super(e.message),this.name="MessengerAPIError",this.code=e.code,this.type=e.type,this.subcode=e.error_subcode,this.fbtrace_id=e.fbtrace_id,this.statusCode=s,this.response=o;}},b=class extends Error{cause;constructor(e,s){super(e),this.name="MessengerNetworkError",this.cause=s;}},h=class extends Error{timeout;constructor(e){super(`Request timed out after ${e}ms`),this.name="MessengerTimeoutError",this.timeout=e;}},m=class extends Error{constructor(e){super(e),this.name="MessengerConfigError";}};var P=class{config;constructor(e){this.config={accessToken:e.accessToken,version:e.version,baseUrl:e.baseUrl||X,timeout:e.timeout||3e4,maxRetries:e.maxRetries||3};}async request(e){let s=this.buildUrl(e.path,e.query,e.accessToken),o;for(let a=0;a<=this.config.maxRetries;a++)try{let n=await this.makeRequest(s,e);return await this.handleResponse(n)}catch(n){if(o=n,n instanceof l&&n.statusCode>=400&&n.statusCode<500||a===this.config.maxRetries)throw n;await this.delay(1e3*(a+1));}throw o||new Error("Unknown error occurred")}buildUrl(e,s,o){let a=new URL(`${this.config.baseUrl}/${this.config.version}${e}`),n=o||this.config.accessToken;if(!n)throw new Error("Access token is required. Provide it in constructor or method options.");return a.searchParams.append("access_token",n),s&&Object.entries(s).forEach(([c,p])=>{a.searchParams.append(c,String(p));}),a.toString()}async makeRequest(e,s){let o=new AbortController,a=setTimeout(()=>o.abort(),this.config.timeout);try{let n={method:s.method,headers:{"Content-Type":"application/json"},signal:o.signal};return s.body&&(n.body=JSON.stringify(s.body)),await fetch(e,n)}catch(n){throw n instanceof Error?n.name==="AbortError"?new h(this.config.timeout):new b(`Network request failed: ${n.message}`,n):n}finally{clearTimeout(a);}}async handleResponse(e){let o=e.headers.get("content-type")?.includes("application/json");if(!e.ok)if(o){let a=await e.json();throw new l(a.error,e.status,a)}else {let a=await e.text();throw new l({message:a||`HTTP ${e.status} ${e.statusText}`,type:"http_error",code:e.status,fbtrace_id:""},e.status,a)}return o?await e.json():await e.text()}delay(e){return new Promise(s=>setTimeout(s,e))}};var u=class extends Error{constructor(e){super(e),this.name="MessageValidationError";}};function j(t){if(!t||t.trim()==="")throw new u("Text message cannot be empty");if(t.length>_.TEXT_MESSAGE_MAX_CHARS)throw new u(`Text message cannot exceed ${_.TEXT_MESSAGE_MAX_CHARS} characters`)}var f=class{constructor(e){this.httpClient=e;}async message(e,s){return e.message?.text&&j(e.message.text),this.httpClient.request({method:"POST",path:g.MESSAGES,body:e,accessToken:s?.accessToken})}async action(e,s,o){return this.httpClient.request({method:"POST",path:g.MESSAGES,body:{recipient:{id:e},messaging_type:"RESPONSE",sender_action:s},accessToken:o?.accessToken})}async typingOn(e,s){return this.action(e,"typing_on",s)}async typingOff(e,s){return this.action(e,"typing_off",s)}async markSeen(e,s){return this.action(e,"mark_seen",s)}async attachment(e,s){return this.message({recipient:e.recipient,messaging_type:e.messaging_type??"RESPONSE",message:{attachment:{type:e.type,payload:{attachment_id:e.attachment_id}}}},s)}async attachmentFromUrl(e,s){return this.message({recipient:e.recipient,messaging_type:e.messaging_type??"RESPONSE",message:{attachment:{type:e.type,payload:{url:e.url}}}},s)}};var y=class{constructor(e){this.httpClient=e;}async upload(e,s){let o={message:{attachment:{type:e.type,payload:{url:e.url,is_reusable:e.is_reusable??true}}}};return this.httpClient.request({method:"POST",path:g.MESSAGE_ATTACHMENTS,body:o,accessToken:s?.accessToken})}};var T=class{constructor(e){this.httpClient=e;}async moderate(e,s){return this.httpClient.request({method:"POST",path:g.MODERATE_CONVERSATIONS,body:e,accessToken:s?.accessToken})}async blockUser(e,s){let o=Array.isArray(e)?e.map(a=>({id:a})):[{id:e}];return this.moderate({user_ids:o,actions:["block_user"]},s)}async unblockUser(e,s){let o=Array.isArray(e)?e.map(a=>({id:a})):[{id:e}];return this.moderate({user_ids:o,actions:["unblock_user"]},s)}async banUser(e,s){let o=Array.isArray(e)?e.map(a=>({id:a})):[{id:e}];return this.moderate({user_ids:o,actions:["ban_user"]},s)}async unbanUser(e,s){let o=Array.isArray(e)?e.map(a=>({id:a})):[{id:e}];return this.moderate({user_ids:o,actions:["unban_user"]},s)}async moveToSpam(e,s){let o=Array.isArray(e)?e.map(a=>({id:a})):[{id:e}];return this.moderate({user_ids:o,actions:["move_to_spam"]},s)}async blockAndSpam(e,s){let o=Array.isArray(e)?e.map(a=>({id:a})):[{id:e}];return this.moderate({user_ids:o,actions:["block_user","move_to_spam"]},s)}};var r=class extends Error{constructor(e){super(e),this.name="TemplateValidationError";}};function V(t){if(t.length===0)throw new r("Generic template must have at least 1 element");if(t.length>i.GENERIC_ELEMENTS_MAX)throw new r(`Generic template cannot have more than ${i.GENERIC_ELEMENTS_MAX} elements`);t.forEach((e,s)=>{me(e,s);});}function me(t,e){if(!t.title||t.title.trim()==="")throw new r(`Element ${e}: title is required`);if(t.title.length>i.GENERIC_TITLE_MAX_CHARS)throw new r(`Element ${e}: title cannot exceed ${i.GENERIC_TITLE_MAX_CHARS} characters`);if(t.subtitle&&t.subtitle.length>i.GENERIC_SUBTITLE_MAX_CHARS)throw new r(`Element ${e}: subtitle cannot exceed ${i.GENERIC_SUBTITLE_MAX_CHARS} characters`);if(t.image_url&&!M(t.image_url))throw new r(`Element ${e}: image_url must be HTTPS`);if(t.buttons&&v(t.buttons,`Element ${e}`),!!!(t.subtitle||t.image_url||t.default_action||t.buttons&&t.buttons.length>0))throw new r(`Element ${e}: must have at least one additional property beyond title`)}function $(t,e){if(!t||t.trim()==="")throw new r("Button template text is required");if(t.length>i.BUTTON_TEXT_MAX_CHARS)throw new r(`Button template text cannot exceed ${i.BUTTON_TEXT_MAX_CHARS} characters`);if(e.length===0)throw new r("Button template must have at least 1 button");v(e,"Button template");}function K(t){if(!t.media_type)throw new r("Media template element must have media_type");if(!t.url&&!t.attachment_id)throw new r("Media template element must have either url or attachment_id");if(t.url&&t.attachment_id)throw new r("Media template element cannot have both url and attachment_id");if(t.url&&!M(t.url))throw new r("Media template url must be HTTPS");if(t.buttons){if(t.buttons.length>i.MEDIA_BUTTONS_MAX_COUNT)throw new r(`Media template cannot have more than ${i.MEDIA_BUTTONS_MAX_COUNT} buttons`);v(t.buttons,"Media template");}}function v(t,e){if(t.length>i.BUTTONS_MAX_COUNT)throw new r(`${e} cannot have more than ${i.BUTTONS_MAX_COUNT} buttons`);t.forEach((s,o)=>{le(s,`${e} button ${o}`);});}function le(t,e){if(!t.type)throw new r(`${e}: type is required`);if(t.type!=="account_unlink"&&(!t.title||t.title.trim()===""))throw new r(`${e}: title is required for ${t.type} buttons`);if(t.title&&t.title.length>i.BUTTON_TITLE_MAX_CHARS)throw new r(`${e}: title cannot exceed ${i.BUTTON_TITLE_MAX_CHARS} characters`);switch(t.type){case "web_url":if(!t.url)throw new r(`${e}: url is required for web_url buttons`);if(!M(t.url))throw new r(`${e}: url must be HTTPS for web_url buttons`);break;case "postback":if(!t.payload)throw new r(`${e}: payload is required for postback buttons`);if(t.payload.length>i.POSTBACK_PAYLOAD_MAX_CHARS)throw new r(`${e}: payload cannot exceed ${i.POSTBACK_PAYLOAD_MAX_CHARS} characters`);break;case "phone_number":if(!t.payload)throw new r(`${e}: payload is required for phone_number buttons`);if(!t.payload.startsWith("+"))throw new r(`${e}: phone_number payload must start with + (e.g., +1234567890)`);break;case "game_play":break;case "account_link":if(!t.url)throw new r(`${e}: url is required for account_link buttons`);if(!M(t.url))throw new r(`${e}: url must be HTTPS for account_link buttons`);break;}if(t.type==="web_url"&&t.messenger_extensions&&t.fallback_url&&!M(t.fallback_url))throw new r(`${e}: fallback_url must be HTTPS`)}function M(t){try{return new URL(t).protocol==="https:"}catch{return false}}var k=class{constructor(e){this.httpClient=e;}async generic(e,s){V(e.elements);let o={template_type:"generic",elements:e.elements,image_aspect_ratio:e.image_aspect_ratio},a={recipient:e.recipient,messaging_type:e.messaging_type||"UPDATE",message:{attachment:{type:"template",payload:o}},notification_type:e.notification_type,tag:e.tag};return this.httpClient.request({method:"POST",path:g.MESSAGES,body:a,accessToken:s?.accessToken})}async button(e,s){$(e.text,e.buttons);let o={template_type:"button",text:e.text,buttons:e.buttons},a={recipient:e.recipient,messaging_type:e.messaging_type||"UPDATE",message:{attachment:{type:"template",payload:o}},notification_type:e.notification_type,tag:e.tag};return this.httpClient.request({method:"POST",path:g.MESSAGES,body:a,accessToken:s?.accessToken})}async media(e,s){K(e.element);let o={template_type:"media",elements:[e.element]},a={recipient:e.recipient,messaging_type:e.messaging_type||"UPDATE",message:{attachment:{type:"template",payload:o}},notification_type:e.notification_type,tag:e.tag};return this.httpClient.request({method:"POST",path:g.MESSAGES,body:a,accessToken:s?.accessToken})}async product(e,s){let o={template_type:"product",elements:e.elements},a={recipient:e.recipient,messaging_type:e.messaging_type||"UPDATE",message:{attachment:{type:"template",payload:o}},notification_type:e.notification_type,tag:e.tag};return this.httpClient.request({method:"POST",path:g.MESSAGES,body:a,accessToken:s?.accessToken})}};var S=class{constructor(e){this.httpClient=e;}async get(e,s){let{psid:o,fields:a=["first_name","last_name"]}=e,n=new URLSearchParams({fields:a.join(",")});return this.httpClient.request({method:"GET",path:`/${o}?${n.toString()}`,body:void 0,accessToken:s?.accessToken})}async getBasic(e,s){return this.get({psid:e,fields:["first_name","last_name","profile_pic"]},s)}async getFull(e,s){return this.get({psid:e,fields:["id","name","first_name","last_name","profile_pic","locale","timezone","gender"]},s)}async getName(e,s){return this.get({psid:e,fields:["first_name","last_name"]},s)}async getProfilePicture(e,s){return this.get({psid:e,fields:["profile_pic"]},s)}};var W=class{send;attachments;moderation;templates;profile;httpClient;constructor(e={}){this.validateConfig(e);let s={accessToken:e.accessToken,version:e.version||q,baseUrl:e.baseUrl,timeout:e.timeout,maxRetries:e.maxRetries};this.httpClient=new P(s),this.send=new f(this.httpClient),this.attachments=new y(this.httpClient),this.moderation=new T(this.httpClient),this.templates=new k(this.httpClient),this.profile=new S(this.httpClient);}validateConfig(e){if(e.accessToken!==void 0&&(typeof e.accessToken!="string"||e.accessToken.trim()===""))throw new m("Access token must be a non-empty string");if(e.version&&typeof e.version!="string")throw new m("API version must be a string");if(e.timeout&&(typeof e.timeout!="number"||e.timeout<=0))throw new m("Timeout must be a positive number");if(e.maxRetries&&(typeof e.maxRetries!="number"||e.maxRetries<0))throw new m("Max retries must be a non-negative number")}};var A=(c=>(c.MESSAGE="message",c.MESSAGE_EDIT="message_edit",c.MESSAGE_REACTION="reaction",c.MESSAGE_READ="read",c.MESSAGING_FEEDBACK="messaging_feedback",c.MESSAGING_POSTBACK="postback",c))(A||{});function Ee(t){return typeof t.id=="string"&&t.id.length>0}function Y(t){let e=[];if(t.object==="page"&&Array.isArray(t.entry))for(let s of t.entry)Array.isArray(s.messaging)&&e.push(...s.messaging);return e}function R(t){let e=Ee(t.sender);return {senderId:t.sender.id,userRef:t.sender.user_ref,recipientId:t.recipient.id,timestamp:t.timestamp,isIdentifiedUser:e,eventDate:new Date(t.timestamp)}}function be(t){return t&&typeof t=="object"&&"message_edit"in t}function he(t){return {...R(t),messageId:t.message_edit.mid,updatedText:t.message_edit.text,editCount:t.message_edit.num_edit}}var ue={MAX_EDITS:5,EVENT_TYPE:"message_edit"};var I=(d=>(d.LIKE="like",d.DISLIKE="dislike",d.LOVE="love",d.SAD="sad",d.ANGRY="angry",d.WOW="wow",d.SMILE="smile",d.OTHER="other",d))(I||{}),O=(s=>(s.REACT="react",s.UNREACT="unreact",s))(O||{});function fe(t){return t&&typeof t=="object"&&"read"in t}function ye(t){return {senderId:t.sender.id,recipientId:t.recipient.id,watermarkTimestamp:t.read.watermark,readTimestamp:t.timestamp,watermarkDate:new Date(t.read.watermark),readDate:new Date(t.timestamp)}}function Q(t,e){return t<=e}function z(t,e){return t.filter(s=>Q(s.timestamp,e))}function Te(t,e){return z(t,e).length}var Me={EVENT_TYPE:"message_reads",READ_PROPERTY:"read"};function ke(t){return t&&typeof t=="object"&&"postback"in t}function Z(t){return t.postback&&"referral"in t.postback&&t.postback.referral!=null}function J(t){return t&&typeof t.id=="string"&&t.id.length>0}function Se(t){let e=Z(t),s=J(t.sender);return {payload:t.postback.payload,senderId:t.sender.id,userRef:t.sender.user_ref,recipientId:t.recipient.id,buttonTitle:t.postback.title,messageId:t.postback.mid,timestamp:t.timestamp,referralContext:e?{ref:t.postback.referral.ref,source:t.postback.referral.source,type:t.postback.referral.type}:void 0,isReferred:e,isIdentifiedUser:s}}var Ae={GET_STARTED:"GET_STARTED",MAIN_MENU:"MAIN_MENU",HELP:"HELP",SUPPORT:"SUPPORT",CONTACT:"CONTACT",CONTACT_SALES:"CONTACT_SALES",CONTACT_SUPPORT:"CONTACT_SUPPORT",BACK:"BACK",NEXT:"NEXT",CANCEL:"CANCEL",SETTINGS:"SETTINGS",PREFERENCES:"PREFERENCES"},_e={MAX_PAYLOAD_LENGTH:1e3,EVENT_TYPE:"postback",REFERRAL_SOURCES:{SHORTLINK:"SHORTLINK",ADS:"ADS",MESSENGER_CODE:"MESSENGER_CODE"},REFERRAL_TYPES:{OPEN_THREAD:"OPEN_THREAD"}};var N=(o=>(o.CSAT="csat",o.NPS="nps",o.CES="ces",o))(N||{}),w=(o=>(o.ONE_TO_FIVE="one_to_five",o.FIVE_STARS="five_stars",o.FIVE_EMOJIS="five_emojis",o))(w||{}),G=(e=>(e.ZERO_TO_TEN="zero_to_ten",e))(G||{}),D=(e=>(e.ONE_TO_SEVEN="one_to_seven",e))(D||{}),U=(e=>(e.FREE_FORM="free_form",e))(U||{});function Pe(t){return t&&typeof t=="object"&&"messaging_feedback"in t}function Re(t){let e=[];return t.messaging_feedback.feedback_screens.forEach(s=>{Object.entries(s.questions).forEach(([o,a])=>{e.push({questionId:o,feedbackType:a.type,score:parseInt(a.payload,10),textFeedback:a.follow_up?.payload,screenId:s.screen_id});});}),{senderId:t.sender.id,recipientId:t.recipient.id,submissionTimestamp:t.timestamp,screenCount:t.messaging_feedback.feedback_screens.length,allResponses:e}}function xe(t){let e=new Map;return t.messaging_feedback.feedback_screens.forEach(s=>{Object.values(s.questions).forEach(o=>{let a=parseInt(o.payload,10),n=e.get(o.type)||[];e.set(o.type,[...n,a]);});}),e}function Ce(t){let e=[];return t.messaging_feedback.feedback_screens.forEach(s=>{Object.values(s.questions).forEach(o=>{o.follow_up?.payload&&e.push(o.follow_up.payload);});}),e}var E={MAX_TEXT_FEEDBACK_LENGTH:400,SCORE_RANGES:{csat:{min:1,max:5},nps:{min:0,max:10},ces:{min:1,max:7}},TEMPLATE_EXPIRY:{MIN_DAYS:1,MAX_DAYS:7,DEFAULT_DAYS:1},QUESTION_ID:{MAX_LENGTH:80,VALID_PATTERN:/^[a-zA-Z0-9_]+$/},TEMPLATE_LIMITS:{MAX_TITLES:1,MAX_SCORING_COMPONENTS:1},EVENT_TYPE:"messaging_feedback"};function ve(t,e){let s=E.SCORE_RANGES[t];return Number.isInteger(e)&&e>=s.min&&e<=s.max}function We(t){return t.length<=E.QUESTION_ID.MAX_LENGTH&&E.QUESTION_ID.VALID_PATTERN.test(t)}function Ie(t){return t.length<=E.MAX_TEXT_FEEDBACK_LENGTH}var F=(p=>(p.AUDIO="audio",p.FILE="file",p.IMAGE="image",p.VIDEO="video",p.FALLBACK="fallback",p.REEL="reel",p.IG_REEL="ig_reel",p))(F||{}),B=(o=>(o.OPEN_THREAD="OPEN_THREAD",o.PRODUCT="product",o.ADS="ads",o))(B||{}),L=(n=>(n.MESSENGER_CODE="MESSENGER_CODE",n.DISCOVER_TAB="DISCOVER_TAB",n.ADS="ADS",n.SHORTLINK="SHORTLINK",n.CUSTOMER_CHAT_PLUGIN="CUSTOMER_CHAT_PLUGIN",n))(L||{});function Oe(t){return t&&typeof t=="object"&&"message"in t}function Ne(t){return typeof t.text=="string"&&t.text.length>0}function x(t){return Array.isArray(t.attachments)&&t.attachments.length>0}function ee(t){return t.quick_reply!==void 0}function te(t){return t.reply_to!==void 0}function se(t){return t.referral!==void 0}function oe(t,e){return t.type===e}function we(t){let{message:e}=t;return {...R(t),messageId:e.mid,text:e.text,hasAttachments:x(e),isQuickReply:ee(e),isReply:te(e),hasReferral:se(e),quickReplyPayload:e.quick_reply?.payload,repliedToMessageId:e.reply_to?.mid}}function Ge(t,e){return x(t)?t.attachments.filter(s=>oe(s,e)):[]}function De(t){return x(t)?t.attachments.map(e=>e.payload.url):[]}var Ue={MAX_TEXT_LENGTH:2e3,MAX_QUICK_REPLY_PAYLOAD_LENGTH:1e3,MAX_REFERRAL_REF_LENGTH:250,EVENT_TYPE:"message"},Fe={image:["image/jpeg","image/png","image/gif","image/webp"],video:["video/mp4","video/avi","video/quicktime","video/webm"],audio:["audio/mpeg","audio/mp4","audio/wav","audio/ogg"],file:["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/plain"]};function C(t){return !t||typeof t!="object"?null:"type"in t&&Object.values(A).includes(t.type)?t.type:"message"in t?"message":"message_edit"in t?"message_edit":"reaction"in t?"reaction":"read"in t?"read":"messaging_feedback"in t?"messaging_feedback":"postback"in t?"postback":null}function ae(t){let e=new Set;if(t.object==="page"&&Array.isArray(t.entry)){for(let s of t.entry)if(Array.isArray(s.messaging))for(let o of s.messaging){let a=C(o);a&&e.add(a);}}return Array.from(e)}function H(t){return Y(t)}function Be(t){let e=C(t);return e?"type"in t?t:{...t,type:e}:null}async function ne(t,e){let s=H(t);for(let o of s){let a=Be(o);if(!a){e.onUnknown&&await e.onUnknown(o);continue}switch(a.type){case "message":e.onMessage&&await e.onMessage(a);break;case "message_edit":e.onMessageEdit&&await e.onMessageEdit(a);break;case "reaction":e.onMessageReaction&&await e.onMessageReaction(a);break;case "read":e.onMessageRead&&await e.onMessageRead(a);break;case "messaging_feedback":e.onMessagingFeedback&&await e.onMessagingFeedback(a);break;case "postback":e.onMessagingPostback&&await e.onMessagingPostback(a);break;default:let n=a;e.onUnknown&&await e.onUnknown(n);break}}}function re(t,e){return t["hub.mode"]==="subscribe"&&t["hub.verify_token"]===e?t["hub.challenge"]:null}async function ie(t,e,s){if(!e)return {isValid:false,error:"Missing X-Hub-Signature-256 header"};if(!e.startsWith("sha256="))return {isValid:false,error:"Invalid signature format. Expected sha256= prefix"};if(!s)return {isValid:false,error:"App secret is required for signature verification"};try{if(typeof Buffer>"u")return {isValid:!1,error:"Signature verification is only supported in Node.js environments"};let o=await import('crypto'),a=e.substring(7),n=o.createHmac("sha256",s).update(t).digest("hex"),c=Buffer.from(a,"hex"),p=Buffer.from(n,"hex");if(c.length!==p.length)return {isValid:!1,error:"Signature length mismatch"};let d=o.timingSafeEqual(c,p);return {isValid:d,error:d?void 0:"Signature verification failed"}}catch(o){return {isValid:false,error:`Signature verification error: ${o instanceof Error?o.message:"Unknown error"}`}}}
|
|
2
|
+
export{ce as ATTACHMENT_LIMITS,Fe as ATTACHMENT_MIME_TYPES,y as AttachmentsAPI,D as CESDisplayOption,Ae as COMMON_POSTBACK_PAYLOADS,w as CSATDisplayOption,N as FeedbackType,U as FollowUpType,Ue as MESSAGE_CONSTANTS,ue as MESSAGE_EDIT_CONSTANTS,_ as MESSAGE_LIMITS,Me as MESSAGE_READS_CONSTANTS,E as MESSAGING_FEEDBACK_CONSTANTS,O as MessageReactionAction,I as MessageReactionType,L as MessageReferralSource,B as MessageReferralType,u as MessageValidationError,W as Messenger,l as MessengerAPIError,m as MessengerConfigError,b as MessengerNetworkError,h as MessengerTimeoutError,T as ModerationAPI,G as NPSDisplayOption,_e as POSTBACK_CONSTANTS,S as ProfileAPI,f as SendAPI,i as TEMPLATE_LIMITS,r as TemplateValidationError,k as TemplatesAPI,F as WebhookAttachmentType,A as WebhookEventType,we as extractMessageContext,he as extractMessageEditContext,ye as extractMessageReadsContext,Re as extractMessagingFeedbackContext,Se as extractPostbackContext,Ce as extractTextFeedback,H as extractWebhookEvents,De as getAttachmentUrls,Ge as getAttachmentsByType,xe as getFeedbackScoresByType,Te as getReadMessageCount,z as getReadMessages,C as getWebhookEventType,ae as getWebhookPayloadEventTypes,x as hasAttachments,ee as hasQuickReply,se as hasReferral,Z as hasReferralData,oe as isAttachmentType,J as isIdentifiedSender,be as isMessageEditEvent,Oe as isMessageEvent,Q as isMessageRead,fe as isMessageReadsEvent,Pe as isMessagingFeedbackEvent,ke as isMessagingPostbackEvent,te as isReplyMessage,Ne as isTextMessage,ve as isValidFeedbackScore,We as isValidQuestionId,Ie as isValidTextFeedback,ne as processWebhookEvents,ie as verifyWebhookSignature,re as verifyWebhookSubscription};//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|