export interface WhatsAppMessage { messaging_product: 'whatsapp'; recipient_type: 'individual'; to: string; type: MessageType; text?: TextMessage; template?: TemplateMessage; interactive?: InteractiveMessage; image?: MediaMessage; document?: MediaMessage; audio?: MediaMessage; } export type MessageType = 'text' | 'template' | 'interactive' | 'image' | 'document' | 'audio'; export interface TextMessage { preview_url?: boolean; body: string; } export interface TemplateMessage { name: string; language: { code: string; }; components?: TemplateComponent[]; } export interface TemplateComponent { type: 'header' | 'body' | 'button'; parameters?: TemplateParameter[]; sub_type?: string; index?: number; } export interface TemplateParameter { type: 'text' | 'image' | 'document' | 'video'; text?: string; image?: { link: string; }; } export interface InteractiveMessage { type: 'button' | 'list' | 'product' | 'product_list'; header?: { type: 'text' | 'image' | 'document' | 'video'; text?: string; }; body: { text: string; }; footer?: { text: string; }; action: InteractiveAction; } export interface InteractiveAction { buttons?: InteractiveButton[]; button?: string; sections?: InteractiveSection[]; } export interface InteractiveButton { type: 'reply'; reply: { id: string; title: string; }; } export interface InteractiveSection { title?: string; rows: InteractiveSectionRow[]; } export interface InteractiveSectionRow { id: string; title: string; description?: string; } export interface MediaMessage { link?: string; id?: string; caption?: string; filename?: string; } export interface WebhookPayload { object: string; entry: WebhookEntry[]; } export interface WebhookEntry { id: string; changes: WebhookChange[]; } export interface WebhookChange { value: WebhookValue; field: string; } export interface WebhookValue { messaging_product: string; metadata: { display_phone_number: string; phone_number_id: string; }; contacts?: WebhookContact[]; messages?: WebhookIncomingMessage[]; statuses?: WebhookStatus[]; } export interface WebhookContact { profile: { name: string; }; wa_id: string; } export interface WebhookIncomingMessage { from: string; id: string; timestamp: string; type: string; text?: { body: string; }; image?: WebhookMedia; audio?: WebhookMedia; document?: WebhookMedia; location?: { latitude: number; longitude: number; name?: string; address?: string; }; interactive?: { type: string; button_reply?: { id: string; title: string; }; list_reply?: { id: string; title: string; description?: string; }; }; context?: { from: string; id: string; }; } export interface WebhookMedia { id: string; mime_type: string; sha256?: string; caption?: string; filename?: string; } export interface WebhookStatus { id: string; status: 'sent' | 'delivered' | 'read' | 'failed'; timestamp: string; recipient_id: string; errors?: Array<{ code: number; title: string; message: string; }>; }