feat(whatsapp): add configurable media max size
- Add whatsapp.mediaMaxMb config option (default: 50MB) - Increases default from previous 5MB hardcoded limit - Allows receiving larger documents/media files - Per-account override via whatsapp.accounts.*.mediaMaxMb Fixes #<issue-number> (if applicable)
This commit is contained in:
committed by
Peter Steinberger
parent
da2323f80e
commit
3026367c1b
@@ -131,6 +131,8 @@ export type WhatsAppConfig = {
|
|||||||
groupPolicy?: GroupPolicy;
|
groupPolicy?: GroupPolicy;
|
||||||
/** Outbound text chunk size (chars). Default: 4000. */
|
/** Outbound text chunk size (chars). Default: 4000. */
|
||||||
textChunkLimit?: number;
|
textChunkLimit?: number;
|
||||||
|
/** Maximum media file size in MB. Default: 50. */
|
||||||
|
mediaMaxMb?: number;
|
||||||
/** Disable block streaming for this account. */
|
/** Disable block streaming for this account. */
|
||||||
blockStreaming?: boolean;
|
blockStreaming?: boolean;
|
||||||
/** Merge streamed block replies before sending. */
|
/** Merge streamed block replies before sending. */
|
||||||
@@ -160,6 +162,7 @@ export type WhatsAppAccountConfig = {
|
|||||||
groupAllowFrom?: string[];
|
groupAllowFrom?: string[];
|
||||||
groupPolicy?: GroupPolicy;
|
groupPolicy?: GroupPolicy;
|
||||||
textChunkLimit?: number;
|
textChunkLimit?: number;
|
||||||
|
mediaMaxMb?: number;
|
||||||
blockStreaming?: boolean;
|
blockStreaming?: boolean;
|
||||||
/** Merge streamed block replies before sending. */
|
/** Merge streamed block replies before sending. */
|
||||||
blockStreamingCoalesce?: BlockStreamingCoalesceConfig;
|
blockStreamingCoalesce?: BlockStreamingCoalesceConfig;
|
||||||
|
|||||||
@@ -1227,6 +1227,7 @@ export const ClawdbotSchema = z.object({
|
|||||||
groupAllowFrom: z.array(z.string()).optional(),
|
groupAllowFrom: z.array(z.string()).optional(),
|
||||||
groupPolicy: GroupPolicySchema.optional().default("open"),
|
groupPolicy: GroupPolicySchema.optional().default("open"),
|
||||||
textChunkLimit: z.number().int().positive().optional(),
|
textChunkLimit: z.number().int().positive().optional(),
|
||||||
|
mediaMaxMb: z.number().int().positive().optional(),
|
||||||
blockStreaming: z.boolean().optional(),
|
blockStreaming: z.boolean().optional(),
|
||||||
blockStreamingCoalesce: BlockStreamingCoalesceSchema.optional(),
|
blockStreamingCoalesce: BlockStreamingCoalesceSchema.optional(),
|
||||||
groups: z
|
groups: z
|
||||||
@@ -1262,6 +1263,7 @@ export const ClawdbotSchema = z.object({
|
|||||||
groupAllowFrom: z.array(z.string()).optional(),
|
groupAllowFrom: z.array(z.string()).optional(),
|
||||||
groupPolicy: GroupPolicySchema.optional().default("open"),
|
groupPolicy: GroupPolicySchema.optional().default("open"),
|
||||||
textChunkLimit: z.number().int().positive().optional(),
|
textChunkLimit: z.number().int().positive().optional(),
|
||||||
|
mediaMaxMb: z.number().int().positive().optional().default(50),
|
||||||
blockStreaming: z.boolean().optional(),
|
blockStreaming: z.boolean().optional(),
|
||||||
blockStreamingCoalesce: BlockStreamingCoalesceSchema.optional(),
|
blockStreamingCoalesce: BlockStreamingCoalesceSchema.optional(),
|
||||||
actions: z
|
actions: z
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ export async function monitorWebInbox(options: {
|
|||||||
accountId: string;
|
accountId: string;
|
||||||
authDir: string;
|
authDir: string;
|
||||||
onMessage: (msg: WebInboundMessage) => Promise<void>;
|
onMessage: (msg: WebInboundMessage) => Promise<void>;
|
||||||
|
mediaMaxMb?: number;
|
||||||
}) {
|
}) {
|
||||||
const inboundLogger = getChildLogger({ module: "web-inbound" });
|
const inboundLogger = getChildLogger({ module: "web-inbound" });
|
||||||
const inboundConsoleLog = createSubsystemLogger(
|
const inboundConsoleLog = createSubsystemLogger(
|
||||||
@@ -375,9 +376,12 @@ export async function monitorWebInbox(options: {
|
|||||||
try {
|
try {
|
||||||
const inboundMedia = await downloadInboundMedia(msg, sock);
|
const inboundMedia = await downloadInboundMedia(msg, sock);
|
||||||
if (inboundMedia) {
|
if (inboundMedia) {
|
||||||
|
const maxBytes = (options.mediaMaxMb ?? 50) * 1024 * 1024;
|
||||||
const saved = await saveMediaBuffer(
|
const saved = await saveMediaBuffer(
|
||||||
inboundMedia.buffer,
|
inboundMedia.buffer,
|
||||||
inboundMedia.mimetype,
|
inboundMedia.mimetype,
|
||||||
|
"inbound",
|
||||||
|
maxBytes,
|
||||||
);
|
);
|
||||||
mediaPath = saved.path;
|
mediaPath = saved.path;
|
||||||
mediaType = inboundMedia.mimetype;
|
mediaType = inboundMedia.mimetype;
|
||||||
|
|||||||
Reference in New Issue
Block a user