/** * Zalo Official Account (OA) - TypeScript Interfaces * * This file contains all TypeScript interfaces for Zalo OA webhook payloads * and event types, based on ZALO_OA_WEBHOOK_APIS.md documentation. */ /** * Base structure for Zalo OA webhook payloads */ export interface IZaloWebhookPayload { event?: string; event_name?: string; timestamp: number; sender: IZaloSender; recipient: IZaloRecipient; message?: IZaloMessage; } /** * Sender information (user) */ export interface IZaloSender { id: string; user_id_by_app?: string; } /** * Recipient information (OA) */ export interface IZaloRecipient { id: string; } /** * Base message structure */ export interface IZaloMessage { text?: string; attachments?: IZaloAttachment[]; payload?: string; url?: string; mid?: string; } /** * Attachment union types */ export interface IZaloAttachment { type: string; payload: IZaloAttachmentPayload; } /** * Attachment payload union types */ export interface IZaloAttachmentPayload { url?: string; sticker_id?: string; coordinates?: { lat: number; long: number; }; title?: string; contact?: { name: string; phone: string; }; } /** * Text message payload */ export interface IZaloTextMessage extends IZaloWebhookPayload { event: 'user_send_text'; message: { text: string; }; } /** * Image message payload */ export interface IZaloImageMessage extends IZaloWebhookPayload { event: 'user_send_image'; message: { attachments: Array<{ type: 'image'; payload: { url: string; }; }>; }; } /** * GIF message payload */ export interface IZaloGifMessage extends IZaloWebhookPayload { event: 'user_send_gif'; message: { attachments: Array<{ type: 'image'; payload: { url: string; }; }>; }; } /** * Sticker message payload */ export interface IZaloStickerMessage extends IZaloWebhookPayload { event: 'user_send_sticker'; message: { attachments: Array<{ type: 'sticker'; payload: { sticker_id: string; }; }>; }; } /** * Location message payload */ export interface IZaloLocationMessage extends IZaloWebhookPayload { event: 'user_send_location'; message: { attachments: Array<{ type: 'location'; payload: { coordinates: { lat: number; long: number; }; }; }>; }; } /** * Follow event payload */ export interface IZaloFollowEvent extends IZaloWebhookPayload { event: 'user_follow'; } /** * Unfollow event payload */ export interface IZaloUnfollowEvent extends IZaloWebhookPayload { event: 'user_unfollow'; } /** * Button click event payload */ export interface IZaloButtonClickEvent extends IZaloWebhookPayload { event: 'user_click_button'; message: { payload: string; }; } /** * Link click event payload */ export interface IZaloLinkClickEvent extends IZaloWebhookPayload { event: 'user_click_link'; message: { url: string; }; } /** * Output Port Mapping * * The trigger node has 6 output ports: * Port 0: Text Message * Port 1: Image * Port 2: Sticker * Port 3: Location * Port 4: Interactive/Follow * Port 5: Others/Fallback */ export declare enum ZaloOutputPort { TEXT_MESSAGE = 0, IMAGE = 1, STICKER = 2, LOCATION = 3, INTERACTIVE_FOLLOW = 4, OTHERS_FALLBACK = 5 } /** * Event to Port mapping constants */ export declare const ZALO_EVENT_PORT_MAP: Record; /** * Get output port index for a given event name * @param eventName - The event name from webhook payload * @returns The output port index (0-5), defaults to 5 (fallback) for unknown events */ export declare function getOutputPortForEvent(eventName: string | undefined): number; /** * Helper to extract event name from payload (defensive check for both 'event' and 'event_name') */ export declare function extractEventName(payload: IZaloWebhookPayload): string | undefined; /** * Helper to extract sender ID from payload */ export declare function extractSenderId(payload: IZaloWebhookPayload): string | undefined; /** * Helper to extract message ID from payload (for idempotency) */ export declare function extractMessageId(payload: IZaloWebhookPayload): string | undefined;