Overview
The Context object is the heart of message handling in WAPI. It wraps every incoming WhatsApp message and provides rich metadata, parsed command information, and convenient reply methods. Every middleware and command handler receives a Context instance.Message Data
Access sender, chat, text, media, and more
Reply Methods
Send text, images, videos, audio, and stickers
Message Actions
Edit and delete messages programmatically
Command Parsing
Pre-parsed command name and arguments
Class Hierarchy
The Context class extends the Message class:Core Properties
Bot Reference
Command Properties
Fromsrc/core/context/context.ts lines 9-11:
| Message | prefixUsed | commandName | args |
|---|---|---|---|
!hello | ! | hello | [] |
/greet Alice | / | greet | ['Alice'] |
!add 10 20 | ! | add | ['10', '20'] |
regular message | "" | "" | [] |
Message Metadata
Fromsrc/core/context/message.ts lines 21-27:
Chat Information
Fromsrc/types/context.ts lines 22-29:
Sender Information
Fromsrc/types/context.ts lines 30-34:
Links and Mentions
Fromsrc/core/context/message.ts lines 28-29:
Quoted Messages
Fromsrc/core/context/message.ts line 30:
quoted contains the original message:
Reply Methods
reply()
Send a text reply to the message. Fromsrc/core/context/context.ts lines 25-40:
text: The text to sendoptions: Optional reply optionsmentions: Array of JIDs to mentioncontextInfo: Advanced context information
replyWithImage()
Send an image reply. Fromsrc/core/context/context.ts lines 41-69:
image: Image URL (string) or Bufferoptions: Optional optionscaption: Image captionmimetype: MIME type (default:image/jpeg)viewOnce: View-once imagementions: Array of JIDs to mention
replyWithVideo()
Send a video reply. Fromsrc/core/context/context.ts lines 70-98:
video: Video URL (string) or Bufferoptions: Optional optionscaption: Video captionmimetype: MIME type (default:video/mp4)viewOnce: View-once videogifPlayback: Play as GIFmentions: Array of JIDs to mention
replyWithAudio()
Send an audio reply. Fromsrc/core/context/context.ts lines 99-127:
audio: Audio URL (string) or Bufferoptions: Optional optionsmimetype: MIME type (default:audio/mpeg)viewOnce: View-once audiomentions: Array of JIDs to mention
replyWithSticker()
Send a sticker reply. Fromsrc/core/context/context.ts lines 128-147:
sticker: Sticker as Buffer (WebP format)options: Optional reply options
Message Actions
del()
Delete the message. Fromsrc/core/context/context.ts lines 148-155:
edit()
Edit a message sent by the bot. Fromsrc/core/context/context.ts lines 156-173:
fromMe: true)
Examples:
download()
Download media from the message. Fromsrc/core/context/context.ts lines 174-176:
Raw Message Access
Fromsrc/core/context/message.ts line 9:
Advanced Patterns
Conversation State
Menu System
Reaction Handler
Best Practices
Always check message type before downloading
Always check message type before downloading
Use optional chaining for quoted messages
Use optional chaining for quoted messages
Store sent messages for editing/deleting
Store sent messages for editing/deleting
Check chat type before group operations
Check chat type before group operations
Next Steps
Commands
Build command-based interactions
Middleware
Compose message handlers