fix(webhook): allow self-messaging from admin phone
This commit is contained in:
parent
694b320d76
commit
77fadb03be
@ -39,9 +39,13 @@ export async function POST(req: Request) {
|
|||||||
const remoteJid = data?.key?.remoteJid;
|
const remoteJid = data?.key?.remoteJid;
|
||||||
const fromMe = data?.key?.fromMe;
|
const fromMe = data?.key?.fromMe;
|
||||||
|
|
||||||
// Ignorar mensajes enviados por el bot mismo
|
const messageData = data?.message || {};
|
||||||
if (fromMe) {
|
const rawText = messageData.conversation || messageData.extendedTextMessage?.text || messageData.imageMessage?.caption || messageData.videoMessage?.caption || '';
|
||||||
return NextResponse.json({ success: true, message: 'Ignored bot message' }, { status: 200 });
|
|
||||||
|
// Ignorar mensajes generados por el bot para evitar bucle infinito,
|
||||||
|
// pero permitir tests que el administrador envíe desde el mismo celular del bot.
|
||||||
|
if (fromMe && (rawText.includes('📰 *Publicación Procesada') || rawText.includes('✅ La publicación ha sido aprobada') || rawText.includes('❌ Error al publicar'))) {
|
||||||
|
return NextResponse.json({ success: true, message: 'Ignored bot self-message loop' }, { status: 200 });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recomendado: filtrar por el grupo específico
|
// Recomendado: filtrar por el grupo específico
|
||||||
@ -49,10 +53,8 @@ export async function POST(req: Request) {
|
|||||||
// return NextResponse.json({ success: true, message: 'Ignored other chat' }, { status: 200 });
|
// return NextResponse.json({ success: true, message: 'Ignored other chat' }, { status: 200 });
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const messageData = data?.message || {};
|
// Extraer texto del mensaje (ya guardado en rawText, lo mantenemos como text para retrocompatibilidad interna)
|
||||||
|
const text = rawText;
|
||||||
// Extraer texto del mensaje
|
|
||||||
const text = messageData.conversation || messageData.extendedTextMessage?.text || messageData.imageMessage?.caption || messageData.videoMessage?.caption || '';
|
|
||||||
const lowerText = text.trim().toLowerCase();
|
const lowerText = text.trim().toLowerCase();
|
||||||
|
|
||||||
const contextInfo = messageData.extendedTextMessage?.contextInfo;
|
const contextInfo = messageData.extendedTextMessage?.contextInfo;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user