Session Status Change
This event is triggered when the session status changes (e.g., from WORKING to STOPPED).
Best practices
Store the 'WORKING' status in your database to prevent sending messages to an offline instance.
Notify administrators immediately if a session moves to 'SCAN_QR_CODE' status.
Use the 'session' field to identify which account changed status.
The Engine Heartbeat: Connectivity Governance and Instance Lifecycle
In the orchestration of high-scale enterprise messaging, connectivity is not a binary state—it is a dynamic lifecycle. The Session Status Change webhook is the definitive signal that informs your infrastructure of the health, availability, and authentication status of your underlying WhatsApp engine. It is the "Heartbeat Monitor" of your community and a non-negotiable component of any resilient communication strategy.
This guide provides a strategic overview of the session lifecycle, exploring how to use status events to build a proactive, self-healing architecture that maximizes uptime and minimizes human intervention.
🏗️ Architectural Philosophy: Status as a Prerequisite for Action
To build a reliable WhatsApp integration, your system must operate with "Connectivity Awareness." Attempting to send a high-priority message to a disconnected instance is a waste of compute resources and a risk to business continuity. The [session.status] webhook transforms your system from a "Hopeful Messenger" into a Strategic Governor.
1. The State Machine of the WhatsApp Engine
The Wawp platform manages a complex state machine for every instance. Each status value represents a specific operational phase:
- WORKING (The Operational Goal): This is the only state where the engine can perform full read/write operations. A strategic architecture uses this status as a "Green Light" for its outbound message queues. When an instance moves away from this state, your system should automatically "Pause" its outbound traffic to prevent delivery failures and quota waste.
- SCAN_QR_CODE (The Gateway to Identity): This is a high-priority event signaling that the instance is unauthenticated. By reacting to this webhook, your system can trigger an automated notification to an administrator's internal dashboard or even send a specialized email containing the QR code for instant re-linking.
- DISCONNECTED (The Critical Alert): This state indicates that the mobile device has been manually unlinked or has lost its network handshake for a prolonged period. This is an "Emergency Stop" signal that requires immediate investigation to ensure customer messages aren't being lost.
2. Event-Driven Health Monitoring
Relying on "Periodic Heartbeat Checks" is an inefficient way to monitor connectivity. By using the Session Status webhook, you move to a "Reactive Monitoring" model. Your server is informed of a failure the moment it happens, allowing for a Mean Time to Recovery (MTTR) measured in milliseconds rather than minutes.
🚀 Strategic Use Cases: Powering Resilient Architectures
Mastering the session lifecycle allows you to build systems that are "Self-Aware" and robust.
1. Proactive Downtime Mitigation and Failover
In an enterprise environment managing multiple WhatsApp Business instances, the Session Status webhook is the foundation of a "Failover Strategy." If Instance A (Sales-UK) moves to a [STOPPED] or [DISCONNECTED] state, your central router can detect this event and automatically redirect incoming queries to Instance B (Sales-Global) or escalate the interaction to an email-based support ticket. This ensures that the customer never experiences a "Dark Chat" where their messages go unanswered.
2. Automated Authentication Workflows
For SaaS providers who offer WhatsApp integration to their own customers, managing authentication at scale is a primary challenge. Use the [SCAN_QR_CODE] event to trigger a "Success UI" on your customer's dashboard. As soon as the webhook arrives, your frontend can automatically display the QR code, wait for the status to transition to STARTING, and finally show a "Connected" checkmark when the status reaches WORKING. This creates a seamless, low-friction "Onboarding Loop" that doesn't require the customer to manually refresh their page.
3. Engine Integrity and Resource Management
The [STARTING] and [STOPPED] statuses are critical for managing your infrastructure's compute costs. If you are running hundreds of instances, you can use these events to track "Engine Cold-Starts." If an instance remains in a [STARTING] state for more than 60 seconds without reaching [WORKING], your system can flag this as a "Stuck Initialization" and programmatically Restart the instance, maintaining the health of your overall instance fleet without manual human intervention.
🛡️ Administrative Mandate: The Guardianship of Connectivity
Effective session management is a method of "Connectivity Insurance."
1. The "Working" State Cache
Every message sending function in your application should perform a "Pre-flight Status Check." By caching the most recent status received from the webhook, your system can immediately reject or queue outbound requests if the instance isn't [WORKING]. This prevents "Failed" message states in your database and allows you to provide immediate feedback to your users: "Our WhatsApp connection is temporarily resetting. Your message will be sent in approximately 30 seconds."
2. Integrity in Multi-Instance Environments
When managing a fleet of instances, the session field in the webhook payload is your primary key. Ensure your monitoring dashboard groups status events by this session ID. A "Status Heatmap" can help you identify platform-wide issues (e.g., if multiple instances move to [DISCONNECTED] at once, it may indicate a larger network or Meta-side connectivity problem) vs. isolated instance issues (e.g., a specific device's battery died).
🛡️ Operational Best Practices: Optimizing Lifecycle Awareness
- Filter for Change (Deduplication): Only trigger your heaviest business logic (like sending an SMS alert to an admin) when the status changes. Do not react to repeated heartbeats of the same status unless your specific architecture requires it.
- The "Human-in-the-Loop" Escalation: For [
SCAN_QR_CODE] events, implement a "Decaying Alert" strategy. Send a notification to the manager. If the status hasn't moved to [WORKING] within 5 minutes, escalate the alert to the IT department. This balances responsiveness with the need to avoid over-alerting for minor network blips. - Logging for Post-Mortems: Store every status transition in a dedicated log table. This allows you to perform "Uptime Audits" and identify patterns in connectivity issues (e.g., Instance C always disconnects at 2 AM on Sundays), which is essential for long-term operational optimization.
⚙️ Engineering Best Practices: The Validation Loop
- Coordinate with QR Generation: When you receive a [
SCAN_QR_CODE] webhook, do not assume the QR image is ready immediately. There is often a several-hundred-millisecond gap between the status change and the new QR being generated by the engine. We recommend a short "Wait and Fetch" strategy before serving the QR image to the user. - Graceful Handling of "Stopped" States: A [
STOPPED] status often indicates a deliberate administrative action. Your system should respect this state and not attempt to "Force-Restart" instances that were intentionally shut down for maintenance or billing reasons. - Validate Webhook Integrity: As with all webhooks, ensure you are verifying the source of the status change notification. Malicious actors could attempt to "Ghost" your system into thinking an instance is offline, triggering unnecessary failover logic and disrupting your business operations.
🎯 Conclusion: Beyond "Connection"—The Architecture of Availability
The Session Status Change Webhook is the "Eye" of your integration. By building an architecture that listens to the heartbeat of the WhatsApp engine, you move your business from a state of "Uncertain Connectivity" to Guaranteed Availability. You build systems that detect their own failures, guide users through authentication, and maintain the integrity of the communication channel through any challenge. In the world of Wawp, status is not just a label; it is the strategic signal that ensures your global conversation never skips a beat.
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": "session.status",
"payload": {
"name": "default",
"status": "STOPPED"
},
"me": {
"id": "11111111111@c.us",
"lid": "123123@lid",
"pushName": "Wawp Instance"
}
}Command Palette
Search for a command to run...