WhiskeySockets / Baileys

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

[BUG] `message.upsert` not listening messages #603

Open SuhailTechInfo opened 5 months ago

SuhailTechInfo commented 5 months ago

BUG

ANY SOLUTION FOR message.upsert NOT WORKING?

WAHTSAPP SOCKET:


# Current Behavior:
* It'll send Confirmation message to user jid, when the **Connection Established** with whatsapp.
* But Not listens any cmds or functions in **message.upsert**

--- 
## I have tried to console:
 - But no responce in log.
Suhail_Md.ev.on('messages.upsert', async chatUpdate => {
     console.log({chatUpdate})  // No responce here
}) 
bobslavtriev commented 5 months ago
sock.ev.on('connection.update', async({ connection, lastDisconnect, receivedPendingNotifications }) => {
    const status = lastDisconnect?.error?.output?.statusCode

    if (connection === 'close'){
        const reason = Object.entries(DisconnectReason).find(i => i[1] === status)?.[0] || 'unknown'

        console.log(`Connection closed, status: ${status} - ${reason}`)

        if (status !== 403 && status !== 401 && status){
            connectToWhatsApp()
        }
    } else if (connection === 'open'){
        console.log('Connected with success')

        if (receivedPendingNotifications && !sock.authState.creds?.myAppStateKeyId){
            sock.ev.flush() // this
        }
    }
})
kyraex commented 5 months ago
sock.ev.on('connection.update', async({ connection, lastDisconnect, receivedPendingNotifications }) => {
  const status = lastDisconnect?.error?.output?.statusCode

  if (connection === 'close'){
      const reason = Object.entries(DisconnectReason).find(i => i[1] === status)?.[0] || 'unknown'

      console.log(`Connection closed, status: ${status} - ${reason}`)

      if (status !== 403 && status !== 401 && status){
          connectToWhatsApp()
      }
  } else if (connection === 'open'){
      console.log('Connected with success')

      if (receivedPendingNotifications && !sock.authState.creds?.myAppStateKeyId){
          sock.ev.flush() // this
      }
  }
})

Do you mind explaining the use of receivedPendingNotifications && !sock.authState.creds?.myAppStateKeyId logic here? Thanks

azudindaem commented 5 months ago
sock.ev.on('connection.update', async({ connection, lastDisconnect, receivedPendingNotifications }) => {
    const status = lastDisconnect?.error?.output?.statusCode

    if (connection === 'close'){
        const reason = Object.entries(DisconnectReason).find(i => i[1] === status)?.[0] || 'unknown'

        console.log(`Connection closed, status: ${status} - ${reason}`)

        if (status !== 403 && status !== 401 && status){
            connectToWhatsApp()
        }
    } else if (connection === 'open'){
        console.log('Connected with success')

        if (receivedPendingNotifications && !sock.authState.creds?.myAppStateKeyId){
            sock.ev.flush() // this
        }
    }
})

Do you mind explaining the use of receivedPendingNotifications && !sock.authState.creds?.myAppStateKeyId logic here? Thanks

If there are received pending notifications and the myAppStateKeyId is not present in creds then flush

SuhailTechInfo commented 5 months ago
sock.ev.on('connection.update', async({ connection, lastDisconnect, receivedPendingNotifications }) => {
  const status = lastDisconnect?.error?.output?.statusCode

  if (connection === 'close'){
      const reason = Object.entries(DisconnectReason).find(i => i[1] === status)?.[0] || 'unknown'

      console.log(`Connection closed, status: ${status} - ${reason}`)

      if (status !== 403 && status !== 401 && status){
          connectToWhatsApp()
      }
  } else if (connection === 'open'){
      console.log('Connected with success')

      if (receivedPendingNotifications && !sock.authState.creds?.myAppStateKeyId){
          sock.ev.flush() // this
      }
  }
})

i have tried to use flush() method. but still same issue,

// OUTPUT {receivedPendingNotifications :undefined}


<br>

- Also `myAppStateKeyId` is present in `creds.json`

## ANY OTHER SOLUTION FOR `message.upsert` NOT WORKING?
SuhailTechInfo commented 5 months ago

because of this problem i can't use official baileys , thanks for your help

Then what's you're using Currently?

ChargerMc commented 5 months ago

This makes the trick


sock.ev.on('connection.update', async({ connection, lastDisconnect, receivedPendingNotifications }) => {
    const status = lastDisconnect?.error?.output?.statusCode

    if (connection === 'close'){
        const reason = Object.entries(DisconnectReason).find(i => i[1] === status)?.[0] || 'unknown'

        console.log(`Connection closed, status: ${status} - ${reason}`)

        if (status !== 403 && status !== 401 && status){
            connectToWhatsApp()
        }
    } else if (connection === 'open'){
        console.log('Connected with success')
            sock.ev.flush() // this
    }
})
enoksaju commented 3 months ago

still issue

drylian commented 1 month ago

i have some problem @SuhailTechInfo you use ipv6?

Araxeus commented 1 week ago

Here are some of my findings:

The following can make an error in your auth file, which allows you to send messages but not receive any:

shouldSyncHistoryMessage(_msg) {
    return false;
},

or / and :

shouldIgnoreJid(jid) {
   return jid !== SPECIFIC_PHONE_NUMBER;
}

Also, on first login (after qr), the phone sync/transmits data to your baileys client, which takes some time - so you shouldn't close the connection straight away, wait atleast 20-30 seconds before closing