WhiskeySockets / Baileys

Lightweight full-featured typescript/javascript WhatsApp Web API
https://baileys.whiskeysockets.io/
MIT License
3.88k stars 1.33k forks source link

Error 428 - Precondition Required[BUG] #445

Open Moneki97 opened 1 year ago

Moneki97 commented 1 year ago

Describe the bug When trying to send an image I get error 428.

To Reproduce Steps to reproduce the behavior:

  1. Created a new connection
  2. Schedule a cron-job every 12 hours, to run an image sending function

Expected behavior Send the image.

Environment (please complete the following information):

Additional context My function is: image

The error is: image

kyraex commented 1 year ago

For this type of logout reason you need to restart the socket

Moneki97 commented 1 year ago

For this type of logout reason you need to restart the socket

I handle reconnection on update event: Screenshot_20231016-215211_GitHub~2.png

makanSukros commented 1 year ago

Nothing to do, the solution is just to restart your socket connection

Moneki97 commented 1 year ago

Nothing to do, the solution is just to restart your socket connection

As I would do it?

okfull commented 1 year ago

This happens when you spend hours without receiving any events, for example: without receiving messages for a long time

AKAZAMD commented 1 year ago

Ini terjadi ketika Anda menghabiskan waktu berjam-jam tanpa menerima peristiwa apa pun, misalnya: tanpa menerima pesan dalam waktu lama

hello bro, what if the status code is 408 when using conn.profilePictureUrl

DiegoCarver commented 1 year ago

Hello bro, could you clarify how you manage/schedule these restarts in your code to avoid this 428 error?

Nothing to do, the solution is just to restart your socket connection

Moneki97 commented 12 months ago

Nada que hacer, la solución es simplemente reiniciar la conexión del socket.

¿Cómo manejamos el reinicio con el error 428?

xadminx commented 11 months ago

Same problem.

weershft commented 11 months ago

Same problem... But, my instances stay in the half 3/4 days connected, and then show error 428 (connection closed)...

I would liked stay connected for the 1 month or plus...

whatsera commented 10 months ago

does any one have a solution for it?

weershft commented 10 months ago

does any one have a solution for it?

federicocm93 commented 10 months ago

having the same problem but with the difference that the first sent message breaks it, after a restart it stays connected (I haven't tested for how long)

weershft commented 10 months ago

@Moneki97 @kyraex does any one have a solution for it?

sumithemmadi commented 10 months ago

setting syncFullHistory: false in makeWASocket and waited for 30 seconds before sending a first message resolved my issue.

  setTimeout(async () => {
    const jid = '919912345678@s.whatsapp.net';

    await socket.presenceSubscribe(jid);
    await delay(500);

    await socket.sendPresenceUpdate('composing', jid);
    await delay(2000);

    await socket.sendPresenceUpdate('paused', jid);
    await socket.sendMessage(jid, { text: 'Hello from Whatsapp' });
  }, 30000);
weershft commented 10 months ago

@sumithemmadi Hello. Did you solve this problem?

smukideejeah commented 2 weeks ago

En mi caso, con tan solo quitar return false en el evento messages.upsert resolvió mi problema (mi error)

antes:

socket.ev.on("messages.upsert", async m => {

        const msg = m.messages[0];
        let message = msg.message?.conversation;
        if(message == "") message = msg.message?.extendedTextMessage?.text;

        if(msg.key.fromMe){
            let info = await ai.assistants.getInfo();
            if(!!info){
                if(new RegExp("^"+info.start+"$", "i").test(message!)){
                    const forbidden = await orm.waForbiddenNumbers.findUnique({where: {phone}});
                    if(!!forbidden) return false;
                    await ai.threads.enable(msg.key.remoteJid!);
                }
            }
        }else{
            if(!message) return false;
            const aiThread = await ai.threads.get(msg.key.remoteJid!);
            if(!aiThread) return false;
            if(!aiThread.info.enabled) return false;
        }
    });

Después

socket.ev.on("messages.upsert", async m => {

        const msg = m.messages[0];
        let message = msg.message?.conversation;
        if(message == "") message = msg.message?.extendedTextMessage?.text;

        if(msg.key.fromMe){
            let info = await ai.assistants.getInfo();
            if(!!info){
                if(new RegExp("^"+info.start+"$", "i").test(message!)){
                    const forbidden = await orm.waForbiddenNumbers.findUnique({where: {phone}});
                    if(!!forbidden) return;
                    await ai.threads.enable(msg.key.remoteJid!);
                }
            }
        }else{
            if(!message) return;
            const aiThread = await ai.threads.get(msg.key.remoteJid!);
            if(!aiThread) return;
            if(!aiThread.info.enabled) return;
        }
    });

No sé si sea tu caso