From 32610ebfd13824708f2e25adfdcaf99edecae27f Mon Sep 17 00:00:00 2001 From: bipproduction Date: Thu, 5 Feb 2026 16:35:28 +0800 Subject: [PATCH] Support @lid format in WhatsApp routes and relax number validation --- src/server/routes/wa_route.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/server/routes/wa_route.ts b/src/server/routes/wa_route.ts index 299f9c6..5d51e43 100644 --- a/src/server/routes/wa_route.ts +++ b/src/server/routes/wa_route.ts @@ -4,6 +4,11 @@ import _ from "lodash"; import mime from "mime-types"; import { MessageMedia } from "whatsapp-web.js"; +const formatJid = (num: string) => { + if (num.includes("@")) return num; + return `${num}@c.us`; +}; + const WaRoute = new Elysia({ prefix: "/wa", tags: ["WhatsApp"] @@ -66,7 +71,7 @@ const WaRoute = new Elysia({ } - const chat = await client.getChatById(`${body.number}@c.us`); + const chat = await client.getChatById(formatJid(body.number)); await chat.sendMessage(body.text); return { @@ -96,7 +101,7 @@ const WaRoute = new Elysia({ try { const { number, caption, media } = body; - const jid = `${number}@c.us`; + const jid = formatJid(number); // Siapkan data media const { data, filename, mimetype } = media; @@ -138,7 +143,7 @@ const WaRoute = new Elysia({ }, { body: t.Object({ - number: t.String({ minLength: 10, maxLength: 15, examples: ["6281234567890"] }), + number: t.String({ minLength: 5, maxLength: 50, examples: ["6281234567890", "1234567890@lid"] }), caption: t.Optional(t.String({ maxLength: 255, examples: ["Hello World"] })), media: t.Object({ data: t.String({ examples: ["iVBORw0KGgoAAAANSUhEUgAAAAEAAAABC..."], description: "Base64 encoded media data" }), @@ -179,14 +184,14 @@ const WaRoute = new Elysia({ }; } - const chat = await state.client.sendMessage(`${nom}@c.us`, text); + const chat = await state.client.sendMessage(formatJid(nom as string), text as string); return { message: "✅ Message sent", info: chat.id, }; }, { query: t.Object({ - nom: t.String({ minLength: 10, maxLength: 15, examples: ["6281234567890"] }), + nom: t.String({ minLength: 5, maxLength: 50, examples: ["6281234567890", "1234567890@lid"] }), text: t.String({ examples: ["Hello World"] }), }), detail: { @@ -221,7 +226,7 @@ const WaRoute = new Elysia({ }; } - const chat = await state.client.getChatById(`${nom}@c.us`); + const chat = await state.client.getChatById(formatJid(nom as string)); // await chat.sendSeen(); return { message: "✅ Seen sent", @@ -229,7 +234,7 @@ const WaRoute = new Elysia({ }; }, { query: t.Object({ - nom: t.String({ minLength: 10, maxLength: 15, examples: ["6281234567890"] }), + nom: t.String({ minLength: 5, maxLength: 50, examples: ["6281234567890", "1234567890@lid"] }), }), detail: { summary: "Send seen to WhatsApp", @@ -263,7 +268,7 @@ const WaRoute = new Elysia({ }; } - const chat = await state.client.getChatById(`${nom}@c.us`); + const chat = await state.client.getChatById(formatJid(nom as string)); await chat.sendStateTyping(); return { message: "✅ Typing sent", @@ -271,7 +276,7 @@ const WaRoute = new Elysia({ }; }, { query: t.Object({ - nom: t.String({ minLength: 10, maxLength: 15, examples: ["6281234567890"] }), + nom: t.String({ minLength: 5, maxLength: 50, examples: ["6281234567890", "1234567890@lid"] }), }), detail: { summary: "Send typing to WhatsApp",