askrella / whatsapp-chatgpt

ChatGPT + DALL-E + WhatsApp = AI Assistant :rocket: :robot:
3.49k stars 842 forks source link

Invalid data structure: data.id.id is not a string #233

Closed PointerSoftware closed 1 year ago

PointerSoftware commented 1 year ago

I am getting this error after I send whatsapp message to the AI Invalid data structure: data.id.id is not a string I setup everything correctly accourding to the documentation. Screenshot

envieme commented 1 year ago

whatsapp web node module has changed and it has introduced errors. Those who installed Whatsapp-Chatgpt recently pulling new node modules or those who happen to update from now may see the error until it is fixed in npm for the library.

For now, quick fix is:

in [/node_modules/whatsapp-web.js/src/structures/Message.js] line 91:

change: this.deviceType = data.id.id.length > 21 ? 'android' : data.id.id.substring(0, 2) == '3A' ? 'ios' : 'web';

to

this.deviceType = typeof data.id.id === 'string' && data.id.id.length > 21 ? 'android' : typeof data.id.id === 'string' && data.id.id.substring(0, 2) === '3A' ? 'ios' : 'web';

and

/node_modules/whatsapp-web.js/src/util/Injected.js around line 250:

Change code to this:

const newId = await window.Store.MsgKey.newId(); //change

        const newMsgId = new window.Store.MsgKey({
            from: meUser,
            to: chat.id,
            id: window.Store.MsgKey.newId(),
            id: newId, // change
            participant: isMD && chat.id.isGroup() ? meUser : undefined,
            selfDir: 'out',
        });

It should fix the errors and message not sending issue.

PointerSoftware commented 1 year ago

Thank you very much. Your support is greatly appreciated, and I am grateful for your exceptional assistance.