Skip to content

clawdis send command fails for WhatsApp group JIDs #45

@arun-8687

Description

@arun-8687

Description
The clawdis send command fails to send messages to WhatsApp groups. Group JIDs are incorrectly converted to individual chat format, causing "gateway timeout" or silent failures.

Reproduction Steps

  • Start Clawdis gateway with WhatsApp connected
  • Run: pnpm run clawdis send --to "123456789-987654321@g.us" --message "Test"
  • Observe gateway timeout or incorrect recipient

Expected Behavior
Message should be sent to the group chat with JID 123456789-987654321@g.us

Actual Behavior
The group JID is converted to an individual chat format:

Input: 91xxx-xyz@g.us
Sent to: 91xxxxyz@s.whatsapp.net (incorrect!)
The - is stripped and @g.us is changed to @s.whatsapp.net, causing the message to fail.

Root Cause
The toWhatsappJid() function in src/utils.ts unconditionally normalizes all inputs as phone numbers and appends @s.whatsapp.net, ignoring existing JID formats.

Similarly, sendMessage() and sendComposingTo() in src/web/inbound.ts always construct JIDs with @s.whatsapp.net.

Fix
Check if the input already contains @ before transforming:

src/utils.ts:

typescript

export function toWhatsappJid(number: string): string {
  // Preserve group JIDs (@g.us) or any existing JID format
  if (number.includes("@")) {
    return number;
  }
  const e164 = normalizeE164(number);
  const digits = e164.replace(/\D/g, "");
  return `${digits}@s.whatsapp.net`;
}

src/web/inbound.ts

typescript
const jid = to.includes("@") ? to : ${to.replace(/^\+/, "")}@s.whatsapp.net;

Environment

  • OS: Ubuntu 24.04
  • Node: v22.21.1
  • Clawdis: v2.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions