open-wa / wa-automate-nodejs

💬 🤖 The most reliable tool for chatbots with advanced features. Be sure to 🌟 this repository for updates!
https://docs.openwa.dev/
Other
3.08k stars 592 forks source link

Ciphertext on the first message #2278

Closed Zedmerlol closed 2 years ago

Zedmerlol commented 2 years ago

Are you using the latest version of the library?

Current Behavior

When someone contact the bot for the first time the type of message shows as "ciphertext" and the object "message" don't contein the value "body" so, it doesn't answer and the proyect crashes because body is not defined.

Expected Behavior

Detect the body on the first message

Steps To Reproduce

2021-11-08_14h34_52 2021-11-08_14h36_16

Mode

EASY API/CLI

create() code

wa.create({
  multiDevice: true,
  sessionId: "ChatbotSession",
  killProcessOnBrowserClose: true,
  qrTimeout: 0,
  authTimeout: 0,
}).then(client => start(client));

DEBUG INFO

Debug Info {
  WA_VERSION: 2.2142.12,
  PAGE_UA: WhatsApp/2.2108.8 Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36,
  WA_AUTOMATE_VERSION: 4.23.7,
  BROWSER_VERSION: HeadlessChrome/93.0.4577.0
}

Environment

- OS: 20.04 (LTS) x64
- Node: 16.8.0
- npm: 8.1.0

Screenshots

No response

Anything else?

No response

Zedmerlol commented 2 years ago

Update: the problem comes from the multi device because without multi-device don't have any error with the first message

daopapp commented 2 years ago

For me, occurs on first message on MD the type unknow and subtype fanout

Captura de Tela 2021-11-09 às 09 55 29
smashah commented 2 years ago

@asdasdsdasdasdas @daopapp I have tried to implement a fix for this but i'm kinda flying blind because I'm not able to consistently reproduce this issue. But I think I've found a fix.

  1. You WILL still receive this ciphertext message with the missing body
  2. The body will not return undefined, at worst it will return "" which will prevent the undefined error
  3. You MIGHT receive the actual message soon after (let me know) - you may not receive the message if in your web session the message looks like this:

image

Due to this screenshot I was not able to resolve the message. It seems to be a security/privacy feature.

Basically, despite this fix, you will still have circumstances where the ciphertext message doesn't eventually emit the actual message - so I suggest never relying on the first incoming message to do anything.

daopapp commented 2 years ago

Hi man, The problem it's that we use the first message as input for an automation. So, on this case, i've got the opt-in of client and depend of message content, we send a different response to client.

smashah commented 2 years ago

Hi man, The problem it's that we use the first message as input for an automation. So, on this case, i've got the opt-in of client and depend of message content, we send a different response to client.

As you can see in the screenshot above, the only time I was able to get a cipher text message, it literally did not load/decrypt the message in my session. You will not see that screenshot on your host account device.

I can understand this is annoying and I've implemented a callback to emit the message once the message type is changed from ciphertext to something else. There's not anything else I can do to be honest

daopapp commented 2 years ago

No problem man.... The strange it's that the type unknow and the subtype fanout only occours on MD. In chypertext i use the getMessageById to try to get the content of message body. I think, that the problem it's when the user has a old dated whatsapp version and send message to MD...

smashah commented 2 years ago

@daopapp yeah I noticed that about your screenshot, however, I was only to get a ciphertext/fanout message, no unknown/fanout message. Fanout is a consistent theme with MD as a message (of any type) needs to "Fan out" messages to multiple recipients (each MD session and the host account device session count as different recipients technically).

I think this issue will be finally resolved after the transition to MD is complete. So I will be closing this for now. Thanks

Zedmerlol commented 2 years ago

I should clarify that this problem of the ciphertext in the first message that the bot receives for the first time from a number only happens using Multi-device. Without Multi-device the body of the message does appear but curiously the name of the contact does not, on the other hand in Multi-device the name of the contact does appear but not the body of the message.

You can generate and see these errors with console.log(message) and wait for them to send you a message from a number which has never contacted their chatbot