Incoming Message
This event is triggered when a new message is received by your WhatsApp instance.
Best practices
Always check 'fromMe' before processing a message to avoid responding to your own bot's messages.
Check 'hasMedia' before attempting to download or process the 'media' object.
Use the 'source' field to identify if a message was sent via the API or manually via the phone.
The Atomic Unit of Conversation: Deep Analysis of the Message Webhook
In the architecture of any conversational application, the Incoming Message is the fundamental unit of value. It is the primary signal that initiates business workflows, triggers automated intelligence, and drives customer engagement. Within the Wawp platform, the [message] webhook is the most prolific and critical event, acting as the real-time bridge between a user's intent and your system's response.
To master this webhook is to master the conversation itself. This guide provides an architectural deep-dive into the strategic properties of the message payload and the best practices for building a scalable, context-aware ingestion layer.
🏗️ Architectural Philosophy: The Anatomy of Intent
A WhatsApp message is far more than just a string of text. It is a rich data object containing identity, source, status, and media metadata. When your server receives a [message] webhook, it is being handed a Moment of Opportunity.
1. The Strategy of Contextual Siloing (fromMe and source)
One of the most common pitfalls in building WhatsApp bots is the "Infinite Feedback Loop"—where a bot responds to its own message, triggering another message, and so on. Wawp provides two critical "Guardrail" properties to prevent this:
- The
fromMeBoolean: This field is the foundation of your logic's "Self-Awareness." It tells you instantly if the message was sent by your own WhatsApp instance (true) or by an external contact (false). An enterprise-grade integration always filters forfromMe === falseas the very first step of its ingestion pipeline. - The
sourceField: This property provides "Operational Context." It identifies if a message was sent via the Wawp API (api) or manually by a human operator using the physical phone or WhatsApp Web (phone). This distinction is vital for hybrid support models where bots handle initial triage and humans handle complex escalations. If the source isphone, your bot logic can automatically "Step Back" and stop interfering with the human conversation.
2. High-Fidelity Source Identification (JIDs)
In the Wawp ecosystem, every message source is identified by a unique JID (WhatsApp ID). The [from] property allows your system to instantly determine the context of the conversation:
- Individual Chats (@c.us): Messages where [
from] ends in@c.usare 1-on-1 private conversations. This is your primary channel for support and personal engagement. - Group Chats (@g.us): If the [
from] ends in@g.us, the message arrived from a shared group. In this context, the [author] property is critical—it identifies the specific individual within the group who sent the message. - Channels and Newsletters (@newsletter): Messages from public broadcasts or channels will carry the
@newslettersuffix. These are typically read-only or one-way communication streams. - Lookup IDs (@lid): Occasionally, you will see
@lid. These are privacy-preserving identifiers used by Meta for business discovery or internal routing.
By correctly parsing these suffixes, your ingestion layer can route messages to different internal modules (e.g., "Group Bot" vs. "Personal Assistant") without needing to perform expensive database lookups for every event.
🚀 Strategic Use Cases: Powering Intelligent Workflows
The message webhook is the "Sensor" that feeds your business's central nervous system.
1. AI-Augmented Triage and Sentiment Analysis
As soon as a message arrives, your system should not just "Reply." It should "Analyze." By routing the body of the message to a Large Language Model (LLM) or a sentiment analysis engine, you can determine the customer's emotional state and intent.
- Strategic Routing: If the sentiment is "Highly Frustrated" and the intent is "Billing Issue," the system can skip the standard bot menu and immediately alert a senior billing specialist.
- Data Enrichment: Use the incoming message to update the "Last Activity" field in your CRM, ensuring your sales team always has a real-time view of lead engagement.
2. The Visual Evidence Pipeline
When hasMedia is true, the interaction moves from a text-based query to a "Proof-based Interaction." In field services or insurance, a user sends a photo of a damaged item. The Wawp webhook provides a temporary S3 URL to this media. A strategic architecture immediately downloads this binary and tags it with the customer's JID and the Message ID. This "Visual Proof" is then attached to the internal dispatch ticket, providing the field technician with zero-latency visual context before they arrive on-site.
3. Cross-Platform Mirroring and Archival
In regulated industries, every customer interaction must be archived for 7-10 years. The message webhook provides the raw data required to build a "Shadow Archive." Your system can mirror every WhatsApp interaction into a private, searchable database or an official email archive. Because the webhook includes the replyTo metadata, you can perfectly reconstruct threaded conversations, providing a high-fidelity record for legal or compliance audits.
🛡️ Administrative Mandate: Scaling the Ingestion Layer
When your business expands to handling tens of thousands of messages per hour, the efficiency of your webhook handler becomes an infrastructure concern.
1. The Strategy of "Thin Ingestion"
Do not perform heavy-duty work within the webhook request-response cycle. If your server receives a message and spends 3 seconds calling an AI API before responding to Wawp, your message queue will back up, and you'll experience "Retries" for messages you've already processed. The Professional Pattern: Your ingestion script should perform minimal validation, push the message object into a fast-access queue (like Redis or NATS), and return a 200 OK Status immediately. A fleet of "Worker Processes" then picks up messages from the queue to perform the actual business logic. This decouples "Delivery" from "Processing," ensuring your system remains responsive during viral traffic events.
2. Global Search and the "Thread ID"
To build a premium user experience, your system must understand "Conversation State." Use the id and replyTo.id fields to build a local "Conversation Graph." When a user replies to a specific message, your system can look up that Message ID in your database to understand exactly what the user is referring to. This "Contextual Awareness" allows your bot to provide specific, helpful answers rather than generic responses.
🛡️ Operational Best Practices: Maintaining Conversational Integrity
- Idempotency is Key: Always check the unique
idof the incoming message against a "Seen Recently" cache. Network hiccups can cause the same webhook to be delivered twice. If your system isn't idempotent, you might charge a customer twice or send duplicate bot responses. - Handle Revocations: Subscribe to the Revoked Message event. If a customer deletes a message after sending it, your system should reflect this in your internal dashboard to ensure your agents aren't responding to "Ghost" text that no longer exists in the customer's UI.
- MIME-Type Awareness: Don't just check if a message
hasMedia. Check themedia.mimetype. Treating a 50MB PDF document as if it were a 10KB JPEG image will lead to processing errors and slow performance. Build specialized handlers for each media category (Image, Video, Audio, Document).
⚙️ Engineering Best Practices: The Validation Loop
- Monitor "Processing Lag": Track the difference between the
timestampprovided in the message payload (when the user sent it) and the time your system actually finished processing it. A gap of more than 1-2 seconds indicates that your worker fleet is undersized. - Verify Authentication: Ensure that every webhook request contains the expected security headers or query tokens that you configured in your dashboard. This prevents a "Flood Attack" where an external actor could attempt to drain your processing resources by sending fake message payloads.
- Cross-Instance Siloing: If your backend manages 50 different WhatsApp instances, the
sessionfield is your primary filtering key. Ensure your database queries always include thesessionscope to prevent "Data Leakage" where a message for Instance A is accidentally processed by the logic for Instance B.
🎯 Conclusion: Mastering the Art of the Real-Time Signal
The Incoming Message Webhook is the heartbeat of your WhatsApp integration. By treating it not just as a data packet, but as a "Strategic Signal," you move your organization from passive reception to active conversational orchestration. You build a system that hears the customer's intent, understands their context, and responds with engineered precision. In the world of Wawp, every message is a bridge to a deeper relationship, and every webhook is the first step in a perfectly timed journey.
Expected Responses
Explore all possible responses and outcomes from the server. We have documented each status code with data examples to make success and error handling easier.
Example
{
"id": "evt_01aaaaaaaaaaaaaaaaaaaaaaaa",
"timestamp": 1634567890123,
"session": "default",
"metadata": {
"user.id": "123",
"user.email": "email@example.com"
},
"engine": "WEBJS",
"event": "message",
"payload": {
"id": "false_11111111111@c.us_AAAAAAAAAAAAAAAAAAAA",
"timestamp": 1666943582,
"from": "11111111111@c.us",
"fromMe": true,
"source": "api",
"to": "11111111111@c.us",
"participant": null,
"body": "Hello, world!",
"hasMedia": true,
"media": {
"url": "https://api.wawp.net/api/files/example.oga",
"mimetype": "audio/ogg",
"filename": "example.oga",
"s3": {
"Bucket": "my-bucket",
"Key": "default/example.oga"
},
"error": null
},
"ack": -1,
"ackName": "PENDING",
"author": "11111111111@c.us",
"location": {
"description": "London, UK",
"latitude": "51.5074",
"longitude": "0.1278"
},
"vCards": {
"0": "BEGIN:VCARD..."
},
"_data": {
},
"replyTo": {
"id": "AAAAAAAAAAAAAAAAAAAA",
"participant": "11111111111@c.us",
"body": "Hello!",
"_data": {
}
}
},
"me": {
"id": "11111111111@c.us",
"lid": "123123@lid",
"pushName": "Wawp Instance"
}
}Command Palette
Search for a command to run...