wechaty / puppet-whatsapp

Wechaty Puppet for Whatsapp
https://npmjs.com/package/wechaty-puppet-whatsapp
Apache License 2.0
24 stars 17 forks source link

Can not get QR Code for login with v1.15 #328

Closed huan closed 2 years ago

huan commented 2 years ago

It seems that we are emitting the scan event payload incorrectly:

https://github.com/wechaty/puppet-whatsapp/blob/bdfa32ea8e2ab4c7be01c0ed90e1c33b87597025/src/whatsapp/event-handler/login-event-handler.ts#L36-L40

According to the above code, the typing of the payload is status: PUPPET.payloads.EventScan, url?: string | undefined but we provided qr.

Which I believe is the reason that I got the below log messages:

19:35:24 INFO WechatyPluginContrib EventLogger scan: ,[object Object],
19:35:34 INFO LoginEventHandler onQRCode(1@VO2AyDojV7zfX3eE5MMtuxSLGWgfN/ZaAfqsvDl6bYUSTC+9WTYP1SKpPJP42X6yecvjBJRH+st0Bw==,Lij20FMqgUFnEfQdRG/Wss9bFzaB/G31V3bQH07QyAI=,DsmQp2crK1L9f+1P9GnNew==)
19:35:34 VERB PuppetWhatsapp onScan([object Object], undefined)
19:35:34 INFO PuppetWhatsapp SCAN

And according to the below code:

https://github.com/wechaty/puppet-whatsapp/blob/bdfa32ea8e2ab4c7be01c0ed90e1c33b87597025/src/puppet-whatsapp.ts#L175-L180

We can confirm that the status and qrcode from 'onScan(%s, %s)', status, qrcode are both incorrect.

@su-chang @hcfw007

su-chang commented 2 years ago

Thank you for describing this bug, it help me to resolve it quickly. It could be resolved after 1.15.1.

huan commented 2 years ago

You are welcome.

I'm curious about why the typing system (TypeScript) has not prevented this bug, and how could this happen after we have finished testing the v0.41?

hcfw007 commented 2 years ago

Somehow xiaoju-bot and puppet-whatsapp@0.41 works. Will check corresponding code.

huan commented 2 years ago

Please let me know when we have any updates, thank you very much!

hcfw007 commented 2 years ago

I think this bug was produced when we tried to single out event handlers and simply copied v0.41 code. Although we did run ding-dong-bot a lot, we used memory-card to avoid repeated login and logout so we missed this. in v0.40s of wechaty, scan event is like (qrcode: string, status: ScanStatus)

su-chang commented 2 years ago

I'm curious about why the typing system (TypeScript) has not prevented this bug, and how could this happen after we have finished testing the v0.41?

{
  status: {
    status: 2,
  },
}

Maybe it seems that typescript regard this data as PUPPET.payloads.EventScan?

Somehow xiaoju-bot and puppet-whatsapp@0.41 works. Will check corresponding code.

It works due to the puppet-whatsapp version is 0.41.198, and the version does not contain the refactor code(something wrong when refactor).

huan commented 2 years ago

Thanks for the investigation!

I think there might need an integration test to make sure we can receive the scan event from the puppet after it start()-ed.

huan commented 2 years ago

Close this issue because the problem has been fixed.

Appreciate it!

hcfw007 commented 2 years ago

I'm writing a test for qrcode, hoping it will prevent this kind of situation in the future. #333