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 fromMe = data?.key?.fromMe;
|
||||
|
||||
// Ignorar mensajes enviados por el bot mismo
|
||||
if (fromMe) {
|
||||
return NextResponse.json({ success: true, message: 'Ignored bot message' }, { status: 200 });
|
||||
const messageData = data?.message || {};
|
||||
const rawText = messageData.conversation || messageData.extendedTextMessage?.text || messageData.imageMessage?.caption || messageData.videoMessage?.caption || '';
|
||||
|
||||
// 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
|
||||
@ -49,10 +53,8 @@ export async function POST(req: Request) {
|
||||
// return NextResponse.json({ success: true, message: 'Ignored other chat' }, { status: 200 });
|
||||
// }
|
||||
|
||||
const messageData = data?.message || {};
|
||||
|
||||
// Extraer texto del mensaje
|
||||
const text = messageData.conversation || messageData.extendedTextMessage?.text || messageData.imageMessage?.caption || messageData.videoMessage?.caption || '';
|
||||
// Extraer texto del mensaje (ya guardado en rawText, lo mantenemos como text para retrocompatibilidad interna)
|
||||
const text = rawText;
|
||||
const lowerText = text.trim().toLowerCase();
|
||||
|
||||
const contextInfo = messageData.extendedTextMessage?.contextInfo;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user