Skip to content

Instantly share code, notes, and snippets.

@pedroSoaresll
Created August 7, 2025 03:26
Show Gist options
  • Save pedroSoaresll/cfbb51a735bc8bd51fa00e5f1e00942f to your computer and use it in GitHub Desktop.
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
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