Skip to content

WhatsApp mediaMaxMb Config Ignored - Falls Back to Hardcoded Constants #7847

@alexpolonsky

Description

@alexpolonsky

Summary

The mediaMaxMb configuration option defined in WhatsApp account schema is completely ignored during media processing. Despite being configurable at multiple levels, the code always falls back to hardcoded constants.

Details

Schema Defines the Option (But It's Never Used)

File: dist/config/zod-schema.providers-whatsapp.js:29

mediaMaxMb: z.number().int().positive().optional(),

This allows users to configure:

channels:
  whatsapp:
    accounts:
      default:
        mediaMaxMb: 64  # This is completely ignored

The Code Path That Ignores It

File: dist/infra/outbound/message-action-runner.js:102-140

The resolveAttachmentMaxBytes function:

function resolveAttachmentMaxBytes(params) {
    const fallback = params.cfg.agents?.defaults?.mediaMaxMb;
    if (params.channel !== "bluebubbles") {
        // WhatsApp path: only reads agents.defaults, ignores channel-specific config
        return typeof fallback === "number" ? fallback * 1024 * 1024 : undefined;
    }
    // Only bluebubbles gets the full config resolution (channel → account → defaults)
    // ...
}

For WhatsApp:

  • ❌ Ignores channels.whatsapp.accounts.<id>.mediaMaxMb
  • ❌ Ignores channels.whatsapp.mediaMaxMb
  • ⚠️ Only reads agents.defaults.mediaMaxMb (which may still be ignored downstream)

Hardcoded Constants Override Everything

File: dist/media/constants.js:1-4

export const MAX_IMAGE_BYTES = 6 * 1024 * 1024; // 6MB
export const MAX_AUDIO_BYTES = 16 * 1024 * 1024; // 16MB
export const MAX_VIDEO_BYTES = 16 * 1024 * 1024; // 16MB
export const MAX_DOCUMENT_BYTES = 100 * 1024 * 1024; // 100MB

These are used by maxBytesForKind() which is called when no maxBytes parameter is passed.

Note on Actual WhatsApp Limits

The hardcoded values are actually correct for WhatsApp Cloud/Web API:

  • Video/Audio: 16MB
  • Images: 5MB
  • Documents: 100MB

(Source: AWS WhatsApp Media Types)

However, the consumer app allows sending videos as documents (up to 100MB), and WhatsApp announced 2GB file sharing support. The config option should work regardless.

Expected Behavior

  1. channels.whatsapp.accounts.<id>.mediaMaxMb should be read and applied
  2. It should fall back to channels.whatsapp.mediaMaxMb
  3. Then fall back to agents.defaults.mediaMaxMb
  4. Finally fall back to the hardcoded defaults

Suggested Fix

Update resolveAttachmentMaxBytes to handle WhatsApp the same way it handles BlueBubbles:

function resolveAttachmentMaxBytes(params) {
    const fallback = params.cfg.agents?.defaults?.mediaMaxMb;
    
    // Get channel-specific config
    const channelCfg = params.cfg.channels?.[params.channel];
    const channelObj = channelCfg && typeof channelCfg === "object" ? channelCfg : undefined;
    const channelMediaMax = typeof channelObj?.mediaMaxMb === "number" ? channelObj.mediaMaxMb : undefined;
    
    // Get account-specific config
    const accountId = typeof params.accountId === "string" ? params.accountId.trim() : "";
    const accountsObj = channelObj?.accounts && typeof channelObj.accounts === "object"
        ? channelObj.accounts : undefined;
    const accountCfg = accountId && accountsObj ? accountsObj[accountId] : undefined;
    const accountMediaMax = accountCfg && typeof accountCfg === "object"
        ? accountCfg.mediaMaxMb : undefined;
    
    // Priority: account → channel → defaults
    const limitMb = accountMediaMax ?? channelMediaMax ?? fallback;
    return typeof limitMb === "number" ? limitMb * 1024 * 1024 : undefined;
}

Environment

  • OpenClaw Version: 2026.1.29
  • OS: macOS Darwin 24.5.0 (arm64)
  • Node: v24.13.0

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions