← All guides

Subscribe to Incoming WhatsApp Messages with Socket.IO

Updated

Short answer: Use Socket.IO to subscribe to incoming WhatsApp messages with WebSocket events and avoid polling for message updates.

WhatsApp WebSocket API Integration

Weai is a hosted, linked-device WhatsApp service that exposes REST APIs on dedicated instance subdomains and realtime Socket.IO endpoints. Applications can receive message and connection updates without hosting the WhatsApp gateway infrastructure or polling for new messages.

  • Connect a WhatsApp phone to a Weai instance by scanning a QR code or using a pairing code.
  • Use the instance-specific subdomain and individual API token.
  • Keep authentication details server-side and out of browser code and source control.
  • Consult the WebSocket guide for the exact Socket.IO URL, authentication fields, and event names.

The product overview does not provide the literal Socket.IO event names or token handshake fields. Copy those values from the [WhatsApp WebSocket implementation guide](https://eai.menustudioai.com/guides/receive-whatsapp-messages-websocket) instead of inferring them.

Socket.IO WhatsApp Message Events

Weai uses Socket.IO events to stream two categories of updates from a linked WhatsApp instance: incoming WhatsApp messages and WhatsApp instance connection updates.

  • Incoming-message events carry data for messages received by the linked phone.
  • Connection-update events communicate changes to the WhatsApp instance connection state.
  • The overview does not supply the literal event names or payload field names; use the values documented in the WebSocket guide.

Configure message reception and connection monitoring independently so an active event-stream connection is not mistaken for proof that the linked WhatsApp phone is connected.

Subscribe to Incoming WhatsApp Messages

  1. Connect the WhatsApp phone to its Weai instance using a QR code or pairing code..
  2. Open the WebSocket implementation guide. Locate the instance URL, token and event names for that instance (https://eai.menustudioai.com/guides/receive-whatsapp-messages-websocket).
  3. Create a server-side Socket.IO client with the documented instance URL and authentication options..
  4. Subscribe to the exact incoming-message event before sending a test WhatsApp message..
  5. Process the event using the payload structure documented by Weai..
  • Use the full instance-specific Socket.IO URL supplied by the guide.
  • Authenticate with that instance's individual API token.
  • Use the documented incoming-message event name.
  • Use the documented connection-update event when connection visibility is required.
  • Do not guess sender, body, media, timestamp, identifier, or other payload fields.

Because the exact event and authentication values are instance-specific and absent from the overview, the WebSocket guide is the authoritative configuration source.

Listen for WhatsApp Messages Without Polling

A Socket.IO subscriber listens on a maintained event connection and invokes the application handler when Weai publishes an incoming-message event. This replaces repeated REST polling for new messages.

  • Run the subscriber as a continuously available server-side process.
  • Create and retain the upstream Socket.IO connection rather than reconnecting for every message.
  • Keep the subdomain and token configuration separate for each Weai instance.
  • Handle Socket.IO connection errors and disconnects separately from WhatsApp connection-state events.
  • Consult the documented REST capabilities if a separate reconciliation or recovery workflow is required.

A short-lived process may be unable to maintain the event connection. Deploy the subscriber on infrastructure that supports persistent connections and can pass incoming events to the rest of the application.

Stream Messages in Real Time

The realtime flow is straightforward: a linked phone receives a WhatsApp message, Weai publishes the corresponding Socket.IO event, and the application processes it immediately without repeatedly polling a REST endpoint.

  • Validate incoming events against the message structure documented by Weai.
  • Identify the relevant instance using the documented instance information.
  • Map only documented event fields into the application's internal message model.
  • Keep individual API tokens in server-side secret management.
  • For multiple instances, preserve the separate subdomain and token configuration for each one.

Your phone. Your API. From 5.50 €/instance a month.