Skip to main content

Overview

Bailey provides a unified sendMessage API for sending all types of messages. Whether you’re sending text, media, or interactive content, the same function is used with different content types.

Basic Message Sending

All messages are sent using the sendMessage method:
const jid: string
const content: AnyMessageContent
const options: MiscMessageGenerationOptions

await sock.sendMessage(jid, content, options)

Parameters

  • jid: The recipient’s WhatsApp ID
    • For individuals: [country code][phone number]@s.whatsapp.net
    • For groups: [email protected]
    • For broadcast lists: [timestamp]@broadcast
    • For stories: status@broadcast
  • content: The message content (see AnyMessageContent)
  • options: Message options like quoted messages, ephemeral settings (see MiscMessageGenerationOptions)

WhatsApp ID Format

Understanding the JID (Jabber ID) format is crucial for sending messages:
const jid = '[email protected]' // +1 999-999-9999
The JID must not include +, (), or - characters. Only include the country code and phone number digits.

Simple Text Message

The most basic message type:
await sock.sendMessage(jid, { text: 'Hello World!' })

Message Return Value

The sendMessage function returns a WAMessage object containing:
const msg = await sock.sendMessage(jid, { text: 'hello' })

// Message structure
msg.key // { remoteJid, fromMe, id }
msg.message // The message content
msg.messageTimestamp // Unix timestamp
msg.status // Message status (PENDING, SERVER_ACK, DELIVERY_ACK, READ, PLAYED)

Message Types Overview

Baileys supports a wide variety of message types:

Text-Based Messages

  • Text messages with mentions
  • Link previews
  • Quoted/replied messages

Media Messages

  • Images (with captions)
  • Videos (including GIFs)
  • Audio (voice notes)
  • Documents
  • Stickers

Location & Contact

  • Location sharing
  • Contact cards

Interactive Messages

  • Polls
  • Reactions
  • Pin messages
  • Events

Special Messages

  • Forward messages
  • View-once messages
  • Disappearing messages
See the following pages for detailed examples of each message type:

Error Handling

try {
  const msg = await sock.sendMessage(jid, { text: 'Hello!' })
  console.log('Message sent:', msg.key.id)
} catch (error) {
  console.error('Failed to send message:', error)
}
Messages may fail to send due to network issues, invalid JIDs, or the recipient blocking you. Always implement proper error handling.

Next Steps

Text Messages

Learn about sending text with mentions, quotes, and links

Media Messages

Send images, videos, audio, and documents

Message Options

Configure ephemeral messages, quotes, and more

Modify Messages

Edit and delete sent messages

Build docs developers (and LLMs) love