Skip to content

[WEBJS] [Chatwoot App] /api/contacts/check-exists fails with phone numbers containing '+' prefix when called from Chatwoot app #1475

@alessandrovolpin

Description

@alessandrovolpin

Bug Report: /api/contacts/check-exists fails with phone numbers containing '+' prefix when called from Chatwoot App

Environment

  • WAHA Version: 2025.9.8
  • Engine: WEBJS
  • Tier: PLUS
  • Browser: Chromium 141.0.7390.54 (Debian GNU/Linux 12 bookworm)
  • Integration: Chatwoot App enabled
  • Session: WhatsApp session authenticated and connected

Description

The /api/contacts/check-exists endpoint consistently returns a 500 error when the phone number parameter includes the international prefix + (e.g., +39xxxxxxxxxx). This issue occurs specifically when messages are sent from the Chatwoot interface, which automatically formats phone numbers with the + prefix according to international standards.

Steps to Reproduce

  1. Enable Chatwoot App integration in WAHA
  2. Configure a Chatwoot inbox connected to a WAHA WhatsApp session
  3. Send a message from Chatwoot interface to a number ( with or without + )
  4. Chatwoot App calls /api/contacts/check-exists?phone=+39xxxxxxxxxx&session=SESSION_NAME
  5. The endpoint fails with 500 error

Expected Behavior

The endpoint should successfully validate phone numbers with international prefix +, returning:

{
  "numberExists": true,
  "chatId": "[email protected]"
}

OR

CHATWOOT App integration should convert the number removing the +

Actual Behavior

The endpoint returns a 500 error with a cryptic Puppeteer evaluation error:

{
  "statusCode": 500,
  "timestamp": "2025-10-09T09:42:20.532Z",
  "exception": {
    "message": "b",
    "name": "b",
    "stack": "b: b\n    at #evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:391:56)\n    at async ExecutionContext.evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:277:16)\n    at async IsolatedWorld.evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/IsolatedWorld.js:100:16)\n    at async CdpFrame.evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Frame.js:364:20)\n    at async CdpPage.evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Page.js:822:20)\n    at async WPage.evaluate (/app/dist/core/engines/webjs/WPage.js:13:20)\n    at async WebjsClientPlus.getNumberId (/app/node_modules/whatsapp-web.js/src/Client.js:1583:16)\n    at async WhatsappSessionWebJSPlus.checkNumberStatus (/app/dist/core/engines/webjs/session.webjs.core.js:364:24)"
  },
  "request": {
    "path": "/api/contacts/check-exists?phone=%2B39xxxxxxxxxx&session=SESSION_NAME",
    "method": "GET",
    "query": {
      "phone": "+39xxxxxxx",
      "session": "SESSION_NAME"
    }
  },
  "version": {
    "version": "2025.9.8",
    "engine": "WEBJS",
    "tier": "PLUS",
    "browser": "/usr/bin/chromium"
  }
}

Test Results

❌ WITH + prefix (FAILS):

curl -X GET "http://localhost:3000/api/contacts/check-exists?phone=%2B39xxxxxxxxxx&session=SESSION_NAME" \
  -H "X-Api-Key: YOUR_API_KEY"

Result: 500 error with "b: b" Puppeteer evaluation error

✅ WITHOUT + prefix (WORKS):

curl -X GET "http://localhost:3000/api/contacts/check-exists?phone=39xxxxxxxxxx&session=SESSION_NAME" \
  -H "X-Api-Key: YOUR_API_KEY"

Result:

{"numberExists":true,"chatId":"[email protected]"}

Relevant Logs

[10:42:16.897] INFO (48): GET /api/contacts/check-exists?phone=%2B39xxxxxxxxxx&session=SESSION_NAME  {"app":"ChatWoot","component":"ChatWootInboxMessageCreatedConsumer","jobId":"7"}

[10:42:16.920] ERROR (48): GET 500 /api/contacts/check-exists {"statusCode":500,"timestamp":"2025-10-09T09:42:16.919Z","exception":{"message":"b","name":"b","stack":"b: b\n    at #evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:391:56)...

[10:42:20.535] ERROR (48): API Error: Request failed with status code 500
Data: {
  "statusCode": 500,
  "timestamp": "2025-10-09T09:42:20.532Z",
  "exception": {
    "message": "b",
    "name": "b",
    "stack": "b: b\n    at #evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:391:56)...

Impact

This bug breaks the Chatwoot integration because:

  1. Chatwoot automatically formats phone numbers with + prefix (international standard)
  2. Every message sent DIRECTLY TO A NUMBER from Chatwoot interface triggers this error
  3. The error causes the Chatwoot consumer to fail processing messages
  4. Messages cannot be properly delivered through the Chatwoot → WAHA → WhatsApp flow

Root Cause Analysis

The error "b: b" suggests that:

  1. The phone number with + is being passed to Puppeteer's page.evaluate()
  2. The + character is likely causing a JavaScript evaluation/parsing error in the WhatsApp Web context
  3. The error is occurring in WebjsClientPlus.getNumberId() when trying to validate the number format

Workaround

Currently, the only workaround is to modify the calling code to strip the + prefix before making the API call. However, this is not feasible when using the Chatwoot App integration, as it's internal to WAHA.

Suggested Fix

The endpoint should sanitize the phone number parameter by:

  1. Removing the + prefix before processing
  2. Or properly escaping/encoding the + when passing to Puppeteer evaluation context
  3. Or validating and normalizing phone number format in WhatsappSessionWebJSPlus.checkNumberStatus()

This should be handled in the WAHA codebase at:

  • /app/dist/core/engines/webjs/session.webjs.core.js:364 (before calling checkNumberStatus)
  • Or in the ChatWoot consumer before calling the API endpoint

Additional Context

  • The issue is reproducible 100% of the time
  • Session remains connected and authenticated; the issue is purely with the contact validation endpoint
  • Other API endpoints work correctly

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions