Created
          August 7, 2025 03:26 
        
      - 
      
- 
        Save pedroSoaresll/cfbb51a735bc8bd51fa00e5f1e00942f to your computer and use it in GitHub Desktop. 
    This will help you to correct type WhatsApp Cloud API body payload to send messages based on options available
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | export type WhatsAppMessage = | |
| | TextMessage | |
| | ImageMessage | |
| | DocumentMessage | |
| | AudioMessage | |
| | VideoMessage | |
| | StickerMessage | |
| | LocationMessage | |
| | ContactMessage | |
| | TemplateMessage | |
| | InteractiveMessage; | |
| type BaseMessage = { | |
| messaging_product: "whatsapp"; | |
| recipient_type: "individual" | "group"; | |
| to: string; | |
| }; | |
| type TextMessage = BaseMessage & { | |
| type: "text"; | |
| text: { | |
| body: string; | |
| preview_url?: boolean; | |
| }; | |
| }; | |
| type ImageMessage = BaseMessage & { | |
| type: "image"; | |
| image: { | |
| link: string; | |
| caption?: string; | |
| }; | |
| }; | |
| type DocumentMessage = BaseMessage & { | |
| type: "document"; | |
| document: { | |
| link: string; | |
| caption?: string; | |
| filename?: string; | |
| }; | |
| }; | |
| type AudioMessage = BaseMessage & { | |
| type: "audio"; | |
| audio: { | |
| link: string; | |
| }; | |
| }; | |
| type VideoMessage = BaseMessage & { | |
| type: "video"; | |
| video: { | |
| link: string; | |
| caption?: string; | |
| }; | |
| }; | |
| type StickerMessage = BaseMessage & { | |
| type: "sticker"; | |
| sticker: { | |
| link: string; | |
| }; | |
| }; | |
| type LocationMessage = BaseMessage & { | |
| type: "location"; | |
| location: { | |
| latitude: number; | |
| longitude: number; | |
| name?: string; | |
| address?: string; | |
| }; | |
| }; | |
| type ContactMessage = BaseMessage & { | |
| type: "contacts"; | |
| contacts: Array<{ | |
| addresses?: Array<{ | |
| street?: string; | |
| city?: string; | |
| state?: string; | |
| zip?: string; | |
| country?: string; | |
| country_code?: string; | |
| type?: string; | |
| }>; | |
| birthday?: string; | |
| emails?: Array<{ | |
| email: string; | |
| type?: string; | |
| }>; | |
| name: { | |
| formatted_name: string; | |
| first_name?: string; | |
| last_name?: string; | |
| middle_name?: string; | |
| suffix?: string; | |
| prefix?: string; | |
| }; | |
| org?: { | |
| company?: string; | |
| department?: string; | |
| title?: string; | |
| }; | |
| phones?: Array<{ | |
| phone: string; | |
| type?: string; | |
| wa_id?: string; | |
| }>; | |
| urls?: Array<{ | |
| url: string; | |
| type?: string; | |
| }>; | |
| }>; | |
| }; | |
| type TemplateMessage = BaseMessage & { | |
| type: "template"; | |
| template: { | |
| name: string; | |
| language: { | |
| code: string; | |
| }; | |
| components?: any[]; | |
| }; | |
| }; | |
| type InteractiveMessage = BaseMessage & { | |
| type: "interactive"; | |
| interactive: any; // You can further type this based on the interactive message structure | |
| }; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment