sendMessage function to send all types of messages. The function handles encryption, media upload, and delivery to all recipient devices automatically.
Basic usage
All messages are sent using thesendMessage method:
Parameters
The recipient’s JID (e.g.,
'[email protected]' for individual chats or '[email protected]' for groups)The message content object. See AnyMessageContent for all supported message types.
Optional configuration for message generation. See MiscMessageGenerationOptions for all available options.
Message content types
TheAnyMessageContent type supports various message formats:
- Text messages: Simple text, with support for mentions, quotes, and formatting
- Media messages: Images, videos, audio, documents, stickers
- Location messages: Share geographical coordinates
- Contact messages: Share vCard contacts
- Poll messages: Create interactive polls
- Reaction messages: React to existing messages
- Forward messages: Forward existing messages
Message generation options
TheMiscMessageGenerationOptions parameter allows you to customize message behavior:
Quote a message
Reply to or quote any message by passing the original message object:The
quoted option works with all message types, not just text messages.Ephemeral messages
Send messages that disappear after a set duration:Cached group metadata
Optimize group message sending by using cached metadata:Status (broadcast) messages
When sending status/broadcast messages, specify the recipient list:Return value
ThesendMessage function returns a WAMessage object containing:
Error handling
Advanced features
Custom message ID
Generate your own message ID:Patch messages before sending
Modify messages before they’re sent (configured at socket level):Best practices
Next steps
Text messages
Learn about text formatting, mentions, and links
Media messages
Send images, videos, audio, and documents
Receiving messages
Handle incoming messages and events
Message modification
Edit, delete, and react to messages