Every message that arrives in any chat your bot is part of is surfaced through a singleDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/jzszdznzzl/WABotJS/llms.txt
Use this file to discover all available pages before exploring further.
onMessage callback. The callback receives a rich Message object that abstracts the raw Baileys payload and exposes pre-parsed fields for text, media metadata, sender identity, quoted context, and more.
The onMessage Callback
Register your handler before calling bot.login(). WABotJS fires it for every event with type === 'notify' in the underlying messages.upsert Baileys event — this covers new incoming messages in private chats and groups. Protocol messages (e.g. delivery receipts) are filtered out automatically.
Message Fields
EveryMessage instance exposes the following fields:
Unique identifier for the message, sourced from
raw.key.id.The JID of the conversation. This is the group JID for group messages, or the sender’s LID
(Linked ID) for private chats. WABotJS resolves phone-number JIDs to LIDs using the internal JID
cache where possible.
The LID of the message author. For messages sent by the bot itself, this is the bot account’s LID.
For group messages it is the participant’s LID. May be
undefined if the JID cannot be resolved.The text body or media caption, trimmed of leading/trailing whitespace.
undefined for purely
media messages without a caption, or protocol messages with no displayable content.Array of JIDs that were
@-mentioned in the message. Phone-number JIDs are resolved to LIDs via
the internal cache; unresolvable JIDs are included as-is.Unix timestamp in seconds indicating when the message was sent.
The Baileys content-type key for the message (e.g.
"conversation", "imageMessage",
"videoMessage", "audioMessage", "documentMessage", "stickerMessage"). Unwrapped through
view-once and ephemeral containers so you always get the innermost content type.MIME type string for media messages, e.g.
"image/jpeg", "video/mp4", "audio/ogg; codecs=opus".
undefined for non-media messages.The
fileSha256 hash of the media file as a Buffer. Used to verify integrity after download.
undefined for non-media messages.The
mediaKey Buffer required to decrypt the media file after downloading. undefined for
non-media messages.A
URL object pointing to the CDN location of the media. undefined for non-media messages.The
directPath string used alongside url to construct the full media CDN URL. undefined for
non-media messages.If this message is a reply to another message,
quoted is a fully hydrated Message instance
representing the original message, with the same set of fields. undefined if the message is not
a reply.Checking Message Context
Use the helper methods onMessage to branch your logic quickly:
Quoted Messages
When a user replies to a previous message,m.quoted holds a Message instance for the original. It carries the same fields — id, chat, sender, text, type, mimetype, url, key, path, and so on — so you can inspect or download the quoted media.
Filtering Messages
Narrow down the messages you act on by combiningisFromMe(), isGroup(), and field checks:
Accessing Raw Data
If you need access to fields not exposed by theMessage abstraction, call m.toRaw() to retrieve the underlying baileys.WAMessage object:
Mutating the object returned by
toRaw() may affect internal WABotJS behaviour. Treat it as
read-only unless you know what you are doing.