0
 function readingFirebase(ref){
   ref.once('value').then(function(codes){
    
   
         codes.forEach  ( async function(nom){
             
            console.log('entrando a nombre de cada numero')
            await sleep(5000)
            const number = nom.val()['Celular'];                
            var chatId = number.toString().replace('+','') + "@c.us";
            var chatSinEspacios=chatId.replace(/\s/g,"")
            var chatSinEspaciosniComillas = chatSinEspacios.replaceAll('"',"")  
            client.sendMessage(chatSinEspaciosniComillas,mensajeAleman)               
            console.log('message sent to' ,chatSinEspaciosniComillas)
            ['Celular'].concat('@c.us')                   
                
        }) 
      })    
    }

 function sleep(ms) {
 return new Promise(resolve => setTimeout(resolve, ms));

}

 readingFirebase(address/X)

The reading from the database is correct what is wrong is when I use the await sleep in the forEach after one round it stops sending just one message. As I need to send several messages to whatsapp numbers if they are too many Whatsapp blocks the number so I need at least a solution to send messages after some seconds for Whatsapp not to detect them and block them

0 Answers0