Session Lifecycle

Documentation on Wawp's Session Lifecycle — how to provision, start, and maintain reliable WhatsApp instances.

Best practices

  • Use webhooks for real-time status updates instead of aggressive polling.

  • Implement a 'Retry' button in your UI that triggers the [/v2/session/restart](/v2/session/restart) endpoint.

  • Monitor the 'STARTING' state duration; if it persists beyond 60s, trigger a manual restart.

  • Store the 'instance_id' and 'server_name' in your database for faster troubleshooting.

  • Automatically trigger a [/v2/session/start](/v2/session/start) if you detect a user trying to send a message while the status is STOPPED.

  • Ensure your application handles the 'FAILED' status gracefully by notifying the administrator.

The Lifecycle of a Session: Architectural Mastery

Wawp’s session API is not just a collection of endpoints; it is a sophisticated orchestration layer designed to make WhatsApp automation reliable, secure, and infinitely scalable. In this guide, we deep-dive into the "Operational Philosophy" behind instance management and how to build production-grade workflows.


🏗️ Operational Philosophy: The "Lazy & Warm" Approach

To maintain 99.9% uptime and provide a premium user experience, we recommend a lifecycle strategy we call "Lazy Provisioning & Warm Booting."

1. Lazy Provisioning (Creation)

Don't create sessions in bulk for users who might never use the service. Provision an instance_id using the create endpoint only at the moment a user decides to connect. This keeps your database clean and ensures your quota is allocated to active customers.

2. Warm Booting (Starting)

Starting a session boots a dedicated engine. If your application detects a user has logged into your dashboard, verify their session status via info. If they are STOPPED, trigger a start call in the background. By the time they navigate to the "WhatsApp QR" page, the engine is already "warm," reducing wait times by up to 15 seconds.


🔄 Status Transitions: Decoding the State Machine

Understanding the movement between states is critical for building a responsive UI.

StatusTechnical ContextRecommended UI Action
STOPPEDThe engine is not running. No resources are consumed.Show a "Power On" or "Start" button.
STARTINGThe engine is booting and connecting to the WhatsApp bridge.Show a "Connecting..." spinner or progress bar.
SCAN_QR_CODEThe engine is active but unauthenticated.Display the QR Code or a Pairing Code input.
WORKINGAuthenticated and ready for all operations.Show "Connected" status and enable messaging features.
FAILEDAn unrecoverable internal error occurred.Show a "Troubleshoot" or "Restart" button.

🌐 Reliability Engineering with Webhooks

While polling the info endpoint is useful for simple scripts, production environments must use webhooks.

Why Webhooks?

  • Instant Response: Receive a SCAN_QR_CODE event the millisecond a session is disconnected or requires re-authentication.
  • Resource Efficiency: Eliminates the need for aggressive polling loops that waste network bandwidth.
  • Audit Trails: Log status changes in your own database to analyze session stability over time.

🛠️ Advanced Orchestration Patterns

The "Auto-Heal" Pattern

If a status webhook returns FAILED, your system should wait 30 seconds and then automatically call /v2/session/restart. Most failures are transient (network drops, port collisions) and can be resolved by a clean restart without user intervention.

The "Identity Verification" Pattern

Once a status hits WORKING, your automation should immediately call /v2/session/me. Compare the returned WhatsApp JID with the record in your database. If a user scans their personal phone instead of their business phone, you can detect this instantly and notify them of the mistake.


🛡️ Security & Performance Best Practices

  • Token Rotation: Treat your access_token like a password. If a developer leaves or a key is leaked, use our security portal to rotate it immediately.
  • Rate Limiting Intelligence: Wawp handles internal rate limits for you, but calling /session/start for the same instance many times in a few seconds will result in a 429 error. Implement an exponential backoff strategy in your code.
  • Scheduled Maintenance: For sessions that stay active for months, a weekly restart during low-traffic hours can help clear memory and maintain peak performance.

Troubleshooting Guide

Why is my session stuck in "STARTING"?

This usually happens if the underlying high-performance node is under heavy load or if there's a delay in the WhatsApp handshake. If it lasts longer than 60 seconds, trigger a manual restart.

My session returns "LOGOUT" via Webhook

The user has likely used their mobile device's "Linked Devices" settings to manually disconnect the session. You should clear their connection state in your database and redirect them to scan the QR code again.


Summary of Operations:

  • create: Allocate instance resources.
  • start: Power on the engine.
  • stop: Hibernate the engine to save resources.
  • info: Real-time health monitoring.
  • me: Profile and identity verification.
  • logout: Cleanly unpair the device.
  • restart: Troubleshooting and maintenance.
  • delete: Complete data destruction.

Command Palette

Search for a command to run...