Zain-ul-din / whatsapp-ai-bot

This is a WhatsApp AI bot that uses various AI models, including Gemini, GPT, DALL-E, and StabilityAI, to generate responses to user input.
https://wa-ai-seven.vercel.app/
MIT License
161 stars 89 forks source link

"TypeError during QR Code generation in WhatsApp AI Bot setup" #33

Closed levitco closed 3 months ago

levitco commented 3 months ago

I runned this on the my local and codespaces

I encountered a TypeError while setting up the WhatsApp AI Bot. After successfully installing dependencies with Yarn and initiating the server, the process failed during the QR Code generation step. The error occurs in LocalWebCache.js of the whatsapp-web.js module when attempting to read a property of null. It seems like the regular expression used to find the version number in indexHtml isn't returning a match and hence the script is trying to access an index of a null object. Here's the stack trace for the error:

TypeError: Cannot read properties of null (reading '1')
    at LocalWebCache.persist (/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/webCache/LocalWebCache.js:34:69)
    at /workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/Client.js:744:36
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

image

`@levitco ➜ /workspaces/whatsapp-ai-bot (master) $ bash ./setup.sh
installing dependencies
Need to install the following packages:
yarn@1.22.22
Ok to proceed? (y) y
yarn install v1.22.22
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 10.23s.
npm notice 
npm notice New minor version of npm available! 10.2.4 -> 10.5.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.5.1
npm notice Run npm install -g npm@10.5.1 to update!
npm notice 
βœ” dependencies has been installed
initializing server
yarn run v1.22.22
$ vite-node ./src/index.ts
πŸ€– starting client...
β ™ Whats App Client | generating QR Code... 
/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/webCache/LocalWebCache.js:34
        const version = indexHtml.match(/manifest-([\d\\.]+)\.json/)[1];
                                                                    ^

TypeError: Cannot read properties of null (reading '1')
    at LocalWebCache.persist (/workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/webCache/LocalWebCache.js:34:69)
    at /workspaces/whatsapp-ai-bot/node_modules/whatsapp-web.js/src/Client.js:744:36
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v20.11.1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@levitco ➜ /workspaces/whatsapp-ai-bot (master) $ `
Zain-ul-din commented 3 months ago

@levitco check again it's working for me on GitHub code spaces

Zain-ul-din commented 3 months ago

solution ref: https://github.com/pedroslopez/whatsapp-web.js/issues/2789#issuecomment-1992260938