generateMessageIDV2
Generates a unique message ID v2 compatible with WhatsApp’s format.string
The user’s JID to include in the message ID generation
string
A unique message ID in the format
3EB0 followed by 18 hex characters- When you need to generate a custom message ID
- For creating messages programmatically
- The ID includes timestamp and random data for uniqueness
getContentType
Extracts the content type key from a message object.proto.IMessage | undefined
The message content object to analyze
keyof proto.IMessage | undefined
The message content type (e.g., ‘conversation’, ‘imageMessage’, ‘videoMessage’)
- To determine what type of message you’re dealing with
- Before processing message content
- For routing messages based on their type
extractUrlFromText
Extracts the first URL found in a text string using regex.string
required
The text string to search for URLs
string | undefined
The first URL found in the text, or undefined if no URL is present
- To detect if a message contains a URL
- Before generating link previews
- For URL validation or filtering
generateLinkPreviewIfRequired
Generates link preview metadata for a URL in the text if agetUrlInfo function is provided.
string
required
The message text potentially containing a URL
(url: string) => Promise<WAUrlInfo>
Function to fetch URL metadata (title, description, thumbnail)
ILogger
Logger instance for error tracking
WAUrlInfo | undefined
Link preview information including title, description, and thumbnail
- To automatically generate link previews in messages
- When sending text messages with URLs
- For rich message formatting
normalizeMessageContent
Normalizes ephemeral, view once, and other wrapped messages to their core content.WAMessageContent | null | undefined
The message content to normalize
WAMessageContent | undefined
The normalized message content without wrappers
- To extract the actual message content from wrapped messages
- Before processing or displaying message content
- When you need the core message regardless of ephemeral/view-once status
generateForwardMessageContent
Generates message content for forwarding a message, maintaining the forward chain.WAMessage
required
The message to forward
boolean
default:false
Whether to show the message as forwarded even if it’s from you
WAMessageContent
Message content with forwarding metadata and score updated
- When implementing message forwarding
- To maintain the forward chain (shows “Forwarded” label)
- Automatically handles forwarding score incrementation
generateWAMessageFromContent
Generates a complete WAMessage object from message content.string
required
The recipient’s JID (e.g., ‘1234567890@s.whatsapp.net’)
WAMessageContent
required
The message content to wrap
MessageGenerationOptionsFromContent
required
Options for message generation
Options
Date
Message timestamp (defaults to current time)
string
Custom message ID (auto-generated if not provided)
WAMessage
Message to quote/reply to
string
required
Your user JID
number
Ephemeral message expiration in seconds
WAMessage
Complete message object ready to be sent
- When you have raw message content and need a complete message object
- For advanced message construction
- When implementing custom message types
extractMessageContent
Extracts the actual message content from template messages and button messages.WAMessageContent | undefined | null
Message content to extract from
WAMessageContent | undefined
The extracted core message content
- To get the media from button/template messages
- Before downloading media from interactive messages
- When processing complex message types
getDevice
Returns the device type based on the message ID format.string
required
The message ID to analyze
'ios' | 'web' | 'android' | 'desktop' | 'unknown'
The predicted device type based on ID pattern
- For analytics on which devices users are messaging from
- To detect message origin
- For debugging purposes