Baileys icon indicating copy to clipboard operation
Baileys copied to clipboard

[BUG] this.constructor.toObject is not a function

Open jurajmatus opened this issue 1 year ago • 2 comments

Describe the bug When I try to JSON.stringify classes from WASignalGroup/GroupProtocol, I get this error:

TypeError: this.constructor.toObject is not a function
at Object.toJSON
at JSON.stringify
...

Cause https://github.com/adiwajshing/Baileys/blob/master/WASignalGroup/GroupProtocol.js#L256 + more occurences in the file (possibly not a supported format by newer node versions)

Suggested solution: using class literals instead of this.constructor

To Reproduce Steps to reproduce the behavior:

  1. Created a new connection
  2. A message of the mentioned classes came and is put into store via an event listener
  3. Serialized store

Expected behavior JSON.stringify should not fail

Environment (please complete the following information):

  • Is this on a server? YES (node version 14)
  • What do your connectOptions look like?
{
    version,// fetchLatestBaileysVersion()
    logger: state.logger, // error level
    markOnlineOnConnect: false,
    auth: state.authState, // custom DynamoDB based implementation
    syncFullHistory: true,
    msgRetryCounterMap: state.msgRetryCounterMap,
    connectTimeoutMs: 5 * 60 * 1000,
    defaultQueryTimeoutMs: undefined,
    keepAliveIntervalMs: 10000,
    browser: Browsers.macOS('Desktop'),
  }
  • Do you have multiple clients on the same IP? NO
  • Are you using a proxy? NO

Additional context I have a custom store implementation which uses JSON.stringify to make a storable representation. When classes from the mentioned file get there, it fails.

jurajmatus avatar Sep 13 '22 17:09 jurajmatus

This issue is stale because it has been open 6 days with no activity. Remove the stale label or comment or this will be closed in 2 days

github-actions[bot] avatar Sep 20 '22 03:09 github-actions[bot]

Still relevant

jurajmatus avatar Sep 20 '22 04:09 jurajmatus

This issue is stale because it has been open 6 days with no activity. Remove the stale label or comment or this will be closed in 2 days

github-actions[bot] avatar Sep 28 '22 04:09 github-actions[bot]

Still relevant

jurajmatus avatar Sep 28 '22 04:09 jurajmatus

This issue is stale because it has been open 6 days with no activity. Remove the stale label or comment or this will be closed in 2 days

github-actions[bot] avatar Oct 06 '22 03:10 github-actions[bot]

Still an issue

jurajmatus avatar Oct 06 '22 06:10 jurajmatus

This issue is stale because it has been open 6 days with no activity. Remove the stale label or comment or this will be closed in 2 days

github-actions[bot] avatar Oct 13 '22 03:10 github-actions[bot]

Still an issue

jurajmatus avatar Oct 13 '22 04:10 jurajmatus

This issue is stale because it has been open 6 days with no activity. Remove the stale label or comment or this will be closed in 2 days

github-actions[bot] avatar Oct 21 '22 03:10 github-actions[bot]